on master help sign in
Add scala syntax highlights (#1278)
0683f0aOliver Hechtl
book/src/generated/lang-support.md+1
@@ -31,6 +31,7 @@
31| racket | | | | `racket` |
31| racket | | | | `racket` |
32| ruby | ✓ | | | `solargraph` |
32| ruby | ✓ | | | `solargraph` |
33| rust | ✓ | ✓ | ✓ | `rust-analyzer` |
33| rust | ✓ | ✓ | ✓ | `rust-analyzer` |
34+| scala | ✓ | | | `metals` |
34| svelte | ✓ | | ✓ | `svelteserver` |
35| svelte | ✓ | | ✓ | `svelteserver` |
35| toml | ✓ | | | |
36| toml | ✓ | | | |
36| tsq | ✓ | | | |
37| tsq | ✓ | | | |
helix-syntax/languages/tree-sitter-scala+1−1

Submodule changed.

languages.toml+9
@@ -430,3 +430,12 @@ file-types = ["md"]
430roots = []
430roots = []
431
431
432indent = { tab-width = 2, unit = " " }
432indent = { tab-width = 2, unit = " " }
433+
434+[[language]]
435+name = "scala"
436+scope = "source.scala"
437+roots = ["build.sbt"]
438+file-types = ["scala", "sbt"]
439+comment-token = "//"
440+indent = { tab-width = 2, unit = " " }
441+language-server = { command = "metals" }
runtime/queries/scala/highlights.scmnew file+203
@@ -0,0 +1,203 @@
1+; CREDITS @stumash (stuart.mashaal@gmail.com)
2+
3+;; variables
4+
5+
6+((identifier) @variable.builtin
7+ (#match? @variable.builtin "^this$"))
8+
9+(interpolation) @none
10+
11+; Assume other uppercase names constants.
12+; NOTE: In order to distinguish constants we highlight
13+; all the identifiers that are uppercased. But this solution
14+; is not suitable for all occurrences e.g. it will highlight
15+; an uppercased method as a constant if used with no params.
16+; Introducing highlighting for those specific cases, is probably
17+; best way to resolve the issue.
18+((identifier) @constant (#match? @constant "^[A-Z]"))
19+
20+;; types
21+
22+(type_identifier) @type
23+
24+(class_definition
25+ name: (identifier) @type)
26+
27+(object_definition
28+ name: (identifier) @type)
29+
30+(trait_definition
31+ name: (identifier) @type)
32+
33+(type_definition
34+ name: (type_identifier) @type)
35+
36+; method definition
37+
38+(class_definition
39+ body: (template_body
40+ (function_definition
41+ name: (identifier) @function.method)))
42+(object_definition
43+ body: (template_body
44+ (function_definition
45+ name: (identifier) @function.method)))
46+(trait_definition
47+ body: (template_body
48+ (function_definition
49+ name: (identifier) @function.method)))
50+
51+; imports
52+
53+(import_declaration
54+ path: (identifier) @namespace)
55+((stable_identifier (identifier) @namespace))
56+
57+((import_declaration
58+ path: (identifier) @type) (#match? @type "^[A-Z]"))
59+((stable_identifier (identifier) @type) (#match? @type "^[A-Z]"))
60+
61+((import_selectors (identifier) @type) (#match? @type "^[A-Z]"))
62+
63+; method invocation
64+
65+
66+(call_expression
67+ function: (identifier) @function)
68+
69+(call_expression
70+ function: (field_expression
71+ field: (identifier) @function.method))
72+
73+((call_expression
74+ function: (identifier) @variable.other.member)
75+ (#match? @variable.other.member "^[A-Z]"))
76+
77+(generic_function
78+ function: (identifier) @function)
79+
80+(
81+ (identifier) @function.builtin
82+ (#match? @function.builtin "^super$")
83+)
84+
85+; function definitions
86+
87+(function_definition
88+ name: (identifier) @function)
89+
90+(parameter
91+ name: (identifier) @variable.parameter)
92+
93+; expressions
94+
95+
96+(field_expression field: (identifier) @variable.other.member)
97+(field_expression value: (identifier) @type
98+ (#match? @type "^[A-Z]"))
99+
100+(infix_expression operator: (identifier) @operator)
101+(infix_expression operator: (operator_identifier) @operator)
102+(infix_type operator: (operator_identifier) @operator)
103+(infix_type operator: (operator_identifier) @operator)
104+
105+; literals
106+(boolean_literal) @constant.builtin.boolean
107+(integer_literal) @constant.numeric.integer
108+(floating_point_literal) @constant.numeric.float
109+
110+
111+(symbol_literal) @string.special.symbol
112+
113+[
114+(string)
115+(character_literal)
116+(interpolated_string_expression)
117+] @string
118+
119+(interpolation "$" @punctuation.special)
120+
121+;; keywords
122+
123+[
124+ "abstract"
125+ "case"
126+ "class"
127+ "extends"
128+ "final"
129+ "finally"
130+;; `forSome` existential types not implemented yet
131+ "implicit"
132+ "lazy"
133+;; `macro` not implemented yet
134+ "object"
135+ "override"
136+ "package"
137+ "private"
138+ "protected"
139+ "sealed"
140+ "trait"
141+ "type"
142+ "val"
143+ "var"
144+ "with"
145+] @keyword
146+
147+(null_literal) @constant.builtin
148+(wildcard) @keyword
149+
150+;; special keywords
151+
152+"new" @keyword.operator
153+
154+[
155+ "else"
156+ "if"
157+ "match"
158+ "try"
159+ "catch"
160+ "throw"
161+] @keyword.control.conditional
162+
163+[
164+ "("
165+ ")"
166+ "["
167+ "]"
168+ "{"
169+ "}"
170+] @punctuation.bracket
171+
172+[
173+ "."
174+ ","
175+] @punctuation.delimiter
176+
177+[
178+ "do"
179+ "for"
180+ "while"
181+ "yield"
182+] @keyword.control.repeat
183+
184+"def" @keyword.function
185+
186+[
187+ "=>"
188+ "<-"
189+ "@"
190+] @keyword.operator
191+
192+"import" @keyword.control.import
193+
194+"return" @keyword.control.return
195+
196+(comment) @comment
197+
198+;; `case` is a conditional keyword in case_block
199+
200+(case_block
201+ (case_clause ("case") @keyword.control.conditional))
202+
203+(identifier) @variable
runtime/queries/scala/indents.tomlnew file+23
@@ -0,0 +1,23 @@
1+
2+indent = [
3+ "block",
4+ "arguments",
5+ "parameter",
6+ "class_definition",
7+ "trait_definition",
8+ "object_definition",
9+ "function_definition",
10+ "val_definition",
11+ "import_declaration",
12+ "while_expression",
13+ "do_while_expression",
14+ "for_expression",
15+ "try_expression",
16+ "match_expression"
17+]
18+
19+outdent = [
20+ "}",
21+ "]",
22+ ")"
23+]
runtime/queries/scala/injections.scmnew file+1
@@ -0,0 +1 @@
1+(comment) @comment