Unnamed repository; edit this file 'description' to name the repository.
just: Use updated grammar with recent language changes and correct highlighting (#11380)
Poliorcetics 2024-08-09
parent 8851031 · commit 68f495b
-rw-r--r--languages.toml2
-rw-r--r--runtime/queries/just/folds.scm2
-rw-r--r--runtime/queries/just/highlights.scm94
-rw-r--r--runtime/queries/just/indents.scm2
-rw-r--r--runtime/queries/just/injections.scm16
-rw-r--r--runtime/queries/just/locals.scm19
-rw-r--r--runtime/queries/just/textobjects.scm13
7 files changed, 67 insertions, 81 deletions
diff --git a/languages.toml b/languages.toml
index 3288788a..b1dfd0d6 100644
--- a/languages.toml
+++ b/languages.toml
@@ -3105,7 +3105,7 @@ indent = { tab-width = 4, unit = " " }
[[grammar]]
name = "just"
-source = { git = "https://github.com/IndianBoy42/tree-sitter-just", rev = "379fbe36d1e441bc9414ea050ad0c85c9d6935ea" }
+source = { git = "https://github.com/poliorcetics/tree-sitter-just", rev = "f58a8fd869035ac4653081401e6c2030251240ab" }
[[language]]
name = "gn"
diff --git a/runtime/queries/just/folds.scm b/runtime/queries/just/folds.scm
index 77079fd4..2640f4c4 100644
--- a/runtime/queries/just/folds.scm
+++ b/runtime/queries/just/folds.scm
@@ -1,5 +1,3 @@
-; From <https://github.com/IndianBoy42/tree-sitter-just/blob/6c2f018ab1d90946c0ce029bb2f7d57f56895dff/queries-flavored/helix/folds.scm>
-
; Define collapse points
([
diff --git a/runtime/queries/just/highlights.scm b/runtime/queries/just/highlights.scm
index d5e5cc19..258fadb9 100644
--- a/runtime/queries/just/highlights.scm
+++ b/runtime/queries/just/highlights.scm
@@ -1,5 +1,3 @@
-; From <https://github.com/IndianBoy42/tree-sitter-just/blob/6c2f018ab1d90946c0ce029bb2f7d57f56895dff/queries-flavored/helix/highlights.scm>
-
; This file specifies how matched syntax patterns should be highlighted
[
@@ -26,35 +24,57 @@
(identifier) @variable)
(alias
- left: (identifier) @variable)
+ name: (identifier) @variable)
(assignment
- left: (identifier) @variable)
+ name: (identifier) @variable)
-; Functions
+(shell_variable_name) @variable
-(recipe_header
- name: (identifier) @function)
+; Functions
-(dependency
+(recipe
name: (identifier) @function)
-(dependency_expression
- name: (identifier) @function)
+(recipe_dependency
+ name: (identifier) @function.call)
(function_call
- name: (identifier) @function)
+ name: (identifier) @function.builtin)
; Parameters
-(parameter
+(recipe_parameter
name: (identifier) @variable.parameter)
; Namespaces
-(module
+(mod
name: (identifier) @namespace)
+; Paths
+
+(mod
+ (path) @string.special.path)
+
+(import
+ (path) @string.special.path)
+
+; Shebangs
+
+(shebang_line) @keyword.directive
+(shebang_line
+ (shebang_shell) @string.special)
+
+
+(shell_expanded_string
+ [
+ (expansion_short_start)
+ (expansion_long_start)
+ (expansion_long_middle)
+ (expansion_long_end)
+ ] @punctuation.special)
+
; Operators
[
@@ -95,55 +115,31 @@
; Literals
-(boolean) @constant.builtin.boolean
+; Booleans are not allowed anywhere except in settings
+(setting
+ (boolean) @constant.builtin.boolean)
[
(string)
(external_command)
] @string
-(escape_sequence) @constant.character.escape
+[
+ (escape_sequence)
+ (escape_variable_end)
+] @constant.character.escape
; Comments
(comment) @comment.line
-(shebang) @keyword.directive
-
-; highlight known settings (filtering does not always work)
+; highlight known settings
(setting
- left: (identifier) @keyword
- (#any-of? @keyword
- "allow-duplicate-recipes"
- "dotenv-filename"
- "dotenv-load"
- "dotenv-path"
- "export"
- "fallback"
- "ignore-comments"
- "positional-arguments"
- "shell"
- "tempdi"
- "windows-powershell"
- "windows-shell"))
-
-; highlight known attributes (filtering does not always work)
+ name: (_) @keyword.function)
+
+; highlight known attributes
(attribute
- (identifier) @attribute
- (#any-of? @attribute
- "private"
- "allow-duplicate-recipes"
- "dotenv-filename"
- "dotenv-load"
- "dotenv-path"
- "export"
- "fallback"
- "ignore-comments"
- "positional-arguments"
- "shell"
- "tempdi"
- "windows-powershell"
- "windows-shell"))
+ name: (identifier) @attribute)
; Numbers are part of the syntax tree, even if disallowed
(numeric_error) @error
diff --git a/runtime/queries/just/indents.scm b/runtime/queries/just/indents.scm
index 7cfca3d7..c66dda4c 100644
--- a/runtime/queries/just/indents.scm
+++ b/runtime/queries/just/indents.scm
@@ -1,5 +1,3 @@
-; From <https://github.com/IndianBoy42/tree-sitter-just/blob/6c2f018ab1d90946c0ce029bb2f7d57f56895dff/queries-flavored/helix/indents.scm>
-;
; This query specifies how to auto-indent logical blocks.
;
; Better documentation with diagrams is in https://docs.helix-editor.com/guides/indent.html
diff --git a/runtime/queries/just/injections.scm b/runtime/queries/just/injections.scm
index 54393059..39877be4 100644
--- a/runtime/queries/just/injections.scm
+++ b/runtime/queries/just/injections.scm
@@ -1,5 +1,3 @@
-; From <https://github.com/IndianBoy42/tree-sitter-just/blob/6c2f018ab1d90946c0ce029bb2f7d57f56895dff/queries-flavored/helix/injections.scm>
-;
; Specify nested languages that live within a `justfile`
; ================ Always applicable ================
@@ -8,7 +6,7 @@
(#set! injection.language "comment"))
; Highlight the RHS of `=~` as regex
-((regex_literal
+((regex
(_) @injection.content)
(#set! injection.language "regex"))
@@ -21,7 +19,7 @@
(#set! injection.include-children)) @injection.content
(external_command
- (command_body) @injection.content
+ (content) @injection.content
(#set! injection.language "bash"))
; ================ Global language specified ================
@@ -43,7 +41,7 @@
; they default to bash. Limitations...
; See https://github.com/tree-sitter/tree-sitter/issues/880 for more on that.
-(source_file
+(file
(setting "shell" ":=" "[" (string) @_langstr
(#match? @_langstr ".*(powershell|pwsh|cmd).*")
(#set! injection.language "powershell"))
@@ -57,10 +55,10 @@
(expression
(value
(external_command
- (command_body) @injection.content))))
+ (content) @injection.content))))
])
-(source_file
+(file
(setting "shell" ":=" "[" (string) @injection.language
(#not-match? @injection.language ".*(powershell|pwsh|cmd).*"))
[
@@ -73,12 +71,12 @@
(expression
(value
(external_command
- (command_body) @injection.content))))
+ (content) @injection.content))))
])
; ================ Recipe language specified - Helix only ================
; Set highlighting for recipes that specify a language using builtin shebang matching
(recipe_body
- (shebang) @injection.shebang
+ (shebang_line) @injection.shebang
(#set! injection.include-children)) @injection.content
diff --git a/runtime/queries/just/locals.scm b/runtime/queries/just/locals.scm
index 827148a1..d612f5da 100644
--- a/runtime/queries/just/locals.scm
+++ b/runtime/queries/just/locals.scm
@@ -1,5 +1,3 @@
-; From <https://github.com/IndianBoy42/tree-sitter-just/blob/6c2f018ab1d90946c0ce029bb2f7d57f56895dff/queries-flavored/helix/locals.scm>
-;
; This file tells us about the scope of variables so e.g. local
; variables override global functions with the same name
@@ -10,32 +8,29 @@
; Definitions
(alias
- left: (identifier) @local.definition)
+ name: (identifier) @local.definition)
(assignment
- left: (identifier) @local.definition)
+ name: (identifier) @local.definition)
-(module
+(mod
name: (identifier) @local.definition)
-(parameter
+(recipe_parameter
name: (identifier) @local.definition)
-(recipe_header
+(recipe
name: (identifier) @local.definition)
; References
(alias
- right: (identifier) @local.reference)
-
-(function_call
name: (identifier) @local.reference)
-(dependency
+(function_call
name: (identifier) @local.reference)
-(dependency_expression
+(recipe_dependency
name: (identifier) @local.reference)
(value
diff --git a/runtime/queries/just/textobjects.scm b/runtime/queries/just/textobjects.scm
index bb604178..b60b11e4 100644
--- a/runtime/queries/just/textobjects.scm
+++ b/runtime/queries/just/textobjects.scm
@@ -1,18 +1,19 @@
-; From <https://github.com/IndianBoy42/tree-sitter-just/blob/6c2f018ab1d90946c0ce029bb2f7d57f56895dff/queries-flavored/helix/textobjects.scm>
-;
; Specify how to navigate around logical blocks in code
+(assert_parameters
+ ((_) @parameter.inside . ","? @parameter.around)) @parameter.around
+
(recipe
(recipe_body) @function.inside) @function.around
-(parameters
+(recipe_parameters
((_) @parameter.inside . ","? @parameter.around)) @parameter.around
-(dependency_expression
+(recipe_dependency
(_) @parameter.inside) @parameter.around
(function_call
- arguments: (sequence
- (expression) @parameter.inside) @parameter.around) @function.around
+ (function_parameters
+ ((_) @parameter.inside . ","? @parameter.around)) @parameter.around) @function.around
(comment) @comment.around