Procházet zdrojové kódy

treesitter: add more highlight rules (#3036)

follow up to #2902
mx42 před 2 roky
rodič
revize
fe49b1b2a6

+ 4 - 4
utils/treesitter/grammar.js

@@ -151,7 +151,7 @@ module.exports = grammar({
         $.struct_type_literal
       ),
 
-    _binding_lhs: ($) => choice($.ident, '_'),
+    binding_lhs: ($) => choice($.ident, '_'),
 
     paren_pattern: ($) =>
       seq(
@@ -163,9 +163,9 @@ module.exports = grammar({
     _pattern_without_expression: ($) =>
       choice(
         'auto',
-        seq($._binding_lhs, ':', $._expression),
-        seq($._binding_lhs, ':!', $._expression),
-        seq('template', $._binding_lhs, ':!', $._expression),
+        seq($.binding_lhs, ':', $._expression),
+        seq($.binding_lhs, ':!', $._expression),
+        seq('template', $.binding_lhs, ':!', $._expression),
         seq('var', $._pattern),
         $.paren_pattern,
         // alternative patterns

+ 6 - 1
utils/treesitter/queries/highlights.scm

@@ -16,7 +16,12 @@
 (function_declaration (declared_name (ident) @function))
 (call_expression (ident) @function)
 
-; TODO: add more specific rules
+(namespace_declaration (declared_name) @namespace)
+(interface_declaration (declared_name) @type)
+(constraint_declaration (declared_name) @type)
+(class_declaration (declared_name) @type)
+(choice_declaration (declared_name) @type)
+(binding_lhs) @variable
 
 ; upper case => type
 ((ident) @type