on master help sign in
Add support for D (#4372)

Co-authored-by: Michael Davis <mcarsondavis@gmail.com>

commit36f97b6aadec1a5c0cc61859d4f456f005983be0 authorGarrett D'Amore <garrett@damore.org> dateThu 20 Oct 2022, 14:54 (4 years ago) parentde60783
6 files changed+275
book/src/generated/lang-support.md+1 languages.toml+15 runtime/queries/d/highlights.scm+231 runtime/queries/d/indents.scm+17 runtime/queries/d/injections.scm+2 runtime/queries/d/textobjects.scm+9
book/src/generated/lang-support.md+1
@@ -15,6 +15,7 @@
1515| cpp | ✓ | ✓ | ✓ | `clangd` |
1616| css | ✓ | | | `vscode-css-language-server` |
1717| cue | ✓ | | | `cuelsp` |
18+| d | ✓ | ✓ | ✓ | `serve-d` |
1819| dart | ✓ | | ✓ | `dart` |
1920| devicetree | ✓ | | | |
2021| diff | ✓ | | | |
languages.toml+15
@@ -1835,3 +1835,18 @@ roots = []
18351835[[grammar]]
18361836name = "wast"
18371837source = { git = "https://github.com/wasm-lsp/tree-sitter-wasm", rev = "2ca28a9f9d709847bf7a3de0942a84e912f59088", subpath = "wast" }
1838+
1839+[[language]]
1840+name = "d"
1841+scope = "source.d"
1842+file-types = [ "d", "dd" ]
1843+roots = []
1844+comment-token = "//"
1845+injection-regex = "d"
1846+indent = { tab-width = 4, unit = " "}
1847+language-server = { command = "serve-d" }
1848+formatter = { command = "dfmt" }
1849+
1850+[[grammar]]
1851+name = "d"
1852+source = { git = "https://github.com/gdamore/tree-sitter-d", rev="601c4a1e8310fb2f3c43fa8a923d0d27497f3c04" }
runtime/queries/d/highlights.scmnew file+231
@@ -0,0 +1,231 @@
1+; highlights.scm
2+;
3+; Highlighting queries for D code for use by Tree-Sitter.
4+;
5+; Copyright 2022 Garrett D'Amore
6+;
7+; Distributed under the MIT License.
8+; (See accompanying file LICENSE.txt or https://opensource.org/licenses/MIT)
9+; SPDX-License-Identifier: MIT
10+
11+; these are listed first, because they override keyword queries
12+(identity_expression (in) @operator)
13+(identity_expression (is) @operator)
14+
15+(storage_class) @keyword.storage
16+
17+(function_declaration (identifier) @function)
18+
19+(call_expression (identifier) @function)
20+(call_expression (type (identifier) @function))
21+
22+(module_fqn) @namespace
23+
24+[
25+ (abstract)
26+ (alias)
27+ (align)
28+ (asm)
29+ (assert)
30+ (auto)
31+ (cast)
32+ (const)
33+ (debug)
34+ (delete)
35+ (deprecated)
36+ (export)
37+ (extern)
38+ (final)
39+ (immutable)
40+ (in)
41+ (inout)
42+ (invariant)
43+ (is)
44+ (lazy)
45+ ; "macro" - obsolete
46+ (mixin)
47+ (module)
48+ (new)
49+ (nothrow)
50+ (out)
51+ (override)
52+ (package)
53+ (pragma)
54+ (private)
55+ (protected)
56+ (public)
57+ (pure)
58+ (ref)
59+ (scope)
60+ (shared)
61+ (static)
62+ (super)
63+ (synchronized)
64+ (template)
65+ (this)
66+ (throw)
67+ (typeid)
68+ (typeof)
69+ (unittest)
70+ (version)
71+ (with)
72+ (gshared)
73+ (traits)
74+ (vector)
75+ (parameters_)
76+] @keyword
77+
78+[
79+ (class)
80+ (struct)
81+ (interface)
82+ (union)
83+ (enum)
84+ (function)
85+ (delegate)
86+] @keyword.storage.type
87+
88+[
89+ (break)
90+ (case)
91+ (catch)
92+ (continue)
93+ (do)
94+ (default)
95+ (finally)
96+ (else)
97+ (goto)
98+ (if)
99+ (switch)
100+ (try)
101+] @keyword.control
102+
103+(return) @keyword.control.return
104+
105+(import) @keyword.control.import
106+
107+[
108+ (for)
109+ (foreach)
110+ (foreach_reverse)
111+ (while)
112+] @keyword.control.repeat
113+
114+[
115+ (not_in)
116+ (not_is)
117+ "/="
118+ "/"
119+ ".."
120+ "..."
121+ "&"
122+ "&="
123+ "&&"
124+ "|"
125+ "|="
126+ "||"
127+ "-"
128+ "-="
129+ "--"
130+ "+"
131+ "+="
132+ "++"
133+ "<"
134+ "<="
135+ "<<"
136+ "<<="
137+ ">"
138+ ">="
139+ ">>="
140+ ">>>="
141+ ">>"
142+ ">>>"
143+ "!"
144+ "!="
145+ "?"
146+ "$"
147+ "="
148+ "=="
149+ "*"
150+ "*="
151+ "%"
152+ "%="
153+ "^"
154+ "^="
155+ "^^"
156+ "^^="
157+ "~"
158+ "~="
159+ "@"
160+ "=>"
161+] @operator
162+
163+[
164+ "("
165+ ")"
166+ "["
167+ "]"
168+] @punctuation.bracket
169+
170+[
171+ ";"
172+ "."
173+ ":"
174+ ","
175+] @punctuation.delimiter
176+
177+[
178+ (true)
179+ (false)
180+] @constant.builtin.boolean
181+
182+(null) @constant.builtin
183+
184+(special_keyword) @constant.builtin
185+
186+(directive) @keyword.directive
187+(shebang) @keyword.directive
188+
189+(comment) @comment
190+
191+[
192+ (void)
193+ (bool)
194+ (byte)
195+ (ubyte)
196+ (char)
197+ (short)
198+ (ushort)
199+ (wchar)
200+ (dchar)
201+ (int)
202+ (uint)
203+ (long)
204+ (ulong)
205+ (real)
206+ (double)
207+] @type.builtin
208+
209+[
210+ (cent)
211+ (ucent)
212+ (ireal)
213+ (idouble)
214+ (ifloat)
215+ (creal)
216+ (double)
217+ (cfloat)
218+] @warning ; these types are deprecated
219+
220+(label (identifier) @label)
221+(goto_statement (goto) @keyword (identifier) @label)
222+
223+(string_literal) @string
224+(int_literal) @constant.numeric.integer
225+(float_literal) @constant.numeric.float
226+(char_literal) @constant.character
227+(identifier) @variable
228+(at_attribute) @attribute
229+
230+; everything after __EOF_ is plain text
231+(end_file) @ui.text
runtime/queries/d/indents.scmnew file+17
@@ -0,0 +1,17 @@
1+[
2+ (parameters)
3+ (template_parameters)
4+ (expression_statement)
5+ (aggregate_body)
6+ (function_body)
7+ (scope_statement)
8+ (block_statement)
9+ (case_statement)
10+] @indent
11+
12+[
13+ (case)
14+ (default)
15+ "}"
16+ "]"
17+] @outdent
runtime/queries/d/injections.scmnew file+2
@@ -0,0 +1,2 @@
1+((comment) @injection.content
2+ (#set! injection.language "comment"))
runtime/queries/d/textobjects.scmnew file+9
@@ -0,0 +1,9 @@
1+(function_declaration (function_body) @function.inside) @function.around
2+(comment) @comment.inside
3+(comment)+ @comment.around
4+(class_declaration (aggregate_body) @class.inside) @class.around
5+(interface_declaration (aggregate_body) @class.inside) @class.around
6+(struct_declaration (aggregate_body) @class.inside) @class.around
7+(unittest_declaration (block_statement) @test.insid) @test.around
8+(parameter) @parameter.inside
9+(template_parameter) @parameter.inside