on master help sign in
Add dart lsp config and queries (#1250)

* Add language: dart The setup requires that dart be in the users path, such as: ``` export PATH="$HOME/Android/flutter/bin/cache/dart-sdk/bin/:$PATH" ``` Refactor the dart highlights * lang: dart: add indents and locals * lang: dart: corrections to local scope Co-authored-by: Blaž Hrastnik <blaz@mxxn.io>

commitedf3c70c302aef628dc1a63895e2492d34e82507 authorLuke Jones <luke@ljones.dev> dateSat 18 Dec 2021, 17:41 (5 years ago) parent0683f0a
6 files changed+293−1
.gitmodules+4 helix-syntax/languages/tree-sitter-dart+1 languages.toml+11−1 runtime/queries/dart/highlights.scm+237 runtime/queries/dart/indents.toml+20 runtime/queries/dart/locals.scm+20
.gitmodules+4
@@ -154,3 +154,7 @@
154154 path = helix-syntax/languages/tree-sitter-markdown
155155 url = https://github.com/MDeiml/tree-sitter-markdown
156156 shallow = true
157+[submodule "helix-syntax/languages/tree-sitter-dart"]
158+ path = helix-syntax/languages/tree-sitter-dart
159+ url = https://github.com/UserNobody14/tree-sitter-dart.git
160+ shallow = true
helix-syntax/languages/tree-sitter-dartnew file+1

Submodule changed.

languages.toml+11−1
@@ -431,6 +431,16 @@ roots = []
431431
432432indent = { tab-width = 2, unit = " " }
433433
434+[[language]]
435+name = "dart"
436+scope = "source.dart"
437+file-types = ["dart"]
438+roots = ["pubspec.yaml"]
439+auto-format = true
440+comment-token = "//"
441+language-server = { command = "dart", args = ["language-server", "--client-id=helix"] }
442+indent = { tab-width = 2, unit = " " }
443+
434444[[language]]
435445name = "scala"
436446scope = "source.scala"
@@ -438,4 +448,4 @@ roots = ["build.sbt"]
438448file-types = ["scala", "sbt"]
439449comment-token = "//"
440450indent = { tab-width = 2, unit = " " }
441−language-server = { command = "metals" }
451+language-server = { command = "metals" }
runtime/queries/dart/highlights.scmnew file+237
@@ -0,0 +1,237 @@
1+(dotted_identifier_list) @string
2+
3+; Methods
4+; --------------------
5+(super) @function.builtin
6+
7+(function_expression_body (identifier) @function.method)
8+((identifier)(selector (argument_part)) @function.method)
9+
10+; Annotations
11+; --------------------
12+(annotation
13+ name: (identifier) @attribute)
14+(marker_annotation
15+ name: (identifier) @attribute)
16+
17+; Types
18+; --------------------
19+(class_definition
20+ name: (identifier) @type)
21+
22+(constructor_signature
23+ name: (identifier) @function.method)
24+
25+(function_signature
26+ name: (identifier) @function.method)
27+
28+(getter_signature
29+ (identifier) @function.builtin)
30+
31+(setter_signature
32+ name: (identifier) @function.builtin)
33+
34+(enum_declaration
35+ name: (identifier) @type)
36+
37+(enum_constant
38+ name: (identifier) @type.builtin)
39+
40+(void_type) @type.builtin
41+
42+((scoped_identifier
43+ scope: (identifier) @type)
44+ (#match? @type "^[a-zA-Z]"))
45+
46+((scoped_identifier
47+ scope: (identifier) @type
48+ name: (identifier) @type)
49+ (#match? @type "^[a-zA-Z]"))
50+
51+; the DisabledDrawerButtons in : const DisabledDrawerButtons(history: true),
52+(type_identifier) @type.builtin
53+
54+; Variables
55+; --------------------
56+; the "File" in var file = File();
57+((identifier) @namespace
58+ (#match? @namespace "^_?[A-Z].*[a-z]")) ; catch Classes or IClasses not CLASSES
59+
60+("Function" @type.builtin)
61+(inferred_type) @type.builtin
62+
63+; properties
64+(unconditional_assignable_selector
65+ (identifier) @variable.other.member)
66+
67+(conditional_assignable_selector
68+ (identifier) @variable.other.member)
69+
70+; assignments
71+; --------------------
72+; the "strings" in : strings = "some string"
73+(assignment_expression
74+ left: (assignable_expression) @variable)
75+
76+(this) @variable.builtin
77+
78+; Parameters
79+; --------------------
80+(formal_parameter
81+ name: (identifier) @variable)
82+
83+(named_argument
84+ (label (identifier) @variable))
85+
86+; Literals
87+; --------------------
88+[
89+ (hex_integer_literal)
90+ (decimal_integer_literal)
91+ (decimal_floating_point_literal)
92+ ;(octal_integer_literal)
93+ ;(hex_floating_point_literal)
94+] @constant.numeric.integer
95+
96+(symbol_literal) @string.special.symbol
97+(string_literal) @string
98+
99+[
100+ (const_builtin)
101+ (final_builtin)
102+] @variable.builtin
103+
104+[
105+ (true)
106+ (false)
107+] @constant.builtin.boolean
108+
109+(null_literal) @constant.builtin
110+
111+(comment) @comment.line
112+(documentation_comment) @comment.block.documentation
113+
114+; Tokens
115+; --------------------
116+(template_substitution
117+ "$" @punctuation.special
118+ "{" @punctuation.special
119+ "}" @punctuation.special
120+) @embedded
121+
122+(template_substitution
123+ "$" @punctuation.special
124+ (identifier_dollar_escaped) @variable
125+) @embedded
126+
127+(escape_sequence) @constant.character.escape
128+
129+; Punctuation
130+;---------------------
131+[
132+ "("
133+ ")"
134+ "["
135+ "]"
136+ "{"
137+ "}"
138+] @punctuation.bracket
139+
140+[
141+ ";"
142+ "."
143+ ","
144+ ":"
145+] @punctuation.delimiter
146+
147+; Operators
148+;---------------------
149+[
150+ "@"
151+ "?"
152+ "=>"
153+ ".."
154+ "=="
155+ "&&"
156+ "%"
157+ "<"
158+ ">"
159+ "="
160+ ">="
161+ "<="
162+ "||"
163+ (multiplicative_operator)
164+ (increment_operator)
165+ (is_operator)
166+ (prefix_operator)
167+ (equality_operator)
168+ (additive_operator)
169+] @operator
170+
171+; Keywords
172+; --------------------
173+["import" "library" "export"] @keyword.control.import
174+["do" "while" "continue" "for"] @keyword.control.repeat
175+["return" "yield"] @keyword.control.return
176+["as" "in" "is"] @keyword.operator
177+
178+[
179+ "?."
180+ "??"
181+ "if"
182+ "else"
183+ "switch"
184+ "default"
185+ "late"
186+] @keyword.control.conditional
187+
188+[
189+ "try"
190+ "throw"
191+ "catch"
192+ "finally"
193+ (break_statement)
194+] @keyword.control.exception
195+
196+; Reserved words (cannot be used as identifiers)
197+[
198+ (case_builtin)
199+ "abstract"
200+ "async"
201+ "async*"
202+ "await"
203+ "class"
204+ "covariant"
205+ "deferred"
206+ "dynamic"
207+ "enum"
208+ "extends"
209+ "extension"
210+ "external"
211+ "factory"
212+ "Function"
213+ "get"
214+ "implements"
215+ "interface"
216+ "mixin"
217+ "new"
218+ "on"
219+ "operator"
220+ "part"
221+ "required"
222+ "set"
223+ "show"
224+ "static"
225+ "super"
226+ "sync*"
227+ "typedef"
228+ "with"
229+] @keyword
230+
231+; when used as an identifier:
232+((identifier) @variable.builtin
233+ (#match? @variable.builtin "^(abstract|as|covariant|deferred|dynamic|export|external|factory|Function|get|implements|import|interface|library|operator|mixin|part|set|static|typedef)$"))
234+
235+; Error
236+(ERROR) @error
237+
runtime/queries/dart/indents.tomlnew file+20
@@ -0,0 +1,20 @@
1+indent = [
2+ "class_body",
3+ "function_body",
4+ "function_expression_body",
5+ "declaration",
6+ "initializers",
7+ "switch_block",
8+ "if_statement",
9+ "formal_parameter_list",
10+ "formal_parameter",
11+ "list_literal",
12+ "return_statement",
13+ "arguments"
14+]
15+
16+outdent = [
17+ "}",
18+ "]",
19+ ")"
20+]
runtime/queries/dart/locals.scmnew file+20
@@ -0,0 +1,20 @@
1+; Scopes
2+;-------
3+
4+[
5+ (block)
6+ (try_statement)
7+ (catch_clause)
8+ (finally_clause)
9+] @local.scope
10+
11+; Definitions
12+;------------
13+
14+(class_definition
15+ body: (_) @local.definition)
16+
17+; References
18+;------------
19+
20+(identifier) @local.reference