just: Use updated grammar with recent language changes and correct highlighting (#11380)

This commit is contained in:
Poliorcetics 2024-08-09 17:26:48 +02:00 committed by GitHub
parent 8851031449
commit 68f495b023
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 67 additions and 81 deletions

View file

@ -3105,7 +3105,7 @@ indent = { tab-width = 4, unit = " " }
[[grammar]] [[grammar]]
name = "just" 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]] [[language]]
name = "gn" name = "gn"

View file

@ -1,5 +1,3 @@
; From <https://github.com/IndianBoy42/tree-sitter-just/blob/6c2f018ab1d90946c0ce029bb2f7d57f56895dff/queries-flavored/helix/folds.scm>
; Define collapse points ; Define collapse points
([ ([

View file

@ -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 ; This file specifies how matched syntax patterns should be highlighted
[ [
@ -26,35 +24,57 @@
(identifier) @variable) (identifier) @variable)
(alias (alias
left: (identifier) @variable) name: (identifier) @variable)
(assignment (assignment
left: (identifier) @variable) name: (identifier) @variable)
(shell_variable_name) @variable
; Functions ; Functions
(recipe_header (recipe
name: (identifier) @function) name: (identifier) @function)
(dependency (recipe_dependency
name: (identifier) @function) name: (identifier) @function.call)
(dependency_expression
name: (identifier) @function)
(function_call (function_call
name: (identifier) @function) name: (identifier) @function.builtin)
; Parameters ; Parameters
(parameter (recipe_parameter
name: (identifier) @variable.parameter) name: (identifier) @variable.parameter)
; Namespaces ; Namespaces
(module (mod
name: (identifier) @namespace) 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 ; Operators
[ [
@ -95,55 +115,31 @@
; Literals ; Literals
(boolean) @constant.builtin.boolean ; Booleans are not allowed anywhere except in settings
(setting
(boolean) @constant.builtin.boolean)
[ [
(string) (string)
(external_command) (external_command)
] @string ] @string
(escape_sequence) @constant.character.escape [
(escape_sequence)
(escape_variable_end)
] @constant.character.escape
; Comments ; Comments
(comment) @comment.line (comment) @comment.line
(shebang) @keyword.directive ; highlight known settings
; highlight known settings (filtering does not always work)
(setting (setting
left: (identifier) @keyword name: (_) @keyword.function)
(#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) ; highlight known attributes
(attribute (attribute
(identifier) @attribute name: (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"))
; Numbers are part of the syntax tree, even if disallowed ; Numbers are part of the syntax tree, even if disallowed
(numeric_error) @error (numeric_error) @error

View file

@ -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. ; This query specifies how to auto-indent logical blocks.
; ;
; Better documentation with diagrams is in https://docs.helix-editor.com/guides/indent.html ; Better documentation with diagrams is in https://docs.helix-editor.com/guides/indent.html

View file

@ -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` ; Specify nested languages that live within a `justfile`
; ================ Always applicable ================ ; ================ Always applicable ================
@ -8,7 +6,7 @@
(#set! injection.language "comment")) (#set! injection.language "comment"))
; Highlight the RHS of `=~` as regex ; Highlight the RHS of `=~` as regex
((regex_literal ((regex
(_) @injection.content) (_) @injection.content)
(#set! injection.language "regex")) (#set! injection.language "regex"))
@ -21,7 +19,7 @@
(#set! injection.include-children)) @injection.content (#set! injection.include-children)) @injection.content
(external_command (external_command
(command_body) @injection.content (content) @injection.content
(#set! injection.language "bash")) (#set! injection.language "bash"))
; ================ Global language specified ================ ; ================ Global language specified ================
@ -43,7 +41,7 @@
; they default to bash. Limitations... ; they default to bash. Limitations...
; See https://github.com/tree-sitter/tree-sitter/issues/880 for more on that. ; See https://github.com/tree-sitter/tree-sitter/issues/880 for more on that.
(source_file (file
(setting "shell" ":=" "[" (string) @_langstr (setting "shell" ":=" "[" (string) @_langstr
(#match? @_langstr ".*(powershell|pwsh|cmd).*") (#match? @_langstr ".*(powershell|pwsh|cmd).*")
(#set! injection.language "powershell")) (#set! injection.language "powershell"))
@ -57,10 +55,10 @@
(expression (expression
(value (value
(external_command (external_command
(command_body) @injection.content)))) (content) @injection.content))))
]) ])
(source_file (file
(setting "shell" ":=" "[" (string) @injection.language (setting "shell" ":=" "[" (string) @injection.language
(#not-match? @injection.language ".*(powershell|pwsh|cmd).*")) (#not-match? @injection.language ".*(powershell|pwsh|cmd).*"))
[ [
@ -73,12 +71,12 @@
(expression (expression
(value (value
(external_command (external_command
(command_body) @injection.content)))) (content) @injection.content))))
]) ])
; ================ Recipe language specified - Helix only ================ ; ================ Recipe language specified - Helix only ================
; Set highlighting for recipes that specify a language using builtin shebang matching ; Set highlighting for recipes that specify a language using builtin shebang matching
(recipe_body (recipe_body
(shebang) @injection.shebang (shebang_line) @injection.shebang
(#set! injection.include-children)) @injection.content (#set! injection.include-children)) @injection.content

View file

@ -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 ; This file tells us about the scope of variables so e.g. local
; variables override global functions with the same name ; variables override global functions with the same name
@ -10,32 +8,29 @@
; Definitions ; Definitions
(alias (alias
left: (identifier) @local.definition) name: (identifier) @local.definition)
(assignment (assignment
left: (identifier) @local.definition)
(module
name: (identifier) @local.definition) name: (identifier) @local.definition)
(parameter (mod
name: (identifier) @local.definition) name: (identifier) @local.definition)
(recipe_header (recipe_parameter
name: (identifier) @local.definition)
(recipe
name: (identifier) @local.definition) name: (identifier) @local.definition)
; References ; References
(alias (alias
right: (identifier) @local.reference) name: (identifier) @local.reference)
(function_call (function_call
name: (identifier) @local.reference) name: (identifier) @local.reference)
(dependency (recipe_dependency
name: (identifier) @local.reference)
(dependency_expression
name: (identifier) @local.reference) name: (identifier) @local.reference)
(value (value

View file

@ -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 ; Specify how to navigate around logical blocks in code
(assert_parameters
((_) @parameter.inside . ","? @parameter.around)) @parameter.around
(recipe (recipe
(recipe_body) @function.inside) @function.around (recipe_body) @function.inside) @function.around
(parameters (recipe_parameters
((_) @parameter.inside . ","? @parameter.around)) @parameter.around ((_) @parameter.inside . ","? @parameter.around)) @parameter.around
(dependency_expression (recipe_dependency
(_) @parameter.inside) @parameter.around (_) @parameter.inside) @parameter.around
(function_call (function_call
arguments: (sequence (function_parameters
(expression) @parameter.inside) @parameter.around) @function.around ((_) @parameter.inside . ","? @parameter.around)) @parameter.around) @function.around
(comment) @comment.around (comment) @comment.around