on master help sign in
Add llvm-mir highlighting (#1398)
641255cSebastian Neubauer
.gitmodules+4
@@ -174,6 +174,10 @@
174 path = helix-syntax/languages/tree-sitter-git-commit
174 path = helix-syntax/languages/tree-sitter-git-commit
175 url = https://github.com/the-mikedavis/tree-sitter-git-commit.git
175 url = https://github.com/the-mikedavis/tree-sitter-git-commit.git
176 shallow = true
176 shallow = true
177+[submodule "helix-syntax/languages/tree-sitter-llvm-mir"]
178+ path = helix-syntax/languages/tree-sitter-llvm-mir
179+ url = https://github.com/Flakebi/tree-sitter-llvm-mir.git
180+ shallow = true
177[submodule "helix-syntax/languages/tree-sitter-git-diff"]
181[submodule "helix-syntax/languages/tree-sitter-git-diff"]
178 path = helix-syntax/languages/tree-sitter-git-diff
182 path = helix-syntax/languages/tree-sitter-git-diff
179 url = https://github.com/the-mikedavis/tree-sitter-git-diff.git
183 url = https://github.com/the-mikedavis/tree-sitter-git-diff.git
book/src/generated/lang-support.md+2
@@ -24,6 +24,8 @@
24| latex | ✓ | | | |
24| latex | ✓ | | | |
25| ledger | ✓ | | | |
25| ledger | ✓ | | | |
26| llvm | ✓ | ✓ | ✓ | |
26| llvm | ✓ | ✓ | ✓ | |
27+| llvm-mir | ✓ | ✓ | ✓ | |
28+| llvm-mir-yaml | ✓ | | ✓ | |
27| lua | ✓ | | ✓ | |
29| lua | ✓ | | ✓ | |
28| markdown | ✓ | | | |
30| markdown | ✓ | | | |
29| mint | | | | `mint` |
31| mint | | | | `mint` |
helix-core/src/indent.rs+1
@@ -436,6 +436,7 @@ where
436 comment_token: None,
436 comment_token: None,
437 auto_format: false,
437 auto_format: false,
438 diagnostic_severity: Severity::Warning,
438 diagnostic_severity: Severity::Warning,
439+ tree_sitter_library: None,
439 language_server: None,
440 language_server: None,
440 indent: Some(IndentationConfiguration {
441 indent: Some(IndentationConfiguration {
441 tab_width: 4,
442 tab_width: 4,
helix-core/src/syntax.rs+10−3
@@ -67,6 +67,8 @@ pub struct LanguageConfiguration {
67 #[serde(default)]
67 #[serde(default)]
68 pub diagnostic_severity: Severity,
68 pub diagnostic_severity: Severity,
69
69
70+ pub tree_sitter_library: Option<String>, // tree-sitter library name, defaults to language_id
71+
70 // content_regex
72 // content_regex
71 #[serde(default, skip_serializing, deserialize_with = "deserialize_regex")]
73 #[serde(default, skip_serializing, deserialize_with = "deserialize_regex")]
72 pub injection_regex: Option<Regex>,
74 pub injection_regex: Option<Regex>,
@@ -192,9 +194,14 @@ impl LanguageConfiguration {
192 if highlights_query.is_empty() {
194 if highlights_query.is_empty() {
193 None
195 None
194 } else {
196 } else {
195− let language = get_language(&crate::RUNTIME_DIR, &self.language_id)
197+ let language = get_language(
198+ &crate::RUNTIME_DIR,
199+ self.tree_sitter_library
200+ .as_deref()
201+ .unwrap_or(&self.language_id),
202+ )
196− .map_err(|e| log::info!("{}", e))
203+ .map_err(|e| log::info!("{}", e))
197− .ok()?;
204+ .ok()?;
198 let config = HighlightConfiguration::new(
205 let config = HighlightConfiguration::new(
199 language,
206 language,
200 &highlights_query,
207 &highlights_query,
helix-syntax/languages/tree-sitter-llvm-mirnew file+1

Submodule changed.

languages.toml+22
@@ -334,6 +334,7 @@ file-types = ["yml", "yaml"]
334roots = []
334roots = []
335comment-token = "#"
335comment-token = "#"
336indent = { tab-width = 2, unit = " " }
336indent = { tab-width = 2, unit = " " }
337+injection-regex = "yml|yaml"
337
338
338# [[language]]
339# [[language]]
339# name = "haskell"
340# name = "haskell"
@@ -386,6 +387,7 @@ roots = []
386comment-token = "#"
387comment-token = "#"
387indent = { tab-width = 2, unit = " " }
388indent = { tab-width = 2, unit = " " }
388language-server = { command = "cmake-language-server" }
389language-server = { command = "cmake-language-server" }
390+injection-regex = "cmake"
389
391
390[[language]]
392[[language]]
391name = "glsl"
393name = "glsl"
@@ -394,6 +396,7 @@ file-types = ["glsl", "vert", "tesc", "tese", "geom", "frag", "comp" ]
394roots = []
396roots = []
395comment-token = "//"
397comment-token = "//"
396indent = { tab-width = 4, unit = " " }
398indent = { tab-width = 4, unit = " " }
399+injection-regex = "glsl"
397
400
398[[language]]
401[[language]]
399name = "perl"
402name = "perl"
@@ -435,6 +438,25 @@ roots = []
435file-types = ["ll"]
438file-types = ["ll"]
436comment-token = ";"
439comment-token = ";"
437indent = { tab-width = 2, unit = " " }
440indent = { tab-width = 2, unit = " " }
441+injection-regex = "llvm"
442+
443+[[language]]
444+name = "llvm-mir"
445+scope = "source.llvm_mir"
446+roots = []
447+file-types = []
448+comment-token = ";"
449+indent = { tab-width = 2, unit = " " }
450+injection-regex = "mir"
451+
452+[[language]]
453+name = "llvm-mir-yaml"
454+tree-sitter-library = "yaml"
455+scope = "source.yaml"
456+roots = []
457+file-types = ["mir"]
458+comment-token = "#"
459+indent = { tab-width = 2, unit = " " }
438
460
439[[language]]
461[[language]]
440name = "tablegen"
462name = "tablegen"
runtime/queries/llvm-mir-yaml/highlights.scmnew file+1
@@ -0,0 +1 @@
1+; inherits: yaml
runtime/queries/llvm-mir-yaml/indents.tomlnew file+3
@@ -0,0 +1,3 @@
1+indent = [
2+ "block_mapping_pair",
3+]
runtime/queries/llvm-mir-yaml/injections.scmnew file+9
@@ -0,0 +1,9 @@
1+; inherits: yaml
2+
3+((document (block_node (block_scalar) @injection.content))
4+ (#set! injection.language "llvm"))
5+
6+((document (block_node (block_mapping (block_mapping_pair
7+ key: (flow_node (plain_scalar (string_scalar))) ; "body"
8+ value: (block_node (block_scalar) @injection.content)))))
9+ (#set! injection.language "mir"))
runtime/queries/llvm-mir/highlights.scmnew file+136
@@ -0,0 +1,136 @@
1+[
2+ (label)
3+ (bb_ref)
4+] @label
5+
6+[
7+ (comment)
8+ (multiline_comment)
9+] @comment
10+
11+[
12+ "("
13+ ")"
14+ "["
15+ "]"
16+ "{"
17+ "}"
18+ "<"
19+ ">"
20+] @punctuation.bracket
21+
22+[
23+ ","
24+ ":"
25+ "|"
26+ "*"
27+] @punctuation.delimiter
28+
29+[
30+ "="
31+ "x"
32+] @operator
33+
34+[
35+ "true"
36+ "false"
37+] @constant.builtin.boolean
38+
39+[
40+ "null"
41+ "_"
42+ "unknown-address"
43+] @constant.builtin
44+
45+[
46+ (stack_object)
47+ (constant_pool_index)
48+ (jump_table_index)
49+ (var)
50+ (physical_register)
51+ (ir_block)
52+ (external_symbol)
53+ (global_var)
54+ (ir_local_var)
55+ (metadata_ref)
56+ (mnemonic)
57+] @variable
58+
59+(low_level_type) @type
60+
61+[
62+ (immediate_type)
63+ (primitive_type)
64+] @type.builtin
65+
66+(number) @constant.numeric.integer
67+(float) @constant.numeric.float
68+(string) @string
69+
70+(instruction name: _ @keyword.operator)
71+
72+[
73+ "successors"
74+ "liveins"
75+ "pre-instr-symbol"
76+ "post-instr-symbol"
77+ "heap-alloc-marker"
78+ "debug-instr-number"
79+ "debug-location"
80+ "mcsymbol"
81+ "tied-def"
82+ "target-flags"
83+ "CustomRegMask"
84+ "same_value"
85+ "def_cfa_register"
86+ "restore"
87+ "undefined"
88+ "offset"
89+ "rel_offset"
90+ "def_cfa"
91+ "llvm_def_aspace_cfa"
92+ "register"
93+ "escape"
94+ "remember_state"
95+ "restore_state"
96+ "window_save"
97+ "negate_ra_sign_state"
98+ "intpred"
99+ "floatpred"
100+ "shufflemask"
101+ "liveout"
102+ "target-index"
103+ "blockaddress"
104+ "intrinsic"
105+ "load"
106+ "store"
107+ "unknown-size"
108+ "on"
109+ "from"
110+ "into"
111+ "align"
112+ "basealign"
113+ "addrspace"
114+ "call-entry"
115+ "custom"
116+ "constant-pool"
117+ "stack"
118+ "got"
119+ "jump-table"
120+ "syncscope"
121+ "address-taken"
122+ "landing-pad"
123+ "inlineasm-br-indirect-target"
124+ "ehfunclet-entry"
125+ "bbsections"
126+
127+ (intpred)
128+ (floatpred)
129+ (memory_operand_flag)
130+ (atomic_ordering)
131+ (register_flag)
132+ (instruction_flag)
133+ (float_keyword)
134+] @keyword
135+
136+(ERROR) @error
runtime/queries/llvm-mir/indents.tomlnew file+7
@@ -0,0 +1,7 @@
1+indent = [
2+ "basic_block",
3+]
4+
5+outdent = [
6+ "label",
7+]
runtime/queries/llvm-mir/injections.scmnew file+2
@@ -0,0 +1,2 @@
1+([ (comment) (multiline_comment)] @injection.content
2+ (#set! injection.language "comment"))
runtime/queries/llvm-mir/textobjects.scmnew file+3
@@ -0,0 +1,3 @@
1+(basic_block) @function.around
2+
3+(argument) @parameter.inside
runtime/queries/yaml/injections.scmnew file+2
@@ -0,0 +1,2 @@
1+((comment) @injection.content
2+ (#set! injection.language "comment"))