diff --git a/build-flavored-queries.py b/build-flavored-queries.py index 912c3e1..fd64af6 100755 --- a/build-flavored-queries.py +++ b/build-flavored-queries.py @@ -338,7 +338,7 @@ (r"(@[\w.]+).inside", "\1.inner"), (r"(@[\w.]+).around", "\1.outer"), # nvim does not have `injection.include-children` - (r"\n?\s*\(\s*#set!\s*injection\.include-children\s*\)", "", re.MULTILINE), + (r"\s*\n?\s*\(\s*#set!\s*injection\.include-children\s*\)", "", re.MULTILINE), # nvim uses `var` rather than `variable` (r"(@[\w.]+)\.variable", r"\1.var"), # nothing more specific than reference @@ -523,7 +523,18 @@ def main(): allowed_settings, basepath, ) in FLAVOR_MAPPINGS: - contents = base_contents + # Remove lines as indicated by directives + contents = "\n".join( + ( + line + for line in base_contents.splitlines() + if f"SKIP-{tag}" not in line + ) + ) + + # Delete other directives + contents = re.sub(r";?\s*SKIP-[\w-]+", "", contents) + for rep in replacements: pat = rep[0] sub = rep[1] @@ -532,14 +543,8 @@ def main(): flags = rep[2] contents = re.sub(pat, sub, contents, flags=flags) - contents = "\n".join( - (line for line in contents.splitlines() if f"SKIP-{tag}" not in line) - ) - - # Delete directives - contents = re.sub(r"SKIP-[\w-]+", "", contents) # Remove trailing whitespace and duplicate newlines - contents = re.sub(r"\s*;?\s+$", "", contents) + contents = re.sub(r"[\s;]+$", "", contents) contents = re.sub(r"((?:\r?\n){2,})(?:\r?\n)+", r"\1", contents) if not contents.endswith("\n"): diff --git a/queries-flavored/helix/highlights.scm b/queries-flavored/helix/highlights.scm index a7d0916..7214ebd 100644 --- a/queries-flavored/helix/highlights.scm +++ b/queries-flavored/helix/highlights.scm @@ -22,29 +22,38 @@ ; Variables -(value (identifier) @variable) +(value + (identifier) @variable) -(alias left: (identifier) @variable) +(alias + left: (identifier) @variable) -(assignment left: (identifier) @variable) +(assignment + left: (identifier) @variable) ; Functions -(recipe_header name: (identifier) @function) +(recipe_header + name: (identifier) @function) -(dependency name: (identifier) @function) +(dependency + name: (identifier) @function) -(dependency_expression name: (identifier) @function) +(dependency_expression + name: (identifier) @function) -(function_call name: (identifier) @function) +(function_call + name: (identifier) @function) ; Parameters -(parameter name: (identifier) @variable.parameter) +(parameter + name: (identifier) @variable.parameter) ; Namespaces -(module name: (identifier) @namespace) +(module + name: (identifier) @namespace) ; Operators @@ -103,7 +112,7 @@ ; highlight known settings (filtering does not always work) (setting - left: ((identifier) @keyword + left: (identifier) @keyword (#any-of? @keyword "allow-duplicate-recipes" "dotenv-filename" @@ -116,27 +125,25 @@ "shell" "tempdi" "windows-powershell" - "windows-shell" - ))) + "windows-shell")) ; highlight known attributes (filtering does not always work) (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" - ))) + (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 (numeric_error) @error diff --git a/queries-flavored/helix/indents.scm b/queries-flavored/helix/indents.scm index 0a9fd7f..325b50f 100644 --- a/queries-flavored/helix/indents.scm +++ b/queries-flavored/helix/indents.scm @@ -1,8 +1,8 @@ ; File autogenerated by build-queries-nvim.py; do not edit -; This query +; This query specifies how to auto-indent logical blocks. ; -; Better documentation is in https://docs.helix-editor.com/guides/indent.html +; Better documentation with diagrams is in https://docs.helix-editor.com/guides/indent.html [ (recipe) diff --git a/queries-flavored/helix/injections.scm b/queries-flavored/helix/injections.scm index a94aa6e..bbf0dd3 100644 --- a/queries-flavored/helix/injections.scm +++ b/queries-flavored/helix/injections.scm @@ -2,15 +2,13 @@ ; Specify nested languages that live within a `justfile` -; FIXME: these are not compatible with helix due to precedence +; FIXME: these are not compatible with helix due to precedence ; ================ Always applicable ================ ((comment) @injection.content (#set! injection.language "comment")) -(comment) @comment - ; Highlight the RHS of `=~` as regex ((regex_literal (_) @injection.content) (#set! injection.language "regex")) @@ -54,7 +52,10 @@ (recipe_body (#set! injection.include-children)) @injection.content) (assignment - (expression (value (external_command (command_body) @injection.content)))) + (expression + (value + (external_command + (command_body) @injection.content)))) ]) (source_file @@ -62,15 +63,19 @@ (#not-match? @injection.language ".*(powershell|pwsh|cmd).*")) [ (recipe - (recipe_body (#set! injection.include-children)) @injection.content) + (recipe_body + (#set! injection.include-children)) @injection.content) (assignment - (expression (value (external_command (command_body) @injection.content)))) + (expression + (value + (external_command + (command_body) @injection.content)))) ]) -; ================ Recipe language specified ================ - -; Set highlighting for recipes that specify a language -(recipe_body - (shebang (language) @injection.language) +; ================ Recipe language specified - Helix only ================ + +; Set highlighting for recipes that specify a language using builtin shebang matching +(recipe_body + (shebang) @injection.shebang (#set! injection.include-children)) @injection.content diff --git a/queries-flavored/helix/locals.scm b/queries-flavored/helix/locals.scm index d77b2ad..89fc8b3 100644 --- a/queries-flavored/helix/locals.scm +++ b/queries-flavored/helix/locals.scm @@ -9,24 +9,34 @@ ; Definitions -(alias left: (identifier) @local.definition.variable) +(alias + left: (identifier) @local.definition.variable) -(assignment left: (identifier) @local.definition.variable) +(assignment + left: (identifier) @local.definition.variable) -(module name: (identifier) @local.definition.namespace) +(module + name: (identifier) @local.definition.namespace) -(parameter name: (identifier) @local.definition.variable) +(parameter + name: (identifier) @local.definition.variable) -(recipe_header name: (identifier) @local.definition.function) +(recipe_header + name: (identifier) @local.definition.function) ; References -(alias right: (identifier) @local.reference) +(alias + right: (identifier) @local.reference) -(function_call name: (identifier) @local.reference) +(function_call + name: (identifier) @local.reference) -(dependency name: (identifier) @local.reference) +(dependency + name: (identifier) @local.reference) -(dependency_expression name: (identifier) @local.reference) +(dependency_expression + name: (identifier) @local.reference) -(value (identifier) @local.reference) +(value + (identifier) @local.reference) diff --git a/queries-flavored/helix/textobjects.scm b/queries-flavored/helix/textobjects.scm index aadb833..bf988e3 100644 --- a/queries-flavored/helix/textobjects.scm +++ b/queries-flavored/helix/textobjects.scm @@ -12,6 +12,7 @@ (_) @parameter.inside) @parameter.around (function_call - arguments: (sequence (expression) @parameter.inside) @parameter.around) @function.around + arguments: (sequence + (expression) @parameter.inside) @parameter.around) @function.around (comment) @comment.around diff --git a/queries-flavored/lapce/highlights.scm b/queries-flavored/lapce/highlights.scm index a7d0916..7214ebd 100644 --- a/queries-flavored/lapce/highlights.scm +++ b/queries-flavored/lapce/highlights.scm @@ -22,29 +22,38 @@ ; Variables -(value (identifier) @variable) +(value + (identifier) @variable) -(alias left: (identifier) @variable) +(alias + left: (identifier) @variable) -(assignment left: (identifier) @variable) +(assignment + left: (identifier) @variable) ; Functions -(recipe_header name: (identifier) @function) +(recipe_header + name: (identifier) @function) -(dependency name: (identifier) @function) +(dependency + name: (identifier) @function) -(dependency_expression name: (identifier) @function) +(dependency_expression + name: (identifier) @function) -(function_call name: (identifier) @function) +(function_call + name: (identifier) @function) ; Parameters -(parameter name: (identifier) @variable.parameter) +(parameter + name: (identifier) @variable.parameter) ; Namespaces -(module name: (identifier) @namespace) +(module + name: (identifier) @namespace) ; Operators @@ -103,7 +112,7 @@ ; highlight known settings (filtering does not always work) (setting - left: ((identifier) @keyword + left: (identifier) @keyword (#any-of? @keyword "allow-duplicate-recipes" "dotenv-filename" @@ -116,27 +125,25 @@ "shell" "tempdi" "windows-powershell" - "windows-shell" - ))) + "windows-shell")) ; highlight known attributes (filtering does not always work) (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" - ))) + (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 (numeric_error) @error diff --git a/queries-flavored/lapce/indents.scm b/queries-flavored/lapce/indents.scm index 0a9fd7f..325b50f 100644 --- a/queries-flavored/lapce/indents.scm +++ b/queries-flavored/lapce/indents.scm @@ -1,8 +1,8 @@ ; File autogenerated by build-queries-nvim.py; do not edit -; This query +; This query specifies how to auto-indent logical blocks. ; -; Better documentation is in https://docs.helix-editor.com/guides/indent.html +; Better documentation with diagrams is in https://docs.helix-editor.com/guides/indent.html [ (recipe) diff --git a/queries-flavored/lapce/injections.scm b/queries-flavored/lapce/injections.scm index a94aa6e..fb8aed4 100644 --- a/queries-flavored/lapce/injections.scm +++ b/queries-flavored/lapce/injections.scm @@ -2,15 +2,13 @@ ; Specify nested languages that live within a `justfile` -; FIXME: these are not compatible with helix due to precedence +; FIXME: these are not compatible with helix due to precedence ; ================ Always applicable ================ ((comment) @injection.content (#set! injection.language "comment")) -(comment) @comment - ; Highlight the RHS of `=~` as regex ((regex_literal (_) @injection.content) (#set! injection.language "regex")) @@ -54,7 +52,10 @@ (recipe_body (#set! injection.include-children)) @injection.content) (assignment - (expression (value (external_command (command_body) @injection.content)))) + (expression + (value + (external_command + (command_body) @injection.content)))) ]) (source_file @@ -62,15 +63,39 @@ (#not-match? @injection.language ".*(powershell|pwsh|cmd).*")) [ (recipe - (recipe_body (#set! injection.include-children)) @injection.content) + (recipe_body + (#set! injection.include-children)) @injection.content) (assignment - (expression (value (external_command (command_body) @injection.content)))) + (expression + (value + (external_command + (command_body) @injection.content)))) ]) -; ================ Recipe language specified ================ - -; Set highlighting for recipes that specify a language -(recipe_body - (shebang (language) @injection.language) +; ================ Recipe language specified ================ + +; Set highlighting for recipes that specify a language, using the exact name by default +(recipe_body ; + (shebang ; + (language) @injection.language) ; + (#not-any-of? @injection.language "python3" "nodejs" "node") + (#set! injection.include-children)) @injection.content + +; Transform some known executables + +; python3 -> python +(recipe_body + (shebang + (language) @_lang) + (#eq? @_lang "python3") + (#set! injection.language "python") + (#set! injection.include-children)) @injection.content + +; node/nodejs -> javascript +(recipe_body + (shebang + (language) @_lang) + (#any-of? @_lang "node" "nodejs") + (#set! injection.language "javascript") (#set! injection.include-children)) @injection.content diff --git a/queries-flavored/lapce/locals.scm b/queries-flavored/lapce/locals.scm index d77b2ad..89fc8b3 100644 --- a/queries-flavored/lapce/locals.scm +++ b/queries-flavored/lapce/locals.scm @@ -9,24 +9,34 @@ ; Definitions -(alias left: (identifier) @local.definition.variable) +(alias + left: (identifier) @local.definition.variable) -(assignment left: (identifier) @local.definition.variable) +(assignment + left: (identifier) @local.definition.variable) -(module name: (identifier) @local.definition.namespace) +(module + name: (identifier) @local.definition.namespace) -(parameter name: (identifier) @local.definition.variable) +(parameter + name: (identifier) @local.definition.variable) -(recipe_header name: (identifier) @local.definition.function) +(recipe_header + name: (identifier) @local.definition.function) ; References -(alias right: (identifier) @local.reference) +(alias + right: (identifier) @local.reference) -(function_call name: (identifier) @local.reference) +(function_call + name: (identifier) @local.reference) -(dependency name: (identifier) @local.reference) +(dependency + name: (identifier) @local.reference) -(dependency_expression name: (identifier) @local.reference) +(dependency_expression + name: (identifier) @local.reference) -(value (identifier) @local.reference) +(value + (identifier) @local.reference) diff --git a/queries-flavored/lapce/textobjects.scm b/queries-flavored/lapce/textobjects.scm index aadb833..bf988e3 100644 --- a/queries-flavored/lapce/textobjects.scm +++ b/queries-flavored/lapce/textobjects.scm @@ -12,6 +12,7 @@ (_) @parameter.inside) @parameter.around (function_call - arguments: (sequence (expression) @parameter.inside) @parameter.around) @function.around + arguments: (sequence + (expression) @parameter.inside) @parameter.around) @function.around (comment) @comment.around diff --git a/queries-flavored/nvim-next/highlights.scm b/queries-flavored/nvim-next/highlights.scm index 4dd2ea8..1048d26 100644 --- a/queries-flavored/nvim-next/highlights.scm +++ b/queries-flavored/nvim-next/highlights.scm @@ -22,29 +22,38 @@ ; Variables -(value (identifier) @variable) +(value + (identifier) @variable) -(alias left: (identifier) @variable) +(alias + left: (identifier) @variable) -(assignment left: (identifier) @variable) +(assignment + left: (identifier) @variable) ; Functions -(recipe_header name: (identifier) @function) +(recipe_header + name: (identifier) @function) -(dependency name: (identifier) @function.call) +(dependency + name: (identifier) @function.call) -(dependency_expression name: (identifier) @function.call) +(dependency_expression + name: (identifier) @function.call) -(function_call name: (identifier) @function.call) +(function_call + name: (identifier) @function.call) ; Parameters -(parameter name: (identifier) @variable.parameter) +(parameter + name: (identifier) @variable.parameter) ; Namespaces -(module name: (identifier) @module) +(module + name: (identifier) @module) ; Operators @@ -103,7 +112,7 @@ ; highlight known settings (filtering does not always work) (setting - left: ((identifier) @keyword + left: (identifier) @keyword (#any-of? @keyword "allow-duplicate-recipes" "dotenv-filename" @@ -116,27 +125,25 @@ "shell" "tempdi" "windows-powershell" - "windows-shell" - ))) + "windows-shell")) ; highlight known attributes (filtering does not always work) (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" - ))) + (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 (numeric_error) @error diff --git a/queries-flavored/nvim-next/indents.scm b/queries-flavored/nvim-next/indents.scm index ccc68a5..a7f5228 100644 --- a/queries-flavored/nvim-next/indents.scm +++ b/queries-flavored/nvim-next/indents.scm @@ -1,8 +1,7 @@ ; File autogenerated by build-queries-nvim.py; do not edit -; This query +; This query specifies how to auto-indent logical blocks. ; -; Better documentation is in https://docs.helix-editor.com/guides/indent.html [ (recipe) diff --git a/queries-flavored/nvim-next/injections.scm b/queries-flavored/nvim-next/injections.scm index 218b94b..0bb650f 100644 --- a/queries-flavored/nvim-next/injections.scm +++ b/queries-flavored/nvim-next/injections.scm @@ -7,8 +7,6 @@ ((comment) @injection.content (#set! injection.language "comment")) -(comment) @comment - ; Highlight the RHS of `=~` as regex ((regex_literal (_) @injection.content) (#set! injection.language "regex")) @@ -51,7 +49,10 @@ (recipe_body) @injection.content) (assignment - (expression (value (external_command (command_body) @injection.content)))) + (expression + (value + (external_command + (command_body) @injection.content)))) ]) (source_file @@ -62,11 +63,32 @@ (recipe_body) @injection.content) (assignment - (expression (value (external_command (command_body) @injection.content)))) + (expression + (value + (external_command + (command_body) @injection.content)))) ]) -; ================ Recipe language specified ================ - -; Set highlighting for recipes that specify a language -(recipe_body - (shebang (language) @injection.language)) @injection.content +; ================ Recipe language specified ================ + +; Set highlighting for recipes that specify a language, using the exact name by default +(recipe_body ; + (shebang ; + (language) @injection.language) ; + (#not-any-of? @injection.language "python3" "nodejs" "node")) @injection.content + +; Transform some known executables + +; python3 -> python +(recipe_body + (shebang + (language) @_lang) + (#eq? @_lang "python3") + (#set! injection.language "python")) @injection.content + +; node/nodejs -> javascript +(recipe_body + (shebang + (language) @_lang) + (#any-of? @_lang "node" "nodejs") + (#set! injection.language "javascript")) @injection.content diff --git a/queries-flavored/nvim-next/locals.scm b/queries-flavored/nvim-next/locals.scm index 76af6fb..ec9bc79 100644 --- a/queries-flavored/nvim-next/locals.scm +++ b/queries-flavored/nvim-next/locals.scm @@ -9,24 +9,34 @@ ; Definitions -(alias left: (identifier) @local.definition.var) +(alias + left: (identifier) @local.definition.var) -(assignment left: (identifier) @local.definition.var) +(assignment + left: (identifier) @local.definition.var) -(module name: (identifier) @local.definition.namespace) +(module + name: (identifier) @local.definition.namespace) -(parameter name: (identifier) @local.definition.var) +(parameter + name: (identifier) @local.definition.var) -(recipe_header name: (identifier) @local.definition.function) +(recipe_header + name: (identifier) @local.definition.function) ; References -(alias right: (identifier) @local.reference) +(alias + right: (identifier) @local.reference) -(function_call name: (identifier) @local.reference) +(function_call + name: (identifier) @local.reference) -(dependency name: (identifier) @local.reference) +(dependency + name: (identifier) @local.reference) -(dependency_expression name: (identifier) @local.reference) +(dependency_expression + name: (identifier) @local.reference) -(value (identifier) @local.reference) +(value + (identifier) @local.reference) diff --git a/queries-flavored/nvim-next/textobjects.scm b/queries-flavored/nvim-next/textobjects.scm index 6a0cd4f..95d40cf 100644 --- a/queries-flavored/nvim-next/textobjects.scm +++ b/queries-flavored/nvim-next/textobjects.scm @@ -12,6 +12,7 @@ (_) .inner) .outer (function_call - arguments: (sequence (expression) .inner) .outer) .outer + arguments: (sequence + (expression) .inner) .outer) .outer (comment) .outer diff --git a/queries-flavored/zed/highlights.scm b/queries-flavored/zed/highlights.scm index a7d0916..7214ebd 100644 --- a/queries-flavored/zed/highlights.scm +++ b/queries-flavored/zed/highlights.scm @@ -22,29 +22,38 @@ ; Variables -(value (identifier) @variable) +(value + (identifier) @variable) -(alias left: (identifier) @variable) +(alias + left: (identifier) @variable) -(assignment left: (identifier) @variable) +(assignment + left: (identifier) @variable) ; Functions -(recipe_header name: (identifier) @function) +(recipe_header + name: (identifier) @function) -(dependency name: (identifier) @function) +(dependency + name: (identifier) @function) -(dependency_expression name: (identifier) @function) +(dependency_expression + name: (identifier) @function) -(function_call name: (identifier) @function) +(function_call + name: (identifier) @function) ; Parameters -(parameter name: (identifier) @variable.parameter) +(parameter + name: (identifier) @variable.parameter) ; Namespaces -(module name: (identifier) @namespace) +(module + name: (identifier) @namespace) ; Operators @@ -103,7 +112,7 @@ ; highlight known settings (filtering does not always work) (setting - left: ((identifier) @keyword + left: (identifier) @keyword (#any-of? @keyword "allow-duplicate-recipes" "dotenv-filename" @@ -116,27 +125,25 @@ "shell" "tempdi" "windows-powershell" - "windows-shell" - ))) + "windows-shell")) ; highlight known attributes (filtering does not always work) (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" - ))) + (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 (numeric_error) @error diff --git a/queries-flavored/zed/indents.scm b/queries-flavored/zed/indents.scm index 0a9fd7f..325b50f 100644 --- a/queries-flavored/zed/indents.scm +++ b/queries-flavored/zed/indents.scm @@ -1,8 +1,8 @@ ; File autogenerated by build-queries-nvim.py; do not edit -; This query +; This query specifies how to auto-indent logical blocks. ; -; Better documentation is in https://docs.helix-editor.com/guides/indent.html +; Better documentation with diagrams is in https://docs.helix-editor.com/guides/indent.html [ (recipe) diff --git a/queries-flavored/zed/injections.scm b/queries-flavored/zed/injections.scm index a94aa6e..fb8aed4 100644 --- a/queries-flavored/zed/injections.scm +++ b/queries-flavored/zed/injections.scm @@ -2,15 +2,13 @@ ; Specify nested languages that live within a `justfile` -; FIXME: these are not compatible with helix due to precedence +; FIXME: these are not compatible with helix due to precedence ; ================ Always applicable ================ ((comment) @injection.content (#set! injection.language "comment")) -(comment) @comment - ; Highlight the RHS of `=~` as regex ((regex_literal (_) @injection.content) (#set! injection.language "regex")) @@ -54,7 +52,10 @@ (recipe_body (#set! injection.include-children)) @injection.content) (assignment - (expression (value (external_command (command_body) @injection.content)))) + (expression + (value + (external_command + (command_body) @injection.content)))) ]) (source_file @@ -62,15 +63,39 @@ (#not-match? @injection.language ".*(powershell|pwsh|cmd).*")) [ (recipe - (recipe_body (#set! injection.include-children)) @injection.content) + (recipe_body + (#set! injection.include-children)) @injection.content) (assignment - (expression (value (external_command (command_body) @injection.content)))) + (expression + (value + (external_command + (command_body) @injection.content)))) ]) -; ================ Recipe language specified ================ - -; Set highlighting for recipes that specify a language -(recipe_body - (shebang (language) @injection.language) +; ================ Recipe language specified ================ + +; Set highlighting for recipes that specify a language, using the exact name by default +(recipe_body ; + (shebang ; + (language) @injection.language) ; + (#not-any-of? @injection.language "python3" "nodejs" "node") + (#set! injection.include-children)) @injection.content + +; Transform some known executables + +; python3 -> python +(recipe_body + (shebang + (language) @_lang) + (#eq? @_lang "python3") + (#set! injection.language "python") + (#set! injection.include-children)) @injection.content + +; node/nodejs -> javascript +(recipe_body + (shebang + (language) @_lang) + (#any-of? @_lang "node" "nodejs") + (#set! injection.language "javascript") (#set! injection.include-children)) @injection.content diff --git a/queries-flavored/zed/locals.scm b/queries-flavored/zed/locals.scm index d77b2ad..89fc8b3 100644 --- a/queries-flavored/zed/locals.scm +++ b/queries-flavored/zed/locals.scm @@ -9,24 +9,34 @@ ; Definitions -(alias left: (identifier) @local.definition.variable) +(alias + left: (identifier) @local.definition.variable) -(assignment left: (identifier) @local.definition.variable) +(assignment + left: (identifier) @local.definition.variable) -(module name: (identifier) @local.definition.namespace) +(module + name: (identifier) @local.definition.namespace) -(parameter name: (identifier) @local.definition.variable) +(parameter + name: (identifier) @local.definition.variable) -(recipe_header name: (identifier) @local.definition.function) +(recipe_header + name: (identifier) @local.definition.function) ; References -(alias right: (identifier) @local.reference) +(alias + right: (identifier) @local.reference) -(function_call name: (identifier) @local.reference) +(function_call + name: (identifier) @local.reference) -(dependency name: (identifier) @local.reference) +(dependency + name: (identifier) @local.reference) -(dependency_expression name: (identifier) @local.reference) +(dependency_expression + name: (identifier) @local.reference) -(value (identifier) @local.reference) +(value + (identifier) @local.reference) diff --git a/queries-flavored/zed/textobjects.scm b/queries-flavored/zed/textobjects.scm index aadb833..bf988e3 100644 --- a/queries-flavored/zed/textobjects.scm +++ b/queries-flavored/zed/textobjects.scm @@ -12,6 +12,7 @@ (_) @parameter.inside) @parameter.around (function_call - arguments: (sequence (expression) @parameter.inside) @parameter.around) @function.around + arguments: (sequence + (expression) @parameter.inside) @parameter.around) @function.around (comment) @comment.around diff --git a/queries-src/highlights.scm b/queries-src/highlights.scm index 6059d35..ef49bfa 100644 --- a/queries-src/highlights.scm +++ b/queries-src/highlights.scm @@ -20,29 +20,38 @@ ; Variables -(value (identifier) @variable) +(value + (identifier) @variable) -(alias left: (identifier) @variable) +(alias + left: (identifier) @variable) -(assignment left: (identifier) @variable) +(assignment + left: (identifier) @variable) ; Functions -(recipe_header name: (identifier) @function) +(recipe_header + name: (identifier) @function) -(dependency name: (identifier) @function.call) +(dependency + name: (identifier) @function.call) -(dependency_expression name: (identifier) @function.call) +(dependency_expression + name: (identifier) @function.call) -(function_call name: (identifier) @function.call) +(function_call + name: (identifier) @function.call) ; Parameters -(parameter name: (identifier) @variable.parameter) +(parameter + name: (identifier) @variable.parameter) ; Namespaces -(module name: (identifier) @namespace) +(module + name: (identifier) @namespace) ; Operators @@ -101,7 +110,7 @@ ; highlight known settings (filtering does not always work) (setting - left: ((identifier) @keyword + left: (identifier) @keyword (#any-of? @keyword "allow-duplicate-recipes" "dotenv-filename" @@ -114,27 +123,25 @@ "shell" "tempdi" "windows-powershell" - "windows-shell" - ))) + "windows-shell")) ; highlight known attributes (filtering does not always work) (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" - ))) + (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 (numeric_error) @error diff --git a/queries-src/indents.scm b/queries-src/indents.scm index c61474d..f292688 100644 --- a/queries-src/indents.scm +++ b/queries-src/indents.scm @@ -1,6 +1,6 @@ -; This query +; This query specifies how to auto-indent logical blocks. ; -; Better documentation is in https://docs.helix-editor.com/guides/indent.html +; Better documentation with diagrams is in https://docs.helix-editor.com/guides/indent.html SKIP-NVIM SKIP-NVIM-NEXT [ (recipe) diff --git a/queries-src/injections.scm b/queries-src/injections.scm index 8e35d32..dad93f6 100644 --- a/queries-src/injections.scm +++ b/queries-src/injections.scm @@ -7,8 +7,6 @@ ((comment) @injection.content (#set! injection.language "comment")) -(comment) @comment - ; Highlight the RHS of `=~` as regex ((regex_literal (_) @injection.content) (#set! injection.language "regex")) @@ -52,7 +50,10 @@ (recipe_body (#set! injection.include-children)) @injection.content) (assignment - (expression (value (external_command (command_body) @injection.content)))) + (expression + (value + (external_command + (command_body) @injection.content)))) ]) (source_file @@ -60,16 +61,46 @@ (#not-match? @injection.language ".*(powershell|pwsh|cmd).*")) [ (recipe - (recipe_body (#set! injection.include-children)) @injection.content) + (recipe_body + (#set! injection.include-children)) @injection.content) (assignment - (expression (value (external_command (command_body) @injection.content)))) + (expression + (value + (external_command + (command_body) @injection.content)))) ]) -; ================ Recipe language specified ================ - -; Set highlighting for recipes that specify a language -(recipe_body - (shebang (language) @injection.language) - (#set! injection.include-children)) @injection.content - +; ================ Recipe language specified ================ ; SKIP-HELIX + ; SKIP-HELIX +; Set highlighting for recipes that specify a language, using the exact name by default ; SKIP-HELIX +(recipe_body ; ; SKIP-HELIX + (shebang ; ; SKIP-HELIX + (language) @injection.language) ; ; SKIP-HELIX + (#not-any-of? @injection.language "python3" "nodejs" "node") ; SKIP-HELIX + (#set! injection.include-children)) @injection.content ; SKIP-HELIX + ; SKIP-HELIX +; Transform some known executables ; SKIP-HELIX + ; SKIP-HELIX +; python3 -> python ; SKIP-HELIX +(recipe_body ; SKIP-HELIX + (shebang ; SKIP-HELIX + (language) @_lang) ; SKIP-HELIX + (#eq? @_lang "python3") ; SKIP-HELIX + (#set! injection.language "python") ; SKIP-HELIX + (#set! injection.include-children)) @injection.content ; SKIP-HELIX + ; SKIP-HELIX +; node/nodejs -> javascript ; SKIP-HELIX +(recipe_body ; SKIP-HELIX + (shebang ; SKIP-HELIX + (language) @_lang) ; SKIP-HELIX + (#any-of? @_lang "node" "nodejs") ; SKIP-HELIX + (#set! injection.language "javascript") ; SKIP-HELIX + (#set! injection.include-children)) @injection.content ; SKIP-HELIX + +; ================ Recipe language specified - Helix only ================ ; SKIP-NVIM SKIP-NVIM-OLD SKIP-LAPCE SKIP-ZED + ; SKIP-NVIM SKIP-NVIM-OLD SKIP-LAPCE SKIP-ZED +; Set highlighting for recipes that specify a language using builtin shebang matching ; SKIP-NVIM SKIP-NVIM-OLD SKIP-LAPCE SKIP-ZED +(recipe_body ; SKIP-NVIM SKIP-NVIM-OLD SKIP-LAPCE SKIP-ZED + (shebang) @injection.shebang ; SKIP-NVIM SKIP-NVIM-OLD SKIP-LAPCE SKIP-ZED + (#set! injection.include-children)) @injection.content ; SKIP-NVIM SKIP-NVIM-OLD SKIP-LAPCE SKIP-ZED diff --git a/queries-src/locals.scm b/queries-src/locals.scm index caf798b..64351f7 100644 --- a/queries-src/locals.scm +++ b/queries-src/locals.scm @@ -7,24 +7,34 @@ ; Definitions -(alias left: (identifier) @local.definition.variable) +(alias + left: (identifier) @local.definition.variable) -(assignment left: (identifier) @local.definition.variable) +(assignment + left: (identifier) @local.definition.variable) -(module name: (identifier) @local.definition.namespace) +(module + name: (identifier) @local.definition.namespace) -(parameter name: (identifier) @local.definition.variable) +(parameter + name: (identifier) @local.definition.variable) -(recipe_header name: (identifier) @local.definition.function) +(recipe_header + name: (identifier) @local.definition.function) ; References -(alias right: (identifier) @local.reference.variable) +(alias + right: (identifier) @local.reference.variable) -(function_call name: (identifier) @local.reference.function) +(function_call + name: (identifier) @local.reference.function) -(dependency name: (identifier) @local.reference.function) +(dependency + name: (identifier) @local.reference.function) -(dependency_expression name: (identifier) @local.reference.function) +(dependency_expression + name: (identifier) @local.reference.function) -(value (identifier) @local.reference.variable) +(value + (identifier) @local.reference.variable) diff --git a/queries-src/textobjects.scm b/queries-src/textobjects.scm index af42014..e90b2a4 100644 --- a/queries-src/textobjects.scm +++ b/queries-src/textobjects.scm @@ -10,6 +10,7 @@ (_) @parameter.inside) @parameter.around (function_call - arguments: (sequence (expression) @parameter.inside) @parameter.around) @function.around + arguments: (sequence + (expression) @parameter.inside) @parameter.around) @function.around (comment) @comment.around diff --git a/queries/just/highlights.scm b/queries/just/highlights.scm index ee78824..4777fa7 100644 --- a/queries/just/highlights.scm +++ b/queries/just/highlights.scm @@ -22,29 +22,38 @@ ; Variables -(value (identifier) @variable) +(value + (identifier) @variable) -(alias left: (identifier) @variable) +(alias + left: (identifier) @variable) -(assignment left: (identifier) @variable) +(assignment + left: (identifier) @variable) ; Functions -(recipe_header name: (identifier) @function) +(recipe_header + name: (identifier) @function) -(dependency name: (identifier) @function.call) +(dependency + name: (identifier) @function.call) -(dependency_expression name: (identifier) @function.call) +(dependency_expression + name: (identifier) @function.call) -(function_call name: (identifier) @function.call) +(function_call + name: (identifier) @function.call) ; Parameters -(parameter name: (identifier) @parameter) +(parameter + name: (identifier) @parameter) ; Namespaces -(module name: (identifier) @namespace) +(module + name: (identifier) @namespace) ; Operators @@ -103,7 +112,7 @@ ; highlight known settings (filtering does not always work) (setting - left: ((identifier) @keyword + left: (identifier) @keyword (#any-of? @keyword "allow-duplicate-recipes" "dotenv-filename" @@ -116,27 +125,25 @@ "shell" "tempdi" "windows-powershell" - "windows-shell" - ))) + "windows-shell")) ; highlight known attributes (filtering does not always work) (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" - ))) + (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 (numeric_error) @error diff --git a/queries/just/indents.scm b/queries/just/indents.scm index ccc68a5..424a02d 100644 --- a/queries/just/indents.scm +++ b/queries/just/indents.scm @@ -1,8 +1,8 @@ ; File autogenerated by build-queries-nvim.py; do not edit -; This query +; This query specifies how to auto-indent logical blocks. ; -; Better documentation is in https://docs.helix-editor.com/guides/indent.html +; Better documentation with diagrams is in https://docs.helix-editor.com/guides/indent.html [ (recipe) diff --git a/queries/just/injections.scm b/queries/just/injections.scm index 218b94b..0bb650f 100644 --- a/queries/just/injections.scm +++ b/queries/just/injections.scm @@ -7,8 +7,6 @@ ((comment) @injection.content (#set! injection.language "comment")) -(comment) @comment - ; Highlight the RHS of `=~` as regex ((regex_literal (_) @injection.content) (#set! injection.language "regex")) @@ -51,7 +49,10 @@ (recipe_body) @injection.content) (assignment - (expression (value (external_command (command_body) @injection.content)))) + (expression + (value + (external_command + (command_body) @injection.content)))) ]) (source_file @@ -62,11 +63,32 @@ (recipe_body) @injection.content) (assignment - (expression (value (external_command (command_body) @injection.content)))) + (expression + (value + (external_command + (command_body) @injection.content)))) ]) -; ================ Recipe language specified ================ - -; Set highlighting for recipes that specify a language -(recipe_body - (shebang (language) @injection.language)) @injection.content +; ================ Recipe language specified ================ + +; Set highlighting for recipes that specify a language, using the exact name by default +(recipe_body ; + (shebang ; + (language) @injection.language) ; + (#not-any-of? @injection.language "python3" "nodejs" "node")) @injection.content + +; Transform some known executables + +; python3 -> python +(recipe_body + (shebang + (language) @_lang) + (#eq? @_lang "python3") + (#set! injection.language "python")) @injection.content + +; node/nodejs -> javascript +(recipe_body + (shebang + (language) @_lang) + (#any-of? @_lang "node" "nodejs") + (#set! injection.language "javascript")) @injection.content diff --git a/queries/just/locals.scm b/queries/just/locals.scm index c917b24..0c25c23 100644 --- a/queries/just/locals.scm +++ b/queries/just/locals.scm @@ -9,24 +9,34 @@ ; Definitions -(alias left: (identifier) @definition.var) +(alias + left: (identifier) @definition.var) -(assignment left: (identifier) @definition.var) +(assignment + left: (identifier) @definition.var) -(module name: (identifier) @definition.namespace) +(module + name: (identifier) @definition.namespace) -(parameter name: (identifier) @definition.var) +(parameter + name: (identifier) @definition.var) -(recipe_header name: (identifier) @definition.function) +(recipe_header + name: (identifier) @definition.function) ; References -(alias right: (identifier) @reference) +(alias + right: (identifier) @reference) -(function_call name: (identifier) @reference) +(function_call + name: (identifier) @reference) -(dependency name: (identifier) @reference) +(dependency + name: (identifier) @reference) -(dependency_expression name: (identifier) @reference) +(dependency_expression + name: (identifier) @reference) -(value (identifier) @reference) +(value + (identifier) @reference) diff --git a/queries/just/textobjects.scm b/queries/just/textobjects.scm index 966d36b..2894a8b 100644 --- a/queries/just/textobjects.scm +++ b/queries/just/textobjects.scm @@ -12,6 +12,7 @@ (_) @parameter.inner) @parameter.outer (function_call - arguments: (sequence (expression) @parameter.inner) @parameter.outer) @function.outer + arguments: (sequence + (expression) @parameter.inner) @parameter.outer) @function.outer (comment) @comment.outer