From f5dc45310941dff6efc02d955fc0c110190e9b85 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Wed, 17 Jan 2024 16:55:52 +0100 Subject: feat(treesitter)!: new standard capture names Problem: Sharing queries with upstream and Helix is difficult due to different capture names. Solution: Define and document a new set of standard captures that matches tree-sitter "standard captures" (where defined) and is closer to Helix' Atom-style nested groups. This is a breaking change for colorschemes that defined highlights based on the old captures. On the other hand, the default colorscheme now defines links for all standard captures (not just those used in bundled queries), improving the out-of-the-box experience. --- runtime/queries/bash/folds.scm | 1 + runtime/queries/bash/highlights.scm | 242 +++++++++++++++++++++++------------- 2 files changed, 160 insertions(+), 83 deletions(-) (limited to 'runtime/queries/bash') diff --git a/runtime/queries/bash/folds.scm b/runtime/queries/bash/folds.scm index 851c67eed4..766dbe598b 100644 --- a/runtime/queries/bash/folds.scm +++ b/runtime/queries/bash/folds.scm @@ -5,4 +5,5 @@ (for_statement) (while_statement) (c_style_for_statement) + (heredoc_redirect) ] @fold diff --git a/runtime/queries/bash/highlights.scm b/runtime/queries/bash/highlights.scm index 23bf03e697..21346ded8f 100644 --- a/runtime/queries/bash/highlights.scm +++ b/runtime/queries/bash/highlights.scm @@ -1,81 +1,100 @@ -(simple_expansion) @none -(expansion - "${" @punctuation.special - "}" @punctuation.special) @none [ - "(" - ")" - "((" - "))" - "{" - "}" - "[" - "]" - "[[" - "]]" - ] @punctuation.bracket + "(" + ")" + "{" + "}" + "[" + "]" + "[[" + "]]" + "((" + "))" +] @punctuation.bracket [ - ";" - ";;" - (heredoc_start) - ] @punctuation.delimiter + ";" + ";;" + ";&" + ";;&" + "&" +] @punctuation.delimiter [ - "$" -] @punctuation.special - + ">" + ">>" + "<" + "<<" + "&&" + "|" + "|&" + "||" + "=" + "+=" + "=~" + "==" + "!=" + "&>" + "&>>" + "<&" + ">&" + ">|" + "<&-" + ">&-" + "<<-" + "<<<" + ".." +] @operator + +; Do *not* spell check strings since they typically have some sort of +; interpolation in them, or, are typically used for things like filenames, URLs, +; flags and file content. [ - ">" - ">>" - "<" - "<<" - "&" - "&&" - "|" - "||" - "=" - "=~" - "==" - "!=" - ] @operator + (string) + (raw_string) + (ansi_c_string) + (heredoc_body) +] @string [ - (string) - (raw_string) - (ansi_c_string) - (heredoc_body) -] @string @spell + (heredoc_start) + (heredoc_end) +] @label -(variable_assignment (word) @string) +(variable_assignment + (word) @string) + +(command + argument: "$" @string) ; bare dollar [ - "if" - "then" - "else" - "elif" - "fi" - "case" - "in" - "esac" - ] @conditional + "if" + "then" + "else" + "elif" + "fi" + "case" + "in" + "esac" +] @keyword.conditional [ - "for" - "do" - "done" - "select" - "until" - "while" - ] @repeat + "for" + "do" + "done" + "select" + "until" + "while" +] @keyword.repeat [ - "declare" - "export" - "local" - "readonly" - "unset" - ] @keyword + "declare" + "typeset" + "export" + "readonly" + "local" + "unset" + "unsetenv" +] @keyword "function" @keyword.function @@ -83,28 +102,56 @@ ; trap -l ((word) @constant.builtin - (#match? @constant.builtin "^SIG(HUP|INT|QUIT|ILL|TRAP|ABRT|BUS|FPE|KILL|USR[12]|SEGV|PIPE|ALRM|TERM|STKFLT|CHLD|CONT|STOP|TSTP|TT(IN|OU)|URG|XCPU|XFSZ|VTALRM|PROF|WINCH|IO|PWR|SYS|RTMIN([+]([1-9]|1[0-5]))?|RTMAX(-([1-9]|1[0-4]))?)$")) + (#match? @constant.builtin "^SIG(HUP|INT|QUIT|ILL|TRAP|ABRT|BUS|FPE|KILL|USR[12]|SEGV|PIPE|ALRM|TERM|STKFLT|CHLD|CONT|STOP|TSTP|TT(IN|OU)|URG|XCPU|XFSZ|VTALRM|PROF|WINCH|IO|PWR|SYS|RTMIN([+]([1-9]|1[0-5]))?|RTMAX(-([1-9]|1[0-4]))?)$")) ((word) @boolean (#any-of? @boolean "true" "false")) (comment) @comment @spell -(test_operator) @string + +(test_operator) @operator (command_substitution - [ "$(" ")" ] @punctuation.bracket) + "$(" @punctuation.bracket) (process_substitution - [ "<(" ")" ] @punctuation.bracket) + "<(" @punctuation.bracket) +(arithmetic_expansion + [ + "$((" + "((" + ] @punctuation.special + "))" @punctuation.special) + +(arithmetic_expansion + "," @punctuation.delimiter) + +(ternary_expression + [ + "?" + ":" + ] @keyword.conditional.ternary) + +(binary_expression + operator: _ @operator) + +(unary_expression + operator: _ @operator) + +(postfix_expression + operator: _ @operator) (function_definition name: (word) @function) -(command_name (word) @function.call) +(command_name + (word) @function.call) -((command_name (word) @function.builtin) - (#any-of? @function.builtin +((command_name + (word) @function.builtin) + ; format-ignore + (#any-of? @function.builtin "alias" "bg" "bind" "break" "builtin" "caller" "cd" "command" "compgen" "complete" "compopt" "continue" "coproc" "dirs" "disown" "echo" "enable" "eval" @@ -116,30 +163,59 @@ "ulimit" "umask" "unalias" "wait")) (command - argument: [ - (word) @parameter - (concatenation (word) @parameter) - ]) + argument: + [ + (word) @variable.parameter + (concatenation + (word) @variable.parameter) + ]) + +(number) @number ((word) @number (#lua-match? @number "^[0-9]+$")) (file_redirect - descriptor: (file_descriptor) @operator - destination: (word) @parameter) + destination: (word) @variable.parameter) + +(file_descriptor) @operator + +(simple_expansion + "$" @punctuation.special) @none + +(expansion + "${" @punctuation.special + "}" @punctuation.special) @none (expansion - [ "${" "}" ] @punctuation.bracket) + operator: _ @punctuation.special) + +(expansion + "@" + . + operator: _ @character.special) + +((expansion + (subscript + index: (word) @character.special)) + (#any-of? @character.special "@" "*")) + +"``" @punctuation.special (variable_name) @variable ((variable_name) @constant - (#lua-match? @constant "^[A-Z][A-Z_0-9]*$")) + (#lua-match? @constant "^[A-Z][A-Z_0-9]*$")) (case_item - value: (word) @parameter) - -(regex) @string.regex + value: (word) @variable.parameter) -((program . (comment) @preproc) - (#lua-match? @preproc "^#!/")) +[ + (regex) + (extglob_pattern) +] @string.regexp + +((program + . + (comment) @keyword.directive) + (#lua-match? @keyword.directive "^#!/")) -- cgit From 71429c90eeb979c6062ee845e516d28b5e6ce402 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Sat, 10 Feb 2024 14:15:43 +0100 Subject: build(deps): bump tree-sitter-bash to v0.20.5 --- runtime/queries/bash/highlights.scm | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'runtime/queries/bash') diff --git a/runtime/queries/bash/highlights.scm b/runtime/queries/bash/highlights.scm index 21346ded8f..b4360ce7e1 100644 --- a/runtime/queries/bash/highlights.scm +++ b/runtime/queries/bash/highlights.scm @@ -43,6 +43,7 @@ "<<-" "<<<" ".." + "!" ] @operator ; Do *not* spell check strings since they typically have some sort of @@ -66,6 +67,13 @@ (command argument: "$" @string) ; bare dollar +(concatenation + [ + (simple_expansion) + (expansion) + ] + (word) @string) + [ "if" "then" -- cgit