on master help sign in
Add language support for Cap’n Proto format (#6325)
commitac2a7731a6d04b8b913f49531058c7e2a843efd5 authorangelodlfrtr <angelo.delefortrie@gmail.com> dateSat 18 Mar 2023, 15:17 (4 years ago) parent9f5374b
7 files changed+286
book/src/generated/lang-support.md+1 languages.toml+13 runtime/queries/capnp/folds.scm+14 runtime/queries/capnp/highlights.scm+141 runtime/queries/capnp/indents.scm+19 runtime/queries/capnp/injections.scm+2 runtime/queries/capnp/locals.scm+96
book/src/generated/lang-support.md+1
@@ -10,6 +10,7 @@
1010| c | ✓ | ✓ | ✓ | `clangd` |
1111| c-sharp | ✓ | ✓ | | `OmniSharp` |
1212| cairo | ✓ | | | |
13+| capnp | ✓ | | ✓ | |
1314| clojure | ✓ | | | `clojure-lsp` |
1415| cmake | ✓ | ✓ | ✓ | `cmake-language-server` |
1516| comment | ✓ | | | |
languages.toml+13
@@ -2328,3 +2328,16 @@ roots = []
23282328[[grammar]]
23292329name = "rst"
23302330source = { git = "https://github.com/stsewd/tree-sitter-rst", rev = "25e6328872ac3a764ba8b926aea12719741103f1" }
2331+
2332+[[language]]
2333+name = "capnp"
2334+scope = "source.capnp"
2335+injection-regex = "capnp"
2336+file-types = ["capnp"]
2337+roots = []
2338+comment-token = "#"
2339+indent = { tab-width = 2, unit = " " }
2340+
2341+[[grammar]]
2342+name = "capnp"
2343+source = { git = "https://github.com/amaanq/tree-sitter-capnp", rev = "fc6e2addf103861b9b3dffb82c543eb6b71061aa" }
runtime/queries/capnp/folds.scmnew file+14
@@ -0,0 +1,14 @@
1+[
2+ (annotation_targets)
3+ (const_list)
4+ (enum)
5+ (interface)
6+ (implicit_generics)
7+ (generics)
8+ (group)
9+ (method_parameters)
10+ (named_return_types)
11+ (struct)
12+ (struct_shorthand)
13+ (union)
14+] @fold
runtime/queries/capnp/highlights.scmnew file+141
@@ -0,0 +1,141 @@
1+; Preproc
2+
3+(unique_id) @keyword.directive
4+(top_level_annotation_body) @keyword.directive
5+
6+; Includes
7+
8+[
9+ "import"
10+ "$import"
11+ "embed"
12+] @keyword.control.import
13+
14+(import_path) @string
15+
16+; Builtins
17+
18+[
19+ (primitive_type)
20+ "List"
21+] @type.builtin
22+
23+; Typedefs
24+
25+(type_definition) @type
26+
27+; Labels (@number, @number!)
28+
29+(field_version) @label
30+
31+; Methods
32+
33+(annotation_definition_identifier) @function.method
34+(method_identifier) @function.method
35+
36+; Fields
37+
38+(field_identifier) @variable.other.member
39+
40+; Properties
41+
42+(property) @label
43+
44+; Parameters
45+
46+(param_identifier) @variable.parameter
47+(return_identifier) @variable.parameter
48+
49+; Constants
50+
51+(const_identifier) @variable
52+(local_const) @constant
53+(enum_member) @type.enum.variant
54+
55+(void) @constant.builtin
56+
57+; Types
58+
59+(enum_identifier) @type.enum
60+(extend_type) @type
61+(type_identifier) @type
62+
63+; Attributes
64+
65+(annotation_identifier) @attribute
66+(attribute) @attribute
67+
68+; Operators
69+
70+[
71+ ; @ ! -
72+ "="
73+] @operator
74+
75+; Keywords
76+
77+
78+[
79+ "annotation"
80+ "enum"
81+ "group"
82+ "interface"
83+ "struct"
84+ "union"
85+] @keyword.storage.type
86+
87+[
88+ "extends"
89+ "namespace"
90+ "using"
91+ (annotation_target)
92+] @special
93+
94+; Literals
95+
96+[
97+ (string)
98+ (concatenated_string)
99+ (block_text)
100+ (namespace)
101+] @string
102+
103+(escape_sequence) @constant.character.escape
104+
105+(data_string) @string.special
106+
107+(number) @constant.numeric.integer
108+
109+(float) @constant.numeric.float
110+
111+(boolean) @constant.builtin.boolean
112+
113+; Misc
114+
115+[
116+ "const"
117+] @keyword.storage.modifier
118+
119+[
120+ "*"
121+ "$"
122+ ":"
123+] @string.special.symbol
124+
125+["{" "}"] @punctuation.bracket
126+
127+["(" ")"] @punctuation.bracket
128+
129+["[" "]"] @punctuation.bracket
130+
131+[
132+ ","
133+ ";"
134+ "->"
135+] @punctuation.delimiter
136+
137+(data_hex) @constant
138+
139+; Comments
140+
141+(comment) @comment.line
runtime/queries/capnp/indents.scmnew file+19
@@ -0,0 +1,19 @@
1+[
2+ (annotation_targets)
3+ (const_list)
4+ (enum)
5+ (interface)
6+ (implicit_generics)
7+ (generics)
8+ (group)
9+ (method_parameters)
10+ (named_return_types)
11+ (struct)
12+ (struct_shorthand)
13+ (union)
14+] @indent
15+
16+[
17+ "}"
18+ ")"
19+] @outdent
runtime/queries/capnp/injections.scmnew file+2
@@ -0,0 +1,2 @@
1+((comment) @injection.content
2+ (#set! injection.language "comment"))
runtime/queries/capnp/locals.scmnew file+96
@@ -0,0 +1,96 @@
1+; Scopes
2+
3+[
4+ (message)
5+ (annotation_targets)
6+ (const_list)
7+ (enum)
8+ (interface)
9+ (implicit_generics)
10+ (generics)
11+ (group)
12+ (method_parameters)
13+ (named_return_types)
14+ (struct)
15+ (struct_shorthand)
16+ (union)
17+] @local.scope
18+
19+; References
20+
21+[
22+ (extend_type)
23+ (field_type)
24+] @local.reference
25+(custom_type (type_identifier) @local.reference)
26+(custom_type
27+ (generics
28+ (generic_parameters
29+ (generic_identifier) @local.reference)))
30+
31+; Definitions
32+
33+(annotation_definition_identifier) @local.definition
34+
35+(const_identifier) @local.definition
36+
37+(enum (enum_identifier) @local.definition)
38+
39+[
40+ (enum_member)
41+ (field_identifier)
42+] @local.definition
43+
44+(method_identifier) @local.definition
45+
46+(namespace) @local.definition
47+
48+[
49+ (param_identifier)
50+ (return_identifier)
51+] @local.definition
52+
53+(group (type_identifier) @local.definition)
54+
55+(struct (type_identifier) @local.definition)
56+
57+(union (type_identifier) @local.definition)
58+
59+(interface (type_identifier) @local.definition)
60+
61+; Generics Related (don't know how to combine these)
62+
63+(struct
64+ (generics
65+ (generic_parameters
66+ (generic_identifier) @local.definition)))
67+
68+(interface
69+ (generics
70+ (generic_parameters
71+ (generic_identifier) @local.definition)))
72+
73+(method
74+ (implicit_generics
75+ (implicit_generic_parameters
76+ (generic_identifier) @local.definition)))
77+
78+(method
79+ (generics
80+ (generic_parameters
81+ (generic_identifier) @local.definition)))
82+
83+(annotation
84+ (generics
85+ (generic_parameters
86+ (generic_identifier) @local.definition)))
87+
88+(replace_using
89+ (generics
90+ (generic_parameters
91+ (generic_identifier) @local.definition)))
92+
93+(return_type
94+ (generics
95+ (generic_parameters
96+ (generic_identifier) @local.definition)))