diff --git a/build-flavored-queries.py b/build-flavored-queries.py index b0da337..a82f874 100755 --- a/build-flavored-queries.py +++ b/build-flavored-queries.py @@ -2,59 +2,574 @@ """Generate NeoVim queries. Everything in `queries/` uses tree-sitter syntax, as defined at -. However, NVim -has a slightly different syntax. +. However, each +editor has a slightly different syntax. This file performs conversions so two sets of files don't need to be maintained. has a bit better -guide for these parameters than tree-sitter does. +guide for the standard parameters than tree-sitter does. """ import re from glob import glob from pathlib import Path -REPLACEMENTS = [ - ("@local.definition", "@definition"), - ("@local.reference", "@reference"), - ("@local.scope", "@scope"), - ("@constants.builtin.boolean", "@boolean"), - ("@keyword.control.conditional", "@conditional"), - ("@variable.parameter", "@parameter"), - ("@comment.line", "@comment"), - ("@constant.character.escape", "@string.escape"), - ("@keyword.module", "@module"), - ("@function.inside", "@function.inner"), - ("@function.around", "@function.outer"), - ("@parameter.around", "@parameter.outer"), - ("@comment.around", "@comment.outer"), + +REPLACEMENTS_HELIX = [] +REPLACEMENTS_ZED = [] +REPLACEMENTS_LAPCE = [] + +ALLOWED_CAPS_ALL = ["@error"] +ALLOWED_PREDICATES_ALL = [ + "#eq?", + "#match?", ] -REPLACEMENTS_RE = [ - (r";\s*NVIM-DISABLE-START.*;\s*NVIM-DISABLE-END", "", re.MULTILINE | re.DOTALL), - ("^.*NVIM-ENABLE(?P.*)$", r"\g", re.MULTILINE), - ("@indent\s+@extend", "@indent.begin", 0), +ALLOWED_CAPS_NVIM_OLD = { + "highlights.scm": [ + "@comment", + "@comment.documentation", + "@error", + "@none", + "@preproc", + "@define", + "@operator", + "@punctuation.delimiter", + "@punctuation.bracket", + "@punctuation.special", + "@string", + "@string.documentation", + "@string.regex", + "@string.escape", + "@string.special", + "@character", + "@character.special", + "@boolean", + "@number", + "@float", + "@function", + "@function.builtin", + "@function.call", + "@function.macro", + "@method", + "@method.call", + "@constructor", + "@parameter", + "@keyword", + "@keyword.coroutine", + "@keyword.function", + "@keyword.operator", + "@keyword.return", + "@conditional", + "@conditional.ternary", + "@repeat", + "@debug", + "@label", + "@include", + "@exception", + "@type", + "@type.builtin", + "@type.definition", + "@type.qualifier", + "@storageclass", + "@attribute", + "@field", + "@property", + "@variable", + "@variable.builtin", + "@constant", + "@constant.builtin", + "@constant.macro", + "@namespace", + "@symbol", + "@text", + "@text.strong", + "@text.emphasis", + "@text.underline", + "@text.strike", + "@text.title", + "@text.quote", + "@text.uri", + "@text.math", + "@text.environment", + "@text.environment.name", + "@text.reference", + "@text.literal", + "@text.literal.block", + "@text.todo", + "@text.note", + "@text.warning", + "@text.danger", + "@text.diff.add", + "@text.diff.delete", + "@tag", + "@tag.attribute", + "@tag.delimiter", + "@conceal", + "@spell", + "@nospell", + ], + "injections.scm": [ + "@injection.language", + "@injection.content", + "@comment", + ], + "locals.scm": [ + "@definition", + "@definition.constant", + "@definition.function", + "@definition.method", + "@definition.var", + "@definition.parameter", + "@definition.macro", + "@definition.type", + "@definition.field", + "@definition.enum", + "@definition.namespace", + "@definition.import", + "@definition.associated", + "@scope", + "@reference", + ], + "folds.scm": [ + "@fold", + ], + "indents.scm": [ + "@indent.begin", + "@indent.end", + "@indent.align", + "@indent.dedent", + "@indent.branch", + "@indent.ignore", + "@indent.auto", + "@indent.zero", + ], + "textobjects.scm": [ + "@attribute.inner", + "@attribute.outer", + "@function.inner", + "@function.outer", + "@class.inner", + "@class.outer", + "@conditional.inner", + "@conditional.outer", + "@loop.inner", + "@loop.outer", + "@call.inner", + "@call.outer", + "@block.inner", + "@block.outer", + "@parameter.inner", + "@parameter.outer", + "@regex.inner", + "@regex.outer", + "@comment.inner", + "@comment.outer", + "@assignment.inner", + "@assignment.outer", + "@return.inner", + "@return.outer", + "@frame.inner", + "@frame.outer", + ], +} + +ALLOWED_SETTINGS_NVIM_OLD = { + "injections.scm": [ + "injection.combined", + "injection.language", + ] +} + +# Old nvim-treesitter before updates +REPLACEMENTS_NVIM_OLD = [ + # Changes to local captures + (r"@local.definition", "@definition"), + (r"@local.reference[\w.]*", "@reference"), + (r"@local.scope", "@scope"), + # Changes to highlight queries + (r"@comment.line", "@comment"), + (r"@comment.around", "@comment.outer"), + (r"@constant.builtin.boolean", "@boolean"), + (r"@constant.character.escape", "@string.escape"), + (r"@keyword.control.conditional", "@conditional"), + (r"@keyword.control.import", "@keyword"), + (r"@keyword.module", "@keyword"), + (r"@variable.parameter", "@parameter"), + # Changes to indent queries + (r"@indent\s+@extend", "@indent.begin"), + # Changes to textobject queries + (r"(@[\w.]+.)inside", r"\1inner"), + (r"(@[\w.]+.)around", r"\1outer"), + # nvim does not have `injection.include-children` + (r"\n?\s*\(\s*#set!\s*injection\.include-children\s*\)", "", re.MULTILINE), + # nvim uses `var` rather than `variable` + (r"(@[\w.]+)\.variable", r"\1.var"), +] + +ALLOWED_CAPS_NVIM = { + "highlights.scm": [ + "@variable", + "@variable.builtin", + "@variable.parameter", + "@variable.parameter.builtin", + "@variable.member", + "@constant", + "@constant.builtin", + "@constant.macro", + "@module", + "@module.builtin", + "@label", + "@string", + "@string.documentation", + "@string.regexp", + "@string.escape", + "@string.special", + "@string.special.symbol", + "@string.special.url", + "@string.special.path", + "@character", + "@character.special", + "@boolean", + "@number", + "@number.float", + "@type", + "@type.builtin", + "@type.definition", + "@type.qualifier", + "@attribute", + "@attribute.builtin", + "@property", + "@function", + "@function.builtin", + "@function.call", + "@function.macro", + "@function.method", + "@function.method.call", + "@constructor", + "@operator", + "@keyword", + "@keyword.coroutine", + "@keyword.function", + "@keyword.operator", + "@keyword.import", + "@keyword.storage", + "@keyword.type", + "@keyword.repeat", + "@keyword.return", + "@keyword.debug", + "@keyword.exception", + "@keyword.conditional", + "@keyword.conditional.ternary", + "@keyword.directive", + "@keyword.directive.define", + "@punctuation.delimiter", + "@punctuation.bracket", + "@punctuation.special", + "@comment", + "@comment.documentation", + "@comment.error", + "@comment.warning", + "@comment.todo", + "@comment.note", + "@none", + "@conceal", + "@spell", + "@nospell", + ], + "injections.scm": [ + "@injection.language", + "@injection.content", + "@comment", + ], + "locals.scm": [ + "@local.definition", + "@local.definition.constant", + "@local.definition.function", + "@local.definition.method", + "@local.definition.var", + "@local.definition.parameter", + "@local.definition.macro", + "@local.definition.type", + "@local.definition.field", + "@local.definition.enum", + "@local.definition.namespace", + "@local.definition.import", + "@local.definition.associated", + "@local.scope", + "@local.reference", + ], + "folds.scm": [ + "@fold", + ], + "indents.scm": [ + "@indent.begin", + "@indent.end", + "@indent.align", + "@indent.dedent", + "@indent.branch", + "@indent.ignore", + "@indent.auto", + "@indent.zero", + ], + "textobjects.scm": ALLOWED_CAPS_NVIM_OLD["textobjects.scm"], +} + +ALLOWED_SETTINGS_NVIM = { + "injections.scm": [ + "injection.combined", + "injection.language", + ] +} + +# Old nvim-treesitter before updates +REPLACEMENTS_NVIM = [ + # Changes to highlight queries + (r"@comment.line", "@comment"), + (r"@constant.builtin.boolean", "@boolean"), + (r"@constant.character.escape", "@string.escape"), + (r"@keyword.module", "@module"), + (r"@keyword.control.", "@keyword."), + (r"@namespace", "@module"), + # Changes to indent queries + (r"@indent\s+@extend", "@indent.begin"), + # Changes to textobject queries + (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), + # nvim uses `var` rather than `variable` + (r"(@[\w.]+)\.variable", r"\1.var"), + # nothing more specific than reference + (r"(@local.reference)[\w.]+", r"\1"), +] + +ALLOWED_CAPS_HELIX = { + "highlights.scm": [ + "@attribute", + "@type.builtin", + "@type.parameter", + "@type.enum.variant", + "@constructor", + "@constant.builtin", + "@constant.builtin.boolean", + "@constant.character", + "@constant.character.escape", + "@constant.numeric", + "@constant.numeric.integer", + "@constant.numeric.float", + "@string", + "@string.regexp", + "@string.special.path", + "@string.special.url", + "@string.special.symbol", + "@comment", + "@comment.line", + "@comment.block", + "@comment.block.documentation", + "@variable", + "@variable.builtin", + "@variable.parameter", + "@variable.other", + "@variable.other.member", + "@label", + "@punctuation", + "@punctuation.delimiter", + "@punctuation.bracket", + "@punctuation.special", + "@keyword", + "@keyword.control", + "@keyword.control.conditional", + "@keyword.control.repeat", + "@keyword.control.import", + "@keyword.control.return", + "@keyword.control.exception", + "@keyword.operator", + "@keyword.directive", + "@keyword.function", + "@keyword.storage", + "@keyword.storage.type", + "@keyword.storage.modifier", + "@operator", + "@function", + "@function.builtin", + "@function.method", + "@function.macro", + "@function.special", + "@namespace", + "@special", + ], + "injections.scm": [ + "@injection.language", + "@injection.content", + "@injection.filename", + "@injection.shebang", + "@comment", + ], + # unspecified in helix + "locals.scm": [ + c.replace("var", "variable") for c in ALLOWED_CAPS_NVIM["locals.scm"] + ], + "folds.scm": ALLOWED_CAPS_NVIM["folds.scm"], + "indents.scm": [ + "@indent", + "@outdent", + "@indent.always", + "@outdent.always", + "@align", + "@extend", + "@extend.prevent-once", + ], + "textobjects.scm": [ + "@function.inside", + "@function.around", + "@class.inside", + "@class.around", + "@test.inside", + "@test.around", + "@parameter.inside", + "@parameter.around", + "@comment.inside", + "@comment.around", + ], +} + +ALLOWED_SETTINGS_HELIX = { + "injections.scm": [ + "injection.combined", + "injection.language", + "injection.include-children", + "injection.include-unnamed-children", + ] +} + +REPLACEMENTS_HELIX = [ + (r"@keyword.module", "@keyword.directive"), + (r"@function.call", "@function"), + (r"@spell", ""), + # nothing more specific than reference + (r"(@local.reference)[\w.]+", r"\1"), +] + +# Documentation not yet complete +ALLOWED_CAPS_ZED = ALLOWED_CAPS_HELIX +ALLOWED_SETTINGS_ZED = ALLOWED_SETTINGS_HELIX +REPLACEMENTS_ZED = REPLACEMENTS_HELIX +ALLOWED_CAPS_LAPCE = ALLOWED_CAPS_HELIX +ALLOWED_SETTINGS_LAPCE = ALLOWED_SETTINGS_HELIX +REPLACEMENTS_LAPCE = REPLACEMENTS_HELIX + +# (rname, eplacements, allowed caps, base path) mappings to create a flavor +FLAVOR_MAPPINGS = [ + ( + "old NeoVim", + "NVIM-OLD", + REPLACEMENTS_NVIM_OLD, + ALLOWED_CAPS_NVIM_OLD, + ALLOWED_SETTINGS_NVIM_OLD, + Path("queries") / "just", + ), + ( + "new NeoVim", + "NVIM", + REPLACEMENTS_NVIM, + ALLOWED_CAPS_NVIM, + ALLOWED_SETTINGS_NVIM, + Path("queries-flavored") / "nvim-next", + ), + ( + "Helix", + "HELIX", + REPLACEMENTS_HELIX, + ALLOWED_CAPS_HELIX, + ALLOWED_SETTINGS_HELIX, + Path("queries-flavored") / "helix", + ), + ( + "Zed", + "ZED", + REPLACEMENTS_ZED, + ALLOWED_CAPS_ZED, + ALLOWED_SETTINGS_ZED, + Path("queries-flavored") / "zed", + ), + ( + "Lapce", + "LAPCE", + REPLACEMENTS_LAPCE, + ALLOWED_CAPS_LAPCE, + ALLOWED_SETTINGS_LAPCE, + Path("queries-flavored") / "lapce", + ), ] def main(): sources = glob("queries-src/*.scm") for fname in sources: - contents = "; File autogenerated by build-queries-nvim.py; do not edit\n\n" + qname = Path(fname).name + print(f"Generating flavored queries from {fname}") + base_contents = "; File autogenerated by build-queries-nvim.py; do not edit\n\n" with open(fname) as f: - contents += f.read() + base_contents += f.read() + + for ( + name, + tag, + replacements, + allowed_caps, + allowed_settings, + basepath, + ) in FLAVOR_MAPPINGS: + contents = base_contents + for rep in replacements: + pat = rep[0] + sub = rep[1] + flags = 0 + if len(rep) > 2: + 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) + ) + if not contents.endswith("\n"): + contents += "\n" + + # 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"((?:\r?\n){2,})(?:\r?\n)+", "\1", contents) + + basepath.mkdir(parents=True, exist_ok=True) + dest = basepath / Path(fname).name + + with open(dest, "w") as f: + f.write(contents) + + # Validate all captures are valid + for qcap in re.finditer(r"@[\w.]+", contents): + matched = qcap[0] - for query, sub in REPLACEMENTS: - contents = contents.replace(query, sub) + # Internal captures + if matched.startswith("@_"): + continue - for query, sub, flags in REPLACEMENTS_RE: - contents = re.sub(query, sub, contents, flags=flags) + allowed = allowed_caps[qname] + assert ( + matched in allowed or matched in ALLOWED_CAPS_ALL + ), f"found disallowed query '{matched}' in '{dest}' ({name}). Allowed: {allowed}" - dest = Path("queries") / "just" / Path(fname).name - with open(dest, "w") as f: - f.write(contents) + # Validate all settings are valid + for qsetting in re.finditer(r"#set!\s+([\w.-]+)", contents): + matched = qsetting[1] + allowed = allowed_settings[qname] + assert ( + matched in allowed + ), f"found disallowed setting '{qsetting[0]}' in '{dest}' ({name}). Allowed: {allowed}" if __name__ == "__main__": diff --git a/queries-flavored/helix/folds.scm b/queries-flavored/helix/folds.scm new file mode 100644 index 0000000..fa2a030 --- /dev/null +++ b/queries-flavored/helix/folds.scm @@ -0,0 +1,10 @@ +; File autogenerated by build-queries-nvim.py; do not edit + +; Define collapse points + +[ + (recipe) + (string) + (external_command) +] @fold +(#trim! @fold) \ No newline at end of file diff --git a/queries-flavored/helix/highlights.scm b/queries-flavored/helix/highlights.scm new file mode 100644 index 0000000..8e8fc51 --- /dev/null +++ b/queries-flavored/helix/highlights.scm @@ -0,0 +1,143 @@ +; File autogenerated by build-queries-nvim.py; do not edit + +; This file specifies how matched syntax patterns should be highlighted + +[ + "export" + "import" +] @keyword.control.import + +"mod" @keyword.directive + +[ + "alias" + "set" + "shell" +] @keyword + +[ + "if" + "else" +] @keyword.control.conditional + +; Variables + +(value (identifier) @variable) + +(alias left: (identifier) @variable) + +(assignment left: (identifier) @variable) + +; Functions + +(recipe_header name: (identifier) @function) + +(dependency name: (identifier) @function) + +(dependency_expression name: (identifier) @function) + +(function_call name: (identifier) @function) + +; Parameters + +(parameter name: (identifier) @variable.parameter) + +; Namespaces + +(module name: (identifier) @namespace) + +; Operators + +[ + ":=" + "?" + "==" + "!=" + "=~" + "@" + "=" + "$" + "*" + "+" + "&&" + "@-" + "-@" + "-" + "/" + ":" +] @operator + +; Punctuation + +[ "," ] @punctuation.delimiter + +[ + "{" + "}" + "[" + "]" + "(" + ")" + "{{" + "}}" +] @punctuation.bracket + +[ "`" "```" ] @punctuation.special + +; Literals + +(boolean) @constant.builtin.boolean + +[ + (string) + (external_command) +] @string + +(escape_sequence) @constant.character.escape + +; Comments + +; FIXME: add once all editors support it +(comment) @comment.line + +(shebang) @comment + +; highlight known settings (filtering does not always work) +(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) +(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" + ))) + +; Numbers are part of the syntax tree, even if disallowed +(numeric_error) @error \ No newline at end of file diff --git a/queries-flavored/helix/indents.scm b/queries-flavored/helix/indents.scm new file mode 100644 index 0000000..f91b794 --- /dev/null +++ b/queries-flavored/helix/indents.scm @@ -0,0 +1,11 @@ +; File autogenerated by build-queries-nvim.py; do not edit + +; This query +; +; Better documentation is in https://docs.helix-editor.com/guides/indent.html + +[ + (recipe) + (string) + (external_command) +] @indent @extend \ No newline at end of file diff --git a/queries-flavored/helix/injections.scm b/queries-flavored/helix/injections.scm new file mode 100644 index 0000000..2f8cec0 --- /dev/null +++ b/queries-flavored/helix/injections.scm @@ -0,0 +1,74 @@ +; File autogenerated by build-queries-nvim.py; do not edit + +; 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")) + +; ================ Global defaults ================ + +; Default everything to be bash +(recipe_body + (#set! injection.language "bash") + (#set! injection.include-children)) @injection.content + +(external_command + (command_body) @injection.content + (#set! injection.language "bash")) + +; ================ Global language specified ================ +; Global language is set with something like one of the following: +; +; set shell := ["bash", "-c", ...] +; set shell := ["pwsh.exe"] +; +; We can extract the first item of the array, but we can't extract the language +; name from the string with something like regex. So instead we special case +; two things: powershell, which is likely to come with a `.exe` attachment that +; we need to strip, and everything else which hopefully has no extension. We +; separate this with a `#match?`. +; +; Unfortunately, there also isn't a way to allow arbitrary nesting or +; alternatively set "global" capture variables. So we can set this for item- +; level external commands, but not for e.g. external commands within an +; expression without getting _really_ annoying. Should at least look fine since +; they default to bash. Limitations... +; See https://github.com/tree-sitter/tree-sitter/issues/880 for more on that. + +(source_file + (setting "shell" ":=" "[" (string) @_langstr + (#match? @_langstr ".*(powershell|pwsh|cmd).*") + (#set! injection.language "powershell")) + [ + (recipe + (recipe_body (#set! injection.include-children)) @injection.content) + + (assignment + (expression (value (external_command (command_body) @injection.content)))) + ]) + +(source_file + (setting "shell" ":=" "[" (string) @injection.language + (#not-match? @injection.language ".*(powershell|pwsh|cmd).*")) + [ + (recipe + (recipe_body (#set! injection.include-children)) @injection.content) + + (assignment + (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 \ No newline at end of file diff --git a/queries-flavored/helix/locals.scm b/queries-flavored/helix/locals.scm new file mode 100644 index 0000000..6c41b3e --- /dev/null +++ b/queries-flavored/helix/locals.scm @@ -0,0 +1,32 @@ +; File autogenerated by build-queries-nvim.py; do not edit + +; This file tells us about the scope of variables so e.g. local +; variables override global functions with the same name + +; Scope + +(recipe) @local.scope + +; Definitions + +(alias left: (identifier) @local.definition.variable) + +(assignment left: (identifier) @local.definition.variable) + +(module name: (identifier) @local.definition.namespace) + +(parameter name: (identifier) @local.definition.variable) + +(recipe_header name: (identifier) @local.definition.function) + +; References + +(alias right: (identifier) @local.reference) + +(function_call name: (identifier) @local.reference) + +(dependency name: (identifier) @local.reference) + +(dependency_expression name: (identifier) @local.reference) + +(value (identifier) @local.reference) \ No newline at end of file diff --git a/queries-flavored/helix/textobjects.scm b/queries-flavored/helix/textobjects.scm new file mode 100644 index 0000000..147aacb --- /dev/null +++ b/queries-flavored/helix/textobjects.scm @@ -0,0 +1,15 @@ +; File autogenerated by build-queries-nvim.py; do not edit + +(recipe + (recipe_body) @function.inside) @function.around + +(parameters + ((_) @parameter.inside . ","? @parameter.around)) @parameter.around + +(dependency_expression + (_) @parameter.inside) @parameter.around + +(function_call + arguments: (sequence (expression) @parameter.inside) @parameter.around) @function.around + +(comment) @comment.around \ No newline at end of file diff --git a/queries-flavored/lapce/folds.scm b/queries-flavored/lapce/folds.scm new file mode 100644 index 0000000..fa2a030 --- /dev/null +++ b/queries-flavored/lapce/folds.scm @@ -0,0 +1,10 @@ +; File autogenerated by build-queries-nvim.py; do not edit + +; Define collapse points + +[ + (recipe) + (string) + (external_command) +] @fold +(#trim! @fold) \ No newline at end of file diff --git a/queries-flavored/lapce/highlights.scm b/queries-flavored/lapce/highlights.scm new file mode 100644 index 0000000..8e8fc51 --- /dev/null +++ b/queries-flavored/lapce/highlights.scm @@ -0,0 +1,143 @@ +; File autogenerated by build-queries-nvim.py; do not edit + +; This file specifies how matched syntax patterns should be highlighted + +[ + "export" + "import" +] @keyword.control.import + +"mod" @keyword.directive + +[ + "alias" + "set" + "shell" +] @keyword + +[ + "if" + "else" +] @keyword.control.conditional + +; Variables + +(value (identifier) @variable) + +(alias left: (identifier) @variable) + +(assignment left: (identifier) @variable) + +; Functions + +(recipe_header name: (identifier) @function) + +(dependency name: (identifier) @function) + +(dependency_expression name: (identifier) @function) + +(function_call name: (identifier) @function) + +; Parameters + +(parameter name: (identifier) @variable.parameter) + +; Namespaces + +(module name: (identifier) @namespace) + +; Operators + +[ + ":=" + "?" + "==" + "!=" + "=~" + "@" + "=" + "$" + "*" + "+" + "&&" + "@-" + "-@" + "-" + "/" + ":" +] @operator + +; Punctuation + +[ "," ] @punctuation.delimiter + +[ + "{" + "}" + "[" + "]" + "(" + ")" + "{{" + "}}" +] @punctuation.bracket + +[ "`" "```" ] @punctuation.special + +; Literals + +(boolean) @constant.builtin.boolean + +[ + (string) + (external_command) +] @string + +(escape_sequence) @constant.character.escape + +; Comments + +; FIXME: add once all editors support it +(comment) @comment.line + +(shebang) @comment + +; highlight known settings (filtering does not always work) +(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) +(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" + ))) + +; Numbers are part of the syntax tree, even if disallowed +(numeric_error) @error \ No newline at end of file diff --git a/queries-flavored/lapce/indents.scm b/queries-flavored/lapce/indents.scm new file mode 100644 index 0000000..f91b794 --- /dev/null +++ b/queries-flavored/lapce/indents.scm @@ -0,0 +1,11 @@ +; File autogenerated by build-queries-nvim.py; do not edit + +; This query +; +; Better documentation is in https://docs.helix-editor.com/guides/indent.html + +[ + (recipe) + (string) + (external_command) +] @indent @extend \ No newline at end of file diff --git a/queries-flavored/lapce/injections.scm b/queries-flavored/lapce/injections.scm new file mode 100644 index 0000000..2f8cec0 --- /dev/null +++ b/queries-flavored/lapce/injections.scm @@ -0,0 +1,74 @@ +; File autogenerated by build-queries-nvim.py; do not edit + +; 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")) + +; ================ Global defaults ================ + +; Default everything to be bash +(recipe_body + (#set! injection.language "bash") + (#set! injection.include-children)) @injection.content + +(external_command + (command_body) @injection.content + (#set! injection.language "bash")) + +; ================ Global language specified ================ +; Global language is set with something like one of the following: +; +; set shell := ["bash", "-c", ...] +; set shell := ["pwsh.exe"] +; +; We can extract the first item of the array, but we can't extract the language +; name from the string with something like regex. So instead we special case +; two things: powershell, which is likely to come with a `.exe` attachment that +; we need to strip, and everything else which hopefully has no extension. We +; separate this with a `#match?`. +; +; Unfortunately, there also isn't a way to allow arbitrary nesting or +; alternatively set "global" capture variables. So we can set this for item- +; level external commands, but not for e.g. external commands within an +; expression without getting _really_ annoying. Should at least look fine since +; they default to bash. Limitations... +; See https://github.com/tree-sitter/tree-sitter/issues/880 for more on that. + +(source_file + (setting "shell" ":=" "[" (string) @_langstr + (#match? @_langstr ".*(powershell|pwsh|cmd).*") + (#set! injection.language "powershell")) + [ + (recipe + (recipe_body (#set! injection.include-children)) @injection.content) + + (assignment + (expression (value (external_command (command_body) @injection.content)))) + ]) + +(source_file + (setting "shell" ":=" "[" (string) @injection.language + (#not-match? @injection.language ".*(powershell|pwsh|cmd).*")) + [ + (recipe + (recipe_body (#set! injection.include-children)) @injection.content) + + (assignment + (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 \ No newline at end of file diff --git a/queries-flavored/lapce/locals.scm b/queries-flavored/lapce/locals.scm new file mode 100644 index 0000000..6c41b3e --- /dev/null +++ b/queries-flavored/lapce/locals.scm @@ -0,0 +1,32 @@ +; File autogenerated by build-queries-nvim.py; do not edit + +; This file tells us about the scope of variables so e.g. local +; variables override global functions with the same name + +; Scope + +(recipe) @local.scope + +; Definitions + +(alias left: (identifier) @local.definition.variable) + +(assignment left: (identifier) @local.definition.variable) + +(module name: (identifier) @local.definition.namespace) + +(parameter name: (identifier) @local.definition.variable) + +(recipe_header name: (identifier) @local.definition.function) + +; References + +(alias right: (identifier) @local.reference) + +(function_call name: (identifier) @local.reference) + +(dependency name: (identifier) @local.reference) + +(dependency_expression name: (identifier) @local.reference) + +(value (identifier) @local.reference) \ No newline at end of file diff --git a/queries-flavored/lapce/textobjects.scm b/queries-flavored/lapce/textobjects.scm new file mode 100644 index 0000000..147aacb --- /dev/null +++ b/queries-flavored/lapce/textobjects.scm @@ -0,0 +1,15 @@ +; File autogenerated by build-queries-nvim.py; do not edit + +(recipe + (recipe_body) @function.inside) @function.around + +(parameters + ((_) @parameter.inside . ","? @parameter.around)) @parameter.around + +(dependency_expression + (_) @parameter.inside) @parameter.around + +(function_call + arguments: (sequence (expression) @parameter.inside) @parameter.around) @function.around + +(comment) @comment.around \ No newline at end of file diff --git a/queries-flavored/nvim-next/folds.scm b/queries-flavored/nvim-next/folds.scm new file mode 100644 index 0000000..fa2a030 --- /dev/null +++ b/queries-flavored/nvim-next/folds.scm @@ -0,0 +1,10 @@ +; File autogenerated by build-queries-nvim.py; do not edit + +; Define collapse points + +[ + (recipe) + (string) + (external_command) +] @fold +(#trim! @fold) \ No newline at end of file diff --git a/queries-flavored/nvim-next/highlights.scm b/queries-flavored/nvim-next/highlights.scm new file mode 100644 index 0000000..25bc0b7 --- /dev/null +++ b/queries-flavored/nvim-next/highlights.scm @@ -0,0 +1,143 @@ +; File autogenerated by build-queries-nvim.py; do not edit + +; This file specifies how matched syntax patterns should be highlighted + +[ + "export" + "import" +] @keyword.import + +"mod" @module + +[ + "alias" + "set" + "shell" +] @keyword + +[ + "if" + "else" +] @keyword.conditional + +; Variables + +(value (identifier) @variable) + +(alias left: (identifier) @variable) + +(assignment left: (identifier) @variable) + +; Functions + +(recipe_header name: (identifier) @function) + +(dependency name: (identifier) @function.call) + +(dependency_expression name: (identifier) @function.call) + +(function_call name: (identifier) @function.call) + +; Parameters + +(parameter name: (identifier) @variable.parameter) + +; Namespaces + +(module name: (identifier) @module) + +; Operators + +[ + ":=" + "?" + "==" + "!=" + "=~" + "@" + "=" + "$" + "*" + "+" + "&&" + "@-" + "-@" + "-" + "/" + ":" +] @operator + +; Punctuation + +[ "," ] @punctuation.delimiter + +[ + "{" + "}" + "[" + "]" + "(" + ")" + "{{" + "}}" +] @punctuation.bracket + +[ "`" "```" ] @punctuation.special + +; Literals + +(boolean) @boolean + +[ + (string) + (external_command) +] @string + +(escape_sequence) @string.escape + +; Comments + +; FIXME: add @spell once all editors support it +(comment) @comment + +(shebang) @comment + +; highlight known settings (filtering does not always work) +(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) +(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" + ))) + +; Numbers are part of the syntax tree, even if disallowed +(numeric_error) @error \ No newline at end of file diff --git a/queries-flavored/nvim-next/indents.scm b/queries-flavored/nvim-next/indents.scm new file mode 100644 index 0000000..505efe0 --- /dev/null +++ b/queries-flavored/nvim-next/indents.scm @@ -0,0 +1,13 @@ +; File autogenerated by build-queries-nvim.py; do not edit + +; This query +; +; Better documentation is in https://docs.helix-editor.com/guides/indent.html + +[ + (recipe) + (string) + (external_command) +] @indent.begin + +(comment) @indent.auto \ No newline at end of file diff --git a/queries-flavored/nvim-next/injections.scm b/queries-flavored/nvim-next/injections.scm new file mode 100644 index 0000000..3942ea7 --- /dev/null +++ b/queries-flavored/nvim-next/injections.scm @@ -0,0 +1,72 @@ +; File autogenerated by build-queries-nvim.py; do not edit + +; 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")) + +; ================ Global defaults ================ + +; Default everything to be bash +(recipe_body + (#set! injection.language "bash")) @injection.content + +(external_command + (command_body) @injection.content + (#set! injection.language "bash")) + +; ================ Global language specified ================ +; Global language is set with something like one of the following: +; +; set shell := ["bash", "-c", ...] +; set shell := ["pwsh.exe"] +; +; We can extract the first item of the array, but we can't extract the language +; name from the string with something like regex. So instead we special case +; two things: powershell, which is likely to come with a `.exe` attachment that +; we need to strip, and everything else which hopefully has no extension. We +; separate this with a `#match?`. +; +; Unfortunately, there also isn't a way to allow arbitrary nesting or +; alternatively set "global" capture variables. So we can set this for item- +; level external commands, but not for e.g. external commands within an +; expression without getting _really_ annoying. Should at least look fine since +; they default to bash. Limitations... +; See https://github.com/tree-sitter/tree-sitter/issues/880 for more on that. + +(source_file + (setting "shell" ":=" "[" (string) @_langstr + (#match? @_langstr ".*(powershell|pwsh|cmd).*") + (#set! injection.language "powershell")) + [ + (recipe + (recipe_body) @injection.content) + + (assignment + (expression (value (external_command (command_body) @injection.content)))) + ]) + +(source_file + (setting "shell" ":=" "[" (string) @injection.language + (#not-match? @injection.language ".*(powershell|pwsh|cmd).*")) + [ + (recipe + (recipe_body) @injection.content) + + (assignment + (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 \ No newline at end of file diff --git a/queries-flavored/nvim-next/locals.scm b/queries-flavored/nvim-next/locals.scm new file mode 100644 index 0000000..833b231 --- /dev/null +++ b/queries-flavored/nvim-next/locals.scm @@ -0,0 +1,32 @@ +; File autogenerated by build-queries-nvim.py; do not edit + +; This file tells us about the scope of variables so e.g. local +; variables override global functions with the same name + +; Scope + +(recipe) @local.scope + +; Definitions + +(alias left: (identifier) @local.definition.var) + +(assignment left: (identifier) @local.definition.var) + +(module name: (identifier) @local.definition.namespace) + +(parameter name: (identifier) @local.definition.var) + +(recipe_header name: (identifier) @local.definition.function) + +; References + +(alias right: (identifier) @local.reference) + +(function_call name: (identifier) @local.reference) + +(dependency name: (identifier) @local.reference) + +(dependency_expression name: (identifier) @local.reference) + +(value (identifier) @local.reference) \ No newline at end of file diff --git a/queries-flavored/nvim-next/textobjects.scm b/queries-flavored/nvim-next/textobjects.scm new file mode 100644 index 0000000..981b93e --- /dev/null +++ b/queries-flavored/nvim-next/textobjects.scm @@ -0,0 +1,15 @@ +; File autogenerated by build-queries-nvim.py; do not edit + +(recipe + (recipe_body) .inner) .outer + +(parameters + ((_) .inner . ","? .outer)) .outer + +(dependency_expression + (_) .inner) .outer + +(function_call + arguments: (sequence (expression) .inner) .outer) .outer + +(comment) .outer \ No newline at end of file diff --git a/queries-flavored/zed/folds.scm b/queries-flavored/zed/folds.scm new file mode 100644 index 0000000..fa2a030 --- /dev/null +++ b/queries-flavored/zed/folds.scm @@ -0,0 +1,10 @@ +; File autogenerated by build-queries-nvim.py; do not edit + +; Define collapse points + +[ + (recipe) + (string) + (external_command) +] @fold +(#trim! @fold) \ No newline at end of file diff --git a/queries-flavored/zed/highlights.scm b/queries-flavored/zed/highlights.scm new file mode 100644 index 0000000..8e8fc51 --- /dev/null +++ b/queries-flavored/zed/highlights.scm @@ -0,0 +1,143 @@ +; File autogenerated by build-queries-nvim.py; do not edit + +; This file specifies how matched syntax patterns should be highlighted + +[ + "export" + "import" +] @keyword.control.import + +"mod" @keyword.directive + +[ + "alias" + "set" + "shell" +] @keyword + +[ + "if" + "else" +] @keyword.control.conditional + +; Variables + +(value (identifier) @variable) + +(alias left: (identifier) @variable) + +(assignment left: (identifier) @variable) + +; Functions + +(recipe_header name: (identifier) @function) + +(dependency name: (identifier) @function) + +(dependency_expression name: (identifier) @function) + +(function_call name: (identifier) @function) + +; Parameters + +(parameter name: (identifier) @variable.parameter) + +; Namespaces + +(module name: (identifier) @namespace) + +; Operators + +[ + ":=" + "?" + "==" + "!=" + "=~" + "@" + "=" + "$" + "*" + "+" + "&&" + "@-" + "-@" + "-" + "/" + ":" +] @operator + +; Punctuation + +[ "," ] @punctuation.delimiter + +[ + "{" + "}" + "[" + "]" + "(" + ")" + "{{" + "}}" +] @punctuation.bracket + +[ "`" "```" ] @punctuation.special + +; Literals + +(boolean) @constant.builtin.boolean + +[ + (string) + (external_command) +] @string + +(escape_sequence) @constant.character.escape + +; Comments + +; FIXME: add once all editors support it +(comment) @comment.line + +(shebang) @comment + +; highlight known settings (filtering does not always work) +(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) +(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" + ))) + +; Numbers are part of the syntax tree, even if disallowed +(numeric_error) @error \ No newline at end of file diff --git a/queries-flavored/zed/indents.scm b/queries-flavored/zed/indents.scm new file mode 100644 index 0000000..f91b794 --- /dev/null +++ b/queries-flavored/zed/indents.scm @@ -0,0 +1,11 @@ +; File autogenerated by build-queries-nvim.py; do not edit + +; This query +; +; Better documentation is in https://docs.helix-editor.com/guides/indent.html + +[ + (recipe) + (string) + (external_command) +] @indent @extend \ No newline at end of file diff --git a/queries-flavored/zed/injections.scm b/queries-flavored/zed/injections.scm new file mode 100644 index 0000000..2f8cec0 --- /dev/null +++ b/queries-flavored/zed/injections.scm @@ -0,0 +1,74 @@ +; File autogenerated by build-queries-nvim.py; do not edit + +; 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")) + +; ================ Global defaults ================ + +; Default everything to be bash +(recipe_body + (#set! injection.language "bash") + (#set! injection.include-children)) @injection.content + +(external_command + (command_body) @injection.content + (#set! injection.language "bash")) + +; ================ Global language specified ================ +; Global language is set with something like one of the following: +; +; set shell := ["bash", "-c", ...] +; set shell := ["pwsh.exe"] +; +; We can extract the first item of the array, but we can't extract the language +; name from the string with something like regex. So instead we special case +; two things: powershell, which is likely to come with a `.exe` attachment that +; we need to strip, and everything else which hopefully has no extension. We +; separate this with a `#match?`. +; +; Unfortunately, there also isn't a way to allow arbitrary nesting or +; alternatively set "global" capture variables. So we can set this for item- +; level external commands, but not for e.g. external commands within an +; expression without getting _really_ annoying. Should at least look fine since +; they default to bash. Limitations... +; See https://github.com/tree-sitter/tree-sitter/issues/880 for more on that. + +(source_file + (setting "shell" ":=" "[" (string) @_langstr + (#match? @_langstr ".*(powershell|pwsh|cmd).*") + (#set! injection.language "powershell")) + [ + (recipe + (recipe_body (#set! injection.include-children)) @injection.content) + + (assignment + (expression (value (external_command (command_body) @injection.content)))) + ]) + +(source_file + (setting "shell" ":=" "[" (string) @injection.language + (#not-match? @injection.language ".*(powershell|pwsh|cmd).*")) + [ + (recipe + (recipe_body (#set! injection.include-children)) @injection.content) + + (assignment + (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 \ No newline at end of file diff --git a/queries-flavored/zed/locals.scm b/queries-flavored/zed/locals.scm new file mode 100644 index 0000000..6c41b3e --- /dev/null +++ b/queries-flavored/zed/locals.scm @@ -0,0 +1,32 @@ +; File autogenerated by build-queries-nvim.py; do not edit + +; This file tells us about the scope of variables so e.g. local +; variables override global functions with the same name + +; Scope + +(recipe) @local.scope + +; Definitions + +(alias left: (identifier) @local.definition.variable) + +(assignment left: (identifier) @local.definition.variable) + +(module name: (identifier) @local.definition.namespace) + +(parameter name: (identifier) @local.definition.variable) + +(recipe_header name: (identifier) @local.definition.function) + +; References + +(alias right: (identifier) @local.reference) + +(function_call name: (identifier) @local.reference) + +(dependency name: (identifier) @local.reference) + +(dependency_expression name: (identifier) @local.reference) + +(value (identifier) @local.reference) \ No newline at end of file diff --git a/queries-flavored/zed/textobjects.scm b/queries-flavored/zed/textobjects.scm new file mode 100644 index 0000000..147aacb --- /dev/null +++ b/queries-flavored/zed/textobjects.scm @@ -0,0 +1,15 @@ +; File autogenerated by build-queries-nvim.py; do not edit + +(recipe + (recipe_body) @function.inside) @function.around + +(parameters + ((_) @parameter.inside . ","? @parameter.around)) @parameter.around + +(dependency_expression + (_) @parameter.inside) @parameter.around + +(function_call + arguments: (sequence (expression) @parameter.inside) @parameter.around) @function.around + +(comment) @comment.around \ No newline at end of file diff --git a/queries-src/highlights.scm b/queries-src/highlights.scm index 60db8b6..1a5b81d 100644 --- a/queries-src/highlights.scm +++ b/queries-src/highlights.scm @@ -3,7 +3,7 @@ [ "export" "import" -] @keyword.import +] @keyword.control.import "mod" @keyword.module @@ -18,8 +18,6 @@ "else" ] @keyword.control.conditional -(boolean [ "true" "false" ]) @constant.builtin.boolean - ; Variables (value (identifier) @variable) @@ -86,7 +84,7 @@ ; Literals -(boolean) @boolean +(boolean) @constant.builtin.boolean [ (string) diff --git a/queries-src/indents.scm b/queries-src/indents.scm index 151ea46..c61474d 100644 --- a/queries-src/indents.scm +++ b/queries-src/indents.scm @@ -8,4 +8,4 @@ (external_command) ] @indent @extend -(comment) @indent.auto +(comment) @indent.auto ; SKIP-HELIX SKIP-ZED SKIP-LAPCE diff --git a/queries-src/injections.scm b/queries-src/injections.scm index 75660fd..83bf1b4 100644 --- a/queries-src/injections.scm +++ b/queries-src/injections.scm @@ -42,8 +42,8 @@ ; See https://github.com/tree-sitter/tree-sitter/issues/880 for more on that. (source_file - (setting "shell" ":=" "[" (string) @langstr - (#match? @langstr ".*(powershell|pwsh|cmd).*") + (setting "shell" ":=" "[" (string) @_langstr + (#match? @_langstr ".*(powershell|pwsh|cmd).*") (#set! injection.language "powershell")) [ (recipe @@ -55,7 +55,7 @@ (source_file (setting "shell" ":=" "[" (string) @injection.language - (#not-match? @langstr ".*(powershell|pwsh|cmd).*")) + (#not-match? @injection.language ".*(powershell|pwsh|cmd).*")) [ (recipe (recipe_body (#set! injection.include-children)) @injection.content) diff --git a/queries-src/textobjects.scm b/queries-src/textobjects.scm index 366bea8..af0aad1 100644 --- a/queries-src/textobjects.scm +++ b/queries-src/textobjects.scm @@ -11,31 +11,3 @@ arguments: (sequence (expression) @parameter.inside) @parameter.around) @function.around (comment) @comment.around - -; (expression -; if:(expression) @block.inner -; ) -; (expression -; else:(expression) @block.inner -; ) -; (interpolation (expression) @block.inner) @block.outer -; ; (string_array (stringlist) @block.inner) @block.outer - -; ; (stringlist -; ; (string) @parameter.inner -; ; . ","? @_end -; ; (#make-range! "parameter.outer" @parameter.inner @_end) -; ; ) -; (parameters -; [ -; (parameter) -; (variadic_parameter) -; ] @parameter.inner -; . " "? @_end -; (#make-range! "parameter.outer" @parameter.inner @_end) -; ) - -; (item [(alias) (assignment) (export) (setting)]) @statement.outer -; (recipe_header) @statement.outer -; (line) @statement.outer - diff --git a/queries/just/folds.scm b/queries/just/folds.scm index 62dc1a4..fa2a030 100644 --- a/queries/just/folds.scm +++ b/queries/just/folds.scm @@ -7,4 +7,4 @@ (string) (external_command) ] @fold -(#trim! @fold) +(#trim! @fold) \ No newline at end of file diff --git a/queries/just/highlights.scm b/queries/just/highlights.scm index 23aa6e4..52dfb79 100644 --- a/queries/just/highlights.scm +++ b/queries/just/highlights.scm @@ -5,9 +5,9 @@ [ "export" "import" -] @keyword.import +] @keyword -"mod" @module +"mod" @keyword [ "alias" @@ -20,8 +20,6 @@ "else" ] @conditional -(boolean [ "true" "false" ]) @constant.builtin.boolean - ; Variables (value (identifier) @variable) @@ -142,4 +140,4 @@ ))) ; Numbers are part of the syntax tree, even if disallowed -(numeric_error) @error +(numeric_error) @error \ No newline at end of file diff --git a/queries/just/indents.scm b/queries/just/indents.scm index ccc68a5..505efe0 100644 --- a/queries/just/indents.scm +++ b/queries/just/indents.scm @@ -10,4 +10,4 @@ (external_command) ] @indent.begin -(comment) @indent.auto +(comment) @indent.auto \ No newline at end of file diff --git a/queries/just/injections.scm b/queries/just/injections.scm index b517662..3942ea7 100644 --- a/queries/just/injections.scm +++ b/queries/just/injections.scm @@ -17,8 +17,7 @@ ; Default everything to be bash (recipe_body - (#set! injection.language "bash") - (#set! injection.include-children)) @injection.content + (#set! injection.language "bash")) @injection.content (external_command (command_body) @injection.content @@ -44,12 +43,12 @@ ; See https://github.com/tree-sitter/tree-sitter/issues/880 for more on that. (source_file - (setting "shell" ":=" "[" (string) @langstr - (#match? @langstr ".*(powershell|pwsh|cmd).*") + (setting "shell" ":=" "[" (string) @_langstr + (#match? @_langstr ".*(powershell|pwsh|cmd).*") (#set! injection.language "powershell")) [ (recipe - (recipe_body (#set! injection.include-children)) @injection.content) + (recipe_body) @injection.content) (assignment (expression (value (external_command (command_body) @injection.content)))) @@ -57,10 +56,10 @@ (source_file (setting "shell" ":=" "[" (string) @injection.language - (#not-match? @langstr ".*(powershell|pwsh|cmd).*")) + (#not-match? @injection.language ".*(powershell|pwsh|cmd).*")) [ (recipe - (recipe_body (#set! injection.include-children)) @injection.content) + (recipe_body) @injection.content) (assignment (expression (value (external_command (command_body) @injection.content)))) @@ -70,6 +69,4 @@ ; Set highlighting for recipes that specify a language (recipe_body - (shebang (language) @injection.language) - (#set! injection.include-children)) @injection.content - + (shebang (language) @injection.language)) @injection.content \ No newline at end of file diff --git a/queries/just/locals.scm b/queries/just/locals.scm index d0c2325..b510271 100644 --- a/queries/just/locals.scm +++ b/queries/just/locals.scm @@ -9,24 +9,24 @@ ; Definitions -(alias left: (identifier) @definition.variable) +(alias left: (identifier) @definition.var) -(assignment left: (identifier) @definition.variable) +(assignment left: (identifier) @definition.var) (module name: (identifier) @definition.namespace) -(parameter name: (identifier) @definition.variable) +(parameter name: (identifier) @definition.var) (recipe_header name: (identifier) @definition.function) ; References -(alias right: (identifier) @reference.variable) +(alias right: (identifier) @reference) -(function_call name: (identifier) @reference.function) +(function_call name: (identifier) @reference) -(dependency name: (identifier) @reference.function) +(dependency name: (identifier) @reference) -(dependency_expression name: (identifier) @reference.function) +(dependency_expression name: (identifier) @reference) -(value (identifier) @reference.variable) +(value (identifier) @reference) \ No newline at end of file diff --git a/queries/just/textobjects.scm b/queries/just/textobjects.scm index c676085..6758cd4 100644 --- a/queries/just/textobjects.scm +++ b/queries/just/textobjects.scm @@ -4,40 +4,12 @@ (recipe_body) @function.inner) @function.outer (parameters - ((_) @parameter.inside . ","? @parameter.outer)) @parameter.outer + ((_) @parameter.inner . ","? @parameter.outer)) @parameter.outer (dependency_expression - (_) @parameter.inside) @parameter.outer + (_) @parameter.inner) @parameter.outer (function_call - arguments: (sequence (expression) @parameter.inside) @parameter.outer) @function.outer - -(comment) @comment.outer - -; (expression -; if:(expression) @block.inner -; ) -; (expression -; else:(expression) @block.inner -; ) -; (interpolation (expression) @block.inner) @block.outer -; ; (string_array (stringlist) @block.inner) @block.outer - -; ; (stringlist -; ; (string) @parameter.inner -; ; . ","? @_end -; ; (#make-range! "parameter.outer" @parameter.inner @_end) -; ; ) -; (parameters -; [ -; (parameter) -; (variadic_parameter) -; ] @parameter.inner -; . " "? @_end -; (#make-range! "parameter.outer" @parameter.inner @_end) -; ) - -; (item [(alias) (assignment) (export) (setting)]) @statement.outer -; (recipe_header) @statement.outer -; (line) @statement.outer + arguments: (sequence (expression) @parameter.inner) @parameter.outer) @function.outer +(comment) @comment.outer \ No newline at end of file diff --git a/test/highlight/statements.just b/test/highlight/statements.just index fc2c1c9..a18c164 100644 --- a/test/highlight/statements.just +++ b/test/highlight/statements.just @@ -161,13 +161,13 @@ foo_fn := env("abc", foo) # ^ punctuation.bracket export fooexp := "abc" -# <- keyword.import +# <- keyword.control.import # ^^^^^^ variable # ^^ operator # ^^^^ string import? 'baz.just' -# <- keyword.import +# <- keyword.control.import # ^ operator # ^^^^^^^^^^ string