From ff94f5d066d54fc177ff790157b8e6ce52ac02c2 Mon Sep 17 00:00:00 2001 From: Axlefublr <101342105+Axlefublr@users.noreply.github.com> Date: Wed, 3 Sep 2025 18:18:07 +0800 Subject: [PATCH 01/19] update nushell parser and queries --- book/src/generated/lang-support.md | 2 +- languages.toml | 2 +- runtime/queries/nu/folds.scm | 10 + runtime/queries/nu/highlights.scm | 574 ++++++++++++++++++----------- runtime/queries/nu/indents.scm | 26 ++ runtime/queries/nu/injections.scm | 49 ++- runtime/queries/nu/textobjects.scm | 78 ++++ 7 files changed, 516 insertions(+), 225 deletions(-) create mode 100644 runtime/queries/nu/folds.scm create mode 100644 runtime/queries/nu/indents.scm create mode 100644 runtime/queries/nu/textobjects.scm diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index c114faa13d82..17f6149d0f8b 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -175,7 +175,7 @@ | nickel | ✓ | | ✓ | | | `nls` | | nim | ✓ | ✓ | ✓ | | | `nimlangserver` | | nix | ✓ | ✓ | ✓ | | ✓ | `nil`, `nixd` | -| nu | ✓ | | | | | `nu` | +| nu | ✓ | ✓ | ✓ | | | `nu` | | nunjucks | ✓ | | | | | | | ocaml | ✓ | | ✓ | | | `ocamllsp` | | ocaml-interface | ✓ | | | | | `ocamllsp` | diff --git a/languages.toml b/languages.toml index 9055a6d9a808..613030c54798 100644 --- a/languages.toml +++ b/languages.toml @@ -2368,7 +2368,7 @@ language-servers = [ "nu-lsp" ] [[grammar]] name = "nu" -source = { git = "https://github.com/nushell/tree-sitter-nu", rev = "358c4f509eb97f0148bbd25ad36acc729819b9c1" } +source = { git = "https://github.com/nushell/tree-sitter-nu", rev = "cc4624fbc6ec3563d98fbe8f215a8b8e10b16f32" } [[language]] name = "vala" diff --git a/runtime/queries/nu/folds.scm b/runtime/queries/nu/folds.scm new file mode 100644 index 000000000000..53607745aa60 --- /dev/null +++ b/runtime/queries/nu/folds.scm @@ -0,0 +1,10 @@ +[ + (attribute_list) + (block) + (command_list) + (parameter_bracks) + (record_body) + (val_list) + (val_table) + (val_closure) +] @fold diff --git a/runtime/queries/nu/highlights.scm b/runtime/queries/nu/highlights.scm index 66a305840508..8fe3bf10afff 100644 --- a/runtime/queries/nu/highlights.scm +++ b/runtime/queries/nu/highlights.scm @@ -1,284 +1,418 @@ -;;; --- -;;; keywords +; --- +; keywords [ - "def" - "alias" - "export-env" - "export" - "extern" - "module" + "let" + "mut" + "const" +] @keyword - "let" - "let-env" - "mut" - "const" +[ + "if" + "else" + "match" +] @keyword.conditional - "hide-env" +[ + "loop" + "while" +] @keyword.repeat - "source" - "source-env" +"def" @keyword.function - "overlay" - "register" +[ + "try" + "catch" + "error" +] @keyword.exception - "loop" - "while" - "error" +[ + "module" + "use" +] @keyword.import - "do" - "if" - "else" - "try" - "catch" - "match" +[ + "alias" + "export-env" + "export" + "extern" +] @keyword.modifier - "break" - "continue" - "return" +(decl_use + "use" @keyword) -] @keyword +(ctrl_for + "for" @keyword + "in" @keyword) -(hide_mod "hide" @keyword) -(decl_use "use" @keyword) +; --- +; literals +(val_number) @number -(ctrl_for - "for" @keyword - "in" @keyword -) -(overlay_list "list" @keyword.storage.modifier) -(overlay_hide "hide" @keyword.storage.modifier) -(overlay_new "new" @keyword.storage.modifier) -(overlay_use - "use" @keyword.storage.modifier - "as" @keyword -) -(ctrl_error "make" @keyword.storage.modifier) - -;;; --- -;;; literals -(val_number) @constant.numeric (val_duration - unit: [ - "ns" "µs" "us" "ms" "sec" "min" "hr" "day" "wk" - ] @variable.parameter -) + unit: _ @variable.parameter) + (val_filesize - unit: [ - "b" "B" - - "kb" "kB" "Kb" "KB" - "mb" "mB" "Mb" "MB" - "gb" "gB" "Gb" "GB" - "tb" "tB" "Tb" "TB" - "pb" "pB" "Pb" "PB" - "eb" "eB" "Eb" "EB" - - "kib" "kiB" "kIB" "kIb" "Kib" "KIb" "KIB" - "mib" "miB" "mIB" "mIb" "Mib" "MIb" "MIB" - "gib" "giB" "gIB" "gIb" "Gib" "GIb" "GIB" - "tib" "tiB" "tIB" "tIb" "Tib" "TIb" "TIB" - "pib" "piB" "pIB" "pIb" "Pib" "PIb" "PIB" - "eib" "eiB" "eIB" "eIb" "Eib" "EIb" "EIB" - ] @variable.parameter -) + unit: _ @variable.parameter) + (val_binary - [ - "0b" - "0o" - "0x" - ] @constant.numeric - "[" @punctuation.bracket - digit: [ - "," @punctuation.delimiter - (hex_digit) @constant.number - ] - "]" @punctuation.bracket -) @constant.numeric + [ + "0b" + "0o" + "0x" + ] @number + "[" @punctuation.bracket + digit: [ + "," @punctuation.delimiter + (hex_digit) @number + ] + "]" @punctuation.bracket) @number + (val_bool) @constant.builtin + (val_nothing) @constant.builtin + (val_string) @string -(val_date) @constant.number + +arg_str: (val_string) @variable.parameter + +file_path: (val_string) @variable.parameter + +(val_date) @number + (inter_escape_sequence) @constant.character.escape + (escape_sequence) @constant.character.escape -(val_interpolated [ + +(val_interpolated + [ "$\"" "$\'" "\"" "\'" -] @string) + ] @string) + (unescaped_interpolated_content) @string + (escaped_interpolated_content) @string -(expr_interpolated ["(" ")"] @variable.parameter) -;;; --- -;;; operators -(expr_binary [ - "+" - "-" - "*" - "/" - "mod" - "//" - "++" - "**" - "==" - "!=" - "<" - "<=" - ">" - ">=" - "=~" - "!~" - "and" - "or" - "xor" - "bit-or" - "bit-xor" - "bit-and" - "bit-shl" - "bit-shr" - "in" - "not-in" - "starts-with" - "ends-with" -] @operator ) - -(where_command [ - "+" - "-" - "*" - "/" - "mod" - "//" - "++" - "**" - "==" - "!=" - "<" - "<=" - ">" - ">=" - "=~" - "!~" - "and" - "or" - "xor" - "bit-or" - "bit-xor" - "bit-and" - "bit-shl" - "bit-shr" - "in" - "not-in" - "starts-with" - "ends-with" -] @operator) - -(assignment [ +(expr_interpolated + [ + "(" + ")" + ] @variable.parameter) + +(raw_string_begin) @punctuation.special + +(raw_string_end) @punctuation.special + +; --- +; operators +(expr_binary + opr: _ @operator) + +(where_predicate + opr: _ @operator) + +(assignment + [ "=" "+=" "-=" "*=" "/=" "++=" -] @operator) + ] @operator) -(expr_unary ["not" "-"] @operator) +(expr_unary + [ + "not" + "-" + ] @operator) -(val_range [ +(val_range + [ ".." "..=" "..<" -] @operator) + ] @operator) -["=>" "=" "|"] @operator +[ + "=>" + "=" + "|" +] @operator [ - "o>" "out>" - "e>" "err>" - "e+o>" "err+out>" - "o+e>" "out+err>" -] @special - -;;; --- -;;; punctuation + "o>" + "out>" + "e>" + "err>" + "e+o>" + "err+out>" + "o+e>" + "out+err>" + "o>>" + "out>>" + "e>>" + "err>>" + "e+o>>" + "err+out>>" + "o+e>>" + "out+err>>" + "e>|" + "err>|" + "e+o>|" + "err+out>|" + "o+e>|" + "out+err>|" +] @operator + +; --- +; punctuation [ - "," - ";" -] @punctuation.delimiter - -(param_short_flag "-" @punctuation.delimiter) -(param_long_flag ["--"] @punctuation.delimiter) -(long_flag ["--"] @punctuation.delimiter) -(param_rest "..." @punctuation.delimiter) -(param_type [":"] @punctuation.special) -(param_value ["="] @punctuation.special) -(param_cmd ["@"] @punctuation.special) -(param_opt ["?"] @punctuation.special) + "," + ";" +] @punctuation.special + +(param_long_flag + "--" @punctuation.delimiter) + +(long_flag + "--" @punctuation.delimiter) + +(short_flag + "-" @punctuation.delimiter) + +(long_flag + "=" @punctuation.special) + +(short_flag + "=" @punctuation.special) + +(param_short_flag + "-" @punctuation.delimiter) + +(param_rest + "..." @punctuation.delimiter) + +(param_type + ":" @punctuation.special) + +(param_value + "=" @punctuation.special) + +(param_cmd + "@" @punctuation.special) + +(attribute + "@" @punctuation.special) + +(param_opt + "?" @punctuation.special) + +(returns + "->" @punctuation.special) [ - "(" ")" - "{" "}" - "[" "]" + "(" + ")" + "{" + "}" + "[" + "]" + "...[" + "...(" + "...{" ] @punctuation.bracket (val_record - (record_entry ":" @punctuation.delimiter)) -;;; --- -;;; identifiers + (record_entry + ":" @punctuation.delimiter)) + +key: (identifier) @property + +; --- +; identifiers (param_rest - name: (_) @variable.parameter) + name: (_) @variable.parameter) + (param_opt - name: (_) @variable.parameter) + name: (_) @variable.parameter) + (parameter - param_name: (_) @variable.parameter) + param_name: (_) @variable.parameter) + (param_cmd - (cmd_identifier) @string) -(param_long_flag) @variable.parameter -(param_short_flag) @variable.parameter + (cmd_identifier) @string) + +(param_long_flag + (long_flag_identifier) @attribute) + +(param_short_flag + (param_short_flag_identifier) @attribute) + +(attribute + (attribute_identifier) @attribute) -(short_flag) @variable.parameter -(long_flag) @variable.parameter +(short_flag + (short_flag_identifier) @attribute) -(scope_pattern [(wild_card) @function]) +(long_flag_identifier) @attribute + +(scope_pattern + (wild_card) @function) (cmd_identifier) @function +; generated with Nu 0.93.0 +; > help commands +; | filter { $in.command_type == builtin and $in.category != core } +; | each {$'"($in.name | split row " " | $in.0)"'} +; | uniq +; | str join ' ' +(command + head: (cmd_identifier) @function.builtin + (#any-of? @function.builtin + "all" "ansi" "any" "append" "ast" "bits" "bytes" "cal" "cd" "char" "clear" "collect" "columns" + "compact" "complete" "config" "cp" "date" "debug" "decode" "default" "detect" "dfr" "drop" "du" + "each" "encode" "enumerate" "every" "exec" "exit" "explain" "explore" "export-env" "fill" + "filter" "find" "first" "flatten" "fmt" "format" "from" "generate" "get" "glob" "grid" "group" + "group-by" "hash" "headers" "histogram" "history" "http" "input" "insert" "inspect" "interleave" + "into" "is-empty" "is-not-empty" "is-terminal" "items" "join" "keybindings" "kill" "last" + "length" "let-env" "lines" "load-env" "ls" "math" "merge" "metadata" "mkdir" "mktemp" "move" + "mv" "nu-check" "nu-highlight" "open" "panic" "par-each" "parse" "path" "plugin" "port" + "prepend" "print" "ps" "query" "random" "range" "reduce" "reject" "rename" "reverse" "rm" "roll" + "rotate" "run-external" "save" "schema" "select" "seq" "shuffle" "skip" "sleep" "sort" "sort-by" + "split" "split-by" "start" "stor" "str" "sys" "table" "take" "tee" "term" "timeit" "to" "touch" + "transpose" "tutor" "ulimit" "uname" "uniq" "uniq-by" "update" "upsert" "url" "values" "view" + "watch" "where" "which" "whoami" "window" "with-env" "wrap" "zip")) + +(command + head: (cmd_identifier) @keyword.repeat + (#any-of? @keyword.repeat "break" "continue" "return")) + +(command + head: (cmd_identifier) @keyword + (#any-of? @keyword "do" "source" "source-env" "hide" "hide-env")) + (command - "^" @punctuation.delimiter - head: (_) @function -) + head: (cmd_identifier) @keyword + . + arg_str: (val_string) @keyword.import + (#any-of? @keyword "overlay" "error")) -"where" @function +(command + head: (cmd_identifier) @cmd + arg_str: (val_string) @keyword + (#eq? @cmd "overlay") + (#eq? @keyword "as")) + +(command + "^" @punctuation.delimiter + head: (_) @function) + +"where" @function.builtin + +(where_predicate + [ + "?" + "!" + ] @punctuation.delimiter) (path - ["." "?"] @punctuation.delimiter -) @variable.parameter + [ + "." + "?" + "!" + ]? @punctuation.delimiter) @variable.parameter -(val_variable - "$" @variable.parameter +(stmt_let + (identifier) @variable) + +(val_variable + "$"? @punctuation.special + "...$"? @punctuation.special [ - (identifier) @namespace - "in" - "nu" - "env" - "nothing" - ] @special -) -;;; --- -;;; types -(flat_type) @type.builtin + (identifier) @variable + "in" @special + "nu" @namespace + "env" @constant + ]) @none + +(val_cellpath + "$" @punctuation.special) + +(record_entry + ":" @punctuation.special) + +; --- +; types +(flat_type) @type + (list_type - "list" @type.enum - ["<" ">"] @punctuation.bracket -) + "list" @type.enum + [ + "<" + ">" + ] @punctuation.bracket) + (collection_type - ["record" "table"] @type.enum - "<" @punctuation.bracket - key: (_) @variable.parameter - ["," ":"] @punctuation.delimiter - ">" @punctuation.bracket -) - -(shebang) @comment + [ + "record" + "table" + ] @type.enum + "<" @punctuation.bracket + key: (_) @variable.parameter + [ + "," + ":" + ] @punctuation.special + ">" @punctuation.bracket) + +(composite_type + "oneof" @type.enum + [ + "<" + ">" + ] @punctuation.bracket) + +(shebang) @keyword.directive + (comment) @comment + +((comment)+ @comment.documentation @spell + . + (decl_def)) + +(parameter + (comment) @comment.documentation @spell) + +(command + head: ((cmd_identifier) @_cmd + (#match? @_cmd "^\\s*(find|parse|split|str)$")) + flag: (_ + name: (_) @_flag + (#any-of? @_flag "r" "regex")) + . + arg: (_ + (string_content) @string.regexp)) + +(_ + opr: [ + "=~" + "!~" + "like" + "not-like" + ] + rhs: (_ + (string_content) @string.regexp)) + +(command + head: ((_) @_cmd + (#any-of? @_cmd "nu" "$nu.current-exe")) + flag: (_ + name: (_) @_flag + (#any-of? @_flag "c" "e" "commands" "execute")) + . + arg: (_ + (string_content) @string.code)) diff --git a/runtime/queries/nu/indents.scm b/runtime/queries/nu/indents.scm new file mode 100644 index 000000000000..e711f7e46c1e --- /dev/null +++ b/runtime/queries/nu/indents.scm @@ -0,0 +1,26 @@ +[ + (expr_parenthesized) + (parameter_bracks) + (ctrl_match) + + (val_record) + (val_list) + (val_closure) + (val_table) + + (block) +] @indent.begin + +[ + "}" + "]" + ")" +] @indent.end + +[ + "}" + "]" + ")" +] @indent.branch + +(comment) @indent.auto diff --git a/runtime/queries/nu/injections.scm b/runtime/queries/nu/injections.scm index 690ff9a864ca..8005ffdc64bc 100644 --- a/runtime/queries/nu/injections.scm +++ b/runtime/queries/nu/injections.scm @@ -1,7 +1,50 @@ ((comment) @injection.content - (#set! injection.language "comment")) + (#set! injection.language "comment")) + +(command + head: ((cmd_identifier) @_cmd + (#match? @_cmd "^\\s*(find|parse|split|str)$")) + flag: (_ + name: (_) @_flag + (#any-of? @_flag "r" "regex")) + . + arg: (_ + (string_content) @injection.content + (#set! injection.language "regex"))) + +(_ + opr: [ + "=~" + "!~" + "like" + "not-like" + ] + rhs: (_ + (string_content) @injection.content + (#set! injection.language "regex"))) + +(command + head: (_) @_cmd + (#any-of? @_cmd "nu" "$nu.current-exe") + flag: (_ + name: (_) @_flag + (#any-of? @_flag "c" "e" "commands" "execute")) + . + arg: (_ + (string_content) @injection.content + (#set! injection.language "nu"))) (command head: (cmd_identifier) @_command (#any-of? @_command "jq" "jaq") - arg: (val_string) @injection.content - (#set! injection.language "jq")) + . + arg: (_ (string_content) @injection.content) + (#set! injection.language "jq") +) + +(command + head: (cmd_identifier) @_command (#eq? @_command "fish") + flag: (short_flag "-") @_flag (#match? @_flag "^-.*c$") + . + arg: (_ (string_content) @injection.content) + (#set! injection.language "fish") +) diff --git a/runtime/queries/nu/textobjects.scm b/runtime/queries/nu/textobjects.scm new file mode 100644 index 000000000000..4b87084bbe2e --- /dev/null +++ b/runtime/queries/nu/textobjects.scm @@ -0,0 +1,78 @@ +(stmt_let) @assignment.outer + +(stmt_mut) @assignment.outer + +(stmt_const) @assignment.outer + +(stmt_let + value: (_) @assignment.inner) + +(stmt_mut + value: (_) @assignment.inner) + +(stmt_const + value: (_) @assignment.inner) + +(block) @block.outer + +(comment) @comment.outer + +(pipeline) @pipeline.outer + +(pipe_element) @pipeline.inner + +(decl_def) @function.outer + +(decl_def + body: (_) @function.inner) + +(ctrl_for) @loop.outer + +(ctrl_loop) @loop.outer + +(ctrl_while) @loop.outer + +(ctrl_for + body: (_) @loop.inner) + +(ctrl_loop + body: (_) @loop.inner) + +(ctrl_while + body: (_) @loop.inner) + +; Conditional inner counts the last one, rather than the current one. +(ctrl_if + then_branch: (_) @conditional.inner + else_block: (_)? @conditional.inner) @conditional.outer + +(parameter) @parameter.outer + +(command + head: (_) @call.inner) @call.outer + +(where_command + predicate: (_) @call.inner) @call.outer + +; define pipeline first, because it should only match as a fallback +; e.g., `let a = date now` should match the whole assignment. +; But a standalone `date now` should also match a statement +(pipeline) @statement.outer + +(stmt_let) @statement.outer + +(stmt_mut) @statement.outer + +(stmt_const) @statement.outer + +(ctrl_if) @statement.outer + +(ctrl_try) @statement.outer + +(ctrl_match) @statement.outer + +(ctrl_while) @statement.outer + +(ctrl_loop) @statement.outer + +(val_number) @number.inner From 1a672c2608c06847610905ffb8a5c7e24ba6e53a Mon Sep 17 00:00:00 2001 From: Axlefublr <101342105+Axlefublr@users.noreply.github.com> Date: Wed, 3 Sep 2025 18:42:22 +0800 Subject: [PATCH 02/19] @number -> @constant.numeric --- runtime/queries/nu/highlights.scm | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/runtime/queries/nu/highlights.scm b/runtime/queries/nu/highlights.scm index 8fe3bf10afff..55e3cb6547d5 100644 --- a/runtime/queries/nu/highlights.scm +++ b/runtime/queries/nu/highlights.scm @@ -46,7 +46,7 @@ ; --- ; literals -(val_number) @number +(val_number) @constant.numeric (val_duration unit: _ @variable.parameter) @@ -59,13 +59,13 @@ "0b" "0o" "0x" - ] @number + ] @constant.numeric "[" @punctuation.bracket digit: [ "," @punctuation.delimiter - (hex_digit) @number + (hex_digit) @constant.numeric ] - "]" @punctuation.bracket) @number + "]" @punctuation.bracket) @constant.numeric (val_bool) @constant.builtin @@ -77,7 +77,7 @@ arg_str: (val_string) @variable.parameter file_path: (val_string) @variable.parameter -(val_date) @number +(val_date) @constant.numeric (inter_escape_sequence) @constant.character.escape @@ -376,9 +376,7 @@ key: (identifier) @property ">" ] @punctuation.bracket) -(shebang) @keyword.directive - -(comment) @comment +[(comment) (shebang)] @comment ((comment)+ @comment.documentation @spell . From f4162e6bb7087fed0a0aa9a8e09b44d97deec4fd Mon Sep 17 00:00:00 2001 From: Axlefublr <101342105+Axlefublr@users.noreply.github.com> Date: Wed, 3 Sep 2025 18:50:48 +0800 Subject: [PATCH 03/19] revert changing @number --- runtime/queries/nu/highlights.scm | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/runtime/queries/nu/highlights.scm b/runtime/queries/nu/highlights.scm index 55e3cb6547d5..748530f21ed3 100644 --- a/runtime/queries/nu/highlights.scm +++ b/runtime/queries/nu/highlights.scm @@ -46,7 +46,7 @@ ; --- ; literals -(val_number) @constant.numeric +(val_number) @number (val_duration unit: _ @variable.parameter) @@ -59,13 +59,13 @@ "0b" "0o" "0x" - ] @constant.numeric + ] @number "[" @punctuation.bracket digit: [ "," @punctuation.delimiter - (hex_digit) @constant.numeric + (hex_digit) @number ] - "]" @punctuation.bracket) @constant.numeric + "]" @punctuation.bracket) @number (val_bool) @constant.builtin @@ -77,7 +77,7 @@ arg_str: (val_string) @variable.parameter file_path: (val_string) @variable.parameter -(val_date) @constant.numeric +(val_date) @number (inter_escape_sequence) @constant.character.escape From 1c38a2afb667c8e1f6fea5cd46bee5d5c386290e Mon Sep 17 00:00:00 2001 From: Axlefublr <101342105+Axlefublr@users.noreply.github.com> Date: Sat, 6 Sep 2025 16:50:37 +0800 Subject: [PATCH 04/19] remove `@spell` to make comment highlight work --- runtime/queries/nu/highlights.scm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/queries/nu/highlights.scm b/runtime/queries/nu/highlights.scm index 748530f21ed3..df44bfab2287 100644 --- a/runtime/queries/nu/highlights.scm +++ b/runtime/queries/nu/highlights.scm @@ -378,12 +378,12 @@ key: (identifier) @property [(comment) (shebang)] @comment -((comment)+ @comment.documentation @spell +((comment)+ @comment.documentation . (decl_def)) (parameter - (comment) @comment.documentation @spell) + (comment) @comment.documentation) (command head: ((cmd_identifier) @_cmd From 1ab28359742f1172beffb0a21bf63832c6adffa9 Mon Sep 17 00:00:00 2001 From: Axlefublr <101342105+Axlefublr@users.noreply.github.com> Date: Sun, 7 Sep 2025 18:35:36 +0800 Subject: [PATCH 05/19] remove all queries --- book/src/generated/lang-support.md | 2 +- runtime/queries/nu/folds.scm | 10 - runtime/queries/nu/highlights.scm | 416 ----------------------------- runtime/queries/nu/indents.scm | 26 -- runtime/queries/nu/injections.scm | 50 ---- runtime/queries/nu/textobjects.scm | 78 ------ 6 files changed, 1 insertion(+), 581 deletions(-) delete mode 100644 runtime/queries/nu/folds.scm delete mode 100644 runtime/queries/nu/highlights.scm delete mode 100644 runtime/queries/nu/indents.scm delete mode 100644 runtime/queries/nu/injections.scm delete mode 100644 runtime/queries/nu/textobjects.scm diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index 17f6149d0f8b..2170f8ae5e14 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -175,7 +175,7 @@ | nickel | ✓ | | ✓ | | | `nls` | | nim | ✓ | ✓ | ✓ | | | `nimlangserver` | | nix | ✓ | ✓ | ✓ | | ✓ | `nil`, `nixd` | -| nu | ✓ | ✓ | ✓ | | | `nu` | +| nu | | | | | | `nu` | | nunjucks | ✓ | | | | | | | ocaml | ✓ | | ✓ | | | `ocamllsp` | | ocaml-interface | ✓ | | | | | `ocamllsp` | diff --git a/runtime/queries/nu/folds.scm b/runtime/queries/nu/folds.scm deleted file mode 100644 index 53607745aa60..000000000000 --- a/runtime/queries/nu/folds.scm +++ /dev/null @@ -1,10 +0,0 @@ -[ - (attribute_list) - (block) - (command_list) - (parameter_bracks) - (record_body) - (val_list) - (val_table) - (val_closure) -] @fold diff --git a/runtime/queries/nu/highlights.scm b/runtime/queries/nu/highlights.scm deleted file mode 100644 index df44bfab2287..000000000000 --- a/runtime/queries/nu/highlights.scm +++ /dev/null @@ -1,416 +0,0 @@ -; --- -; keywords -[ - "let" - "mut" - "const" -] @keyword - -[ - "if" - "else" - "match" -] @keyword.conditional - -[ - "loop" - "while" -] @keyword.repeat - -"def" @keyword.function - -[ - "try" - "catch" - "error" -] @keyword.exception - -[ - "module" - "use" -] @keyword.import - -[ - "alias" - "export-env" - "export" - "extern" -] @keyword.modifier - -(decl_use - "use" @keyword) - -(ctrl_for - "for" @keyword - "in" @keyword) - -; --- -; literals -(val_number) @number - -(val_duration - unit: _ @variable.parameter) - -(val_filesize - unit: _ @variable.parameter) - -(val_binary - [ - "0b" - "0o" - "0x" - ] @number - "[" @punctuation.bracket - digit: [ - "," @punctuation.delimiter - (hex_digit) @number - ] - "]" @punctuation.bracket) @number - -(val_bool) @constant.builtin - -(val_nothing) @constant.builtin - -(val_string) @string - -arg_str: (val_string) @variable.parameter - -file_path: (val_string) @variable.parameter - -(val_date) @number - -(inter_escape_sequence) @constant.character.escape - -(escape_sequence) @constant.character.escape - -(val_interpolated - [ - "$\"" - "$\'" - "\"" - "\'" - ] @string) - -(unescaped_interpolated_content) @string - -(escaped_interpolated_content) @string - -(expr_interpolated - [ - "(" - ")" - ] @variable.parameter) - -(raw_string_begin) @punctuation.special - -(raw_string_end) @punctuation.special - -; --- -; operators -(expr_binary - opr: _ @operator) - -(where_predicate - opr: _ @operator) - -(assignment - [ - "=" - "+=" - "-=" - "*=" - "/=" - "++=" - ] @operator) - -(expr_unary - [ - "not" - "-" - ] @operator) - -(val_range - [ - ".." - "..=" - "..<" - ] @operator) - -[ - "=>" - "=" - "|" -] @operator - -[ - "o>" - "out>" - "e>" - "err>" - "e+o>" - "err+out>" - "o+e>" - "out+err>" - "o>>" - "out>>" - "e>>" - "err>>" - "e+o>>" - "err+out>>" - "o+e>>" - "out+err>>" - "e>|" - "err>|" - "e+o>|" - "err+out>|" - "o+e>|" - "out+err>|" -] @operator - -; --- -; punctuation -[ - "," - ";" -] @punctuation.special - -(param_long_flag - "--" @punctuation.delimiter) - -(long_flag - "--" @punctuation.delimiter) - -(short_flag - "-" @punctuation.delimiter) - -(long_flag - "=" @punctuation.special) - -(short_flag - "=" @punctuation.special) - -(param_short_flag - "-" @punctuation.delimiter) - -(param_rest - "..." @punctuation.delimiter) - -(param_type - ":" @punctuation.special) - -(param_value - "=" @punctuation.special) - -(param_cmd - "@" @punctuation.special) - -(attribute - "@" @punctuation.special) - -(param_opt - "?" @punctuation.special) - -(returns - "->" @punctuation.special) - -[ - "(" - ")" - "{" - "}" - "[" - "]" - "...[" - "...(" - "...{" -] @punctuation.bracket - -(val_record - (record_entry - ":" @punctuation.delimiter)) - -key: (identifier) @property - -; --- -; identifiers -(param_rest - name: (_) @variable.parameter) - -(param_opt - name: (_) @variable.parameter) - -(parameter - param_name: (_) @variable.parameter) - -(param_cmd - (cmd_identifier) @string) - -(param_long_flag - (long_flag_identifier) @attribute) - -(param_short_flag - (param_short_flag_identifier) @attribute) - -(attribute - (attribute_identifier) @attribute) - -(short_flag - (short_flag_identifier) @attribute) - -(long_flag_identifier) @attribute - -(scope_pattern - (wild_card) @function) - -(cmd_identifier) @function - -; generated with Nu 0.93.0 -; > help commands -; | filter { $in.command_type == builtin and $in.category != core } -; | each {$'"($in.name | split row " " | $in.0)"'} -; | uniq -; | str join ' ' -(command - head: (cmd_identifier) @function.builtin - (#any-of? @function.builtin - "all" "ansi" "any" "append" "ast" "bits" "bytes" "cal" "cd" "char" "clear" "collect" "columns" - "compact" "complete" "config" "cp" "date" "debug" "decode" "default" "detect" "dfr" "drop" "du" - "each" "encode" "enumerate" "every" "exec" "exit" "explain" "explore" "export-env" "fill" - "filter" "find" "first" "flatten" "fmt" "format" "from" "generate" "get" "glob" "grid" "group" - "group-by" "hash" "headers" "histogram" "history" "http" "input" "insert" "inspect" "interleave" - "into" "is-empty" "is-not-empty" "is-terminal" "items" "join" "keybindings" "kill" "last" - "length" "let-env" "lines" "load-env" "ls" "math" "merge" "metadata" "mkdir" "mktemp" "move" - "mv" "nu-check" "nu-highlight" "open" "panic" "par-each" "parse" "path" "plugin" "port" - "prepend" "print" "ps" "query" "random" "range" "reduce" "reject" "rename" "reverse" "rm" "roll" - "rotate" "run-external" "save" "schema" "select" "seq" "shuffle" "skip" "sleep" "sort" "sort-by" - "split" "split-by" "start" "stor" "str" "sys" "table" "take" "tee" "term" "timeit" "to" "touch" - "transpose" "tutor" "ulimit" "uname" "uniq" "uniq-by" "update" "upsert" "url" "values" "view" - "watch" "where" "which" "whoami" "window" "with-env" "wrap" "zip")) - -(command - head: (cmd_identifier) @keyword.repeat - (#any-of? @keyword.repeat "break" "continue" "return")) - -(command - head: (cmd_identifier) @keyword - (#any-of? @keyword "do" "source" "source-env" "hide" "hide-env")) - -(command - head: (cmd_identifier) @keyword - . - arg_str: (val_string) @keyword.import - (#any-of? @keyword "overlay" "error")) - -(command - head: (cmd_identifier) @cmd - arg_str: (val_string) @keyword - (#eq? @cmd "overlay") - (#eq? @keyword "as")) - -(command - "^" @punctuation.delimiter - head: (_) @function) - -"where" @function.builtin - -(where_predicate - [ - "?" - "!" - ] @punctuation.delimiter) - -(path - [ - "." - "?" - "!" - ]? @punctuation.delimiter) @variable.parameter - -(stmt_let - (identifier) @variable) - -(val_variable - "$"? @punctuation.special - "...$"? @punctuation.special - [ - (identifier) @variable - "in" @special - "nu" @namespace - "env" @constant - ]) @none - -(val_cellpath - "$" @punctuation.special) - -(record_entry - ":" @punctuation.special) - -; --- -; types -(flat_type) @type - -(list_type - "list" @type.enum - [ - "<" - ">" - ] @punctuation.bracket) - -(collection_type - [ - "record" - "table" - ] @type.enum - "<" @punctuation.bracket - key: (_) @variable.parameter - [ - "," - ":" - ] @punctuation.special - ">" @punctuation.bracket) - -(composite_type - "oneof" @type.enum - [ - "<" - ">" - ] @punctuation.bracket) - -[(comment) (shebang)] @comment - -((comment)+ @comment.documentation - . - (decl_def)) - -(parameter - (comment) @comment.documentation) - -(command - head: ((cmd_identifier) @_cmd - (#match? @_cmd "^\\s*(find|parse|split|str)$")) - flag: (_ - name: (_) @_flag - (#any-of? @_flag "r" "regex")) - . - arg: (_ - (string_content) @string.regexp)) - -(_ - opr: [ - "=~" - "!~" - "like" - "not-like" - ] - rhs: (_ - (string_content) @string.regexp)) - -(command - head: ((_) @_cmd - (#any-of? @_cmd "nu" "$nu.current-exe")) - flag: (_ - name: (_) @_flag - (#any-of? @_flag "c" "e" "commands" "execute")) - . - arg: (_ - (string_content) @string.code)) diff --git a/runtime/queries/nu/indents.scm b/runtime/queries/nu/indents.scm deleted file mode 100644 index e711f7e46c1e..000000000000 --- a/runtime/queries/nu/indents.scm +++ /dev/null @@ -1,26 +0,0 @@ -[ - (expr_parenthesized) - (parameter_bracks) - (ctrl_match) - - (val_record) - (val_list) - (val_closure) - (val_table) - - (block) -] @indent.begin - -[ - "}" - "]" - ")" -] @indent.end - -[ - "}" - "]" - ")" -] @indent.branch - -(comment) @indent.auto diff --git a/runtime/queries/nu/injections.scm b/runtime/queries/nu/injections.scm deleted file mode 100644 index 8005ffdc64bc..000000000000 --- a/runtime/queries/nu/injections.scm +++ /dev/null @@ -1,50 +0,0 @@ -((comment) @injection.content - (#set! injection.language "comment")) - -(command - head: ((cmd_identifier) @_cmd - (#match? @_cmd "^\\s*(find|parse|split|str)$")) - flag: (_ - name: (_) @_flag - (#any-of? @_flag "r" "regex")) - . - arg: (_ - (string_content) @injection.content - (#set! injection.language "regex"))) - -(_ - opr: [ - "=~" - "!~" - "like" - "not-like" - ] - rhs: (_ - (string_content) @injection.content - (#set! injection.language "regex"))) - -(command - head: (_) @_cmd - (#any-of? @_cmd "nu" "$nu.current-exe") - flag: (_ - name: (_) @_flag - (#any-of? @_flag "c" "e" "commands" "execute")) - . - arg: (_ - (string_content) @injection.content - (#set! injection.language "nu"))) - -(command - head: (cmd_identifier) @_command (#any-of? @_command "jq" "jaq") - . - arg: (_ (string_content) @injection.content) - (#set! injection.language "jq") -) - -(command - head: (cmd_identifier) @_command (#eq? @_command "fish") - flag: (short_flag "-") @_flag (#match? @_flag "^-.*c$") - . - arg: (_ (string_content) @injection.content) - (#set! injection.language "fish") -) diff --git a/runtime/queries/nu/textobjects.scm b/runtime/queries/nu/textobjects.scm deleted file mode 100644 index 4b87084bbe2e..000000000000 --- a/runtime/queries/nu/textobjects.scm +++ /dev/null @@ -1,78 +0,0 @@ -(stmt_let) @assignment.outer - -(stmt_mut) @assignment.outer - -(stmt_const) @assignment.outer - -(stmt_let - value: (_) @assignment.inner) - -(stmt_mut - value: (_) @assignment.inner) - -(stmt_const - value: (_) @assignment.inner) - -(block) @block.outer - -(comment) @comment.outer - -(pipeline) @pipeline.outer - -(pipe_element) @pipeline.inner - -(decl_def) @function.outer - -(decl_def - body: (_) @function.inner) - -(ctrl_for) @loop.outer - -(ctrl_loop) @loop.outer - -(ctrl_while) @loop.outer - -(ctrl_for - body: (_) @loop.inner) - -(ctrl_loop - body: (_) @loop.inner) - -(ctrl_while - body: (_) @loop.inner) - -; Conditional inner counts the last one, rather than the current one. -(ctrl_if - then_branch: (_) @conditional.inner - else_block: (_)? @conditional.inner) @conditional.outer - -(parameter) @parameter.outer - -(command - head: (_) @call.inner) @call.outer - -(where_command - predicate: (_) @call.inner) @call.outer - -; define pipeline first, because it should only match as a fallback -; e.g., `let a = date now` should match the whole assignment. -; But a standalone `date now` should also match a statement -(pipeline) @statement.outer - -(stmt_let) @statement.outer - -(stmt_mut) @statement.outer - -(stmt_const) @statement.outer - -(ctrl_if) @statement.outer - -(ctrl_try) @statement.outer - -(ctrl_match) @statement.outer - -(ctrl_while) @statement.outer - -(ctrl_loop) @statement.outer - -(val_number) @number.inner From ea36041bf621fd3e1d39d5a86a3a1714de7b4723 Mon Sep 17 00:00:00 2001 From: Axlefublr <101342105+Axlefublr@users.noreply.github.com> Date: Sun, 7 Sep 2025 18:54:03 +0800 Subject: [PATCH 06/19] bring back folds --- runtime/queries/nu/folds.scm | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 runtime/queries/nu/folds.scm diff --git a/runtime/queries/nu/folds.scm b/runtime/queries/nu/folds.scm new file mode 100644 index 000000000000..53607745aa60 --- /dev/null +++ b/runtime/queries/nu/folds.scm @@ -0,0 +1,10 @@ +[ + (attribute_list) + (block) + (command_list) + (parameter_bracks) + (record_body) + (val_list) + (val_table) + (val_closure) +] @fold From 525c5e764735b78b2e4e3e66ac3261f0a6ac1c4d Mon Sep 17 00:00:00 2001 From: Axlefublr <101342105+Axlefublr@users.noreply.github.com> Date: Sun, 7 Sep 2025 19:07:09 +0800 Subject: [PATCH 07/19] bring back highlights --- book/src/generated/lang-support.md | 2 +- runtime/queries/nu/highlights.scm | 416 +++++++++++++++++++++++++++++ 2 files changed, 417 insertions(+), 1 deletion(-) create mode 100644 runtime/queries/nu/highlights.scm diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index 2170f8ae5e14..c114faa13d82 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -175,7 +175,7 @@ | nickel | ✓ | | ✓ | | | `nls` | | nim | ✓ | ✓ | ✓ | | | `nimlangserver` | | nix | ✓ | ✓ | ✓ | | ✓ | `nil`, `nixd` | -| nu | | | | | | `nu` | +| nu | ✓ | | | | | `nu` | | nunjucks | ✓ | | | | | | | ocaml | ✓ | | ✓ | | | `ocamllsp` | | ocaml-interface | ✓ | | | | | `ocamllsp` | diff --git a/runtime/queries/nu/highlights.scm b/runtime/queries/nu/highlights.scm new file mode 100644 index 000000000000..df44bfab2287 --- /dev/null +++ b/runtime/queries/nu/highlights.scm @@ -0,0 +1,416 @@ +; --- +; keywords +[ + "let" + "mut" + "const" +] @keyword + +[ + "if" + "else" + "match" +] @keyword.conditional + +[ + "loop" + "while" +] @keyword.repeat + +"def" @keyword.function + +[ + "try" + "catch" + "error" +] @keyword.exception + +[ + "module" + "use" +] @keyword.import + +[ + "alias" + "export-env" + "export" + "extern" +] @keyword.modifier + +(decl_use + "use" @keyword) + +(ctrl_for + "for" @keyword + "in" @keyword) + +; --- +; literals +(val_number) @number + +(val_duration + unit: _ @variable.parameter) + +(val_filesize + unit: _ @variable.parameter) + +(val_binary + [ + "0b" + "0o" + "0x" + ] @number + "[" @punctuation.bracket + digit: [ + "," @punctuation.delimiter + (hex_digit) @number + ] + "]" @punctuation.bracket) @number + +(val_bool) @constant.builtin + +(val_nothing) @constant.builtin + +(val_string) @string + +arg_str: (val_string) @variable.parameter + +file_path: (val_string) @variable.parameter + +(val_date) @number + +(inter_escape_sequence) @constant.character.escape + +(escape_sequence) @constant.character.escape + +(val_interpolated + [ + "$\"" + "$\'" + "\"" + "\'" + ] @string) + +(unescaped_interpolated_content) @string + +(escaped_interpolated_content) @string + +(expr_interpolated + [ + "(" + ")" + ] @variable.parameter) + +(raw_string_begin) @punctuation.special + +(raw_string_end) @punctuation.special + +; --- +; operators +(expr_binary + opr: _ @operator) + +(where_predicate + opr: _ @operator) + +(assignment + [ + "=" + "+=" + "-=" + "*=" + "/=" + "++=" + ] @operator) + +(expr_unary + [ + "not" + "-" + ] @operator) + +(val_range + [ + ".." + "..=" + "..<" + ] @operator) + +[ + "=>" + "=" + "|" +] @operator + +[ + "o>" + "out>" + "e>" + "err>" + "e+o>" + "err+out>" + "o+e>" + "out+err>" + "o>>" + "out>>" + "e>>" + "err>>" + "e+o>>" + "err+out>>" + "o+e>>" + "out+err>>" + "e>|" + "err>|" + "e+o>|" + "err+out>|" + "o+e>|" + "out+err>|" +] @operator + +; --- +; punctuation +[ + "," + ";" +] @punctuation.special + +(param_long_flag + "--" @punctuation.delimiter) + +(long_flag + "--" @punctuation.delimiter) + +(short_flag + "-" @punctuation.delimiter) + +(long_flag + "=" @punctuation.special) + +(short_flag + "=" @punctuation.special) + +(param_short_flag + "-" @punctuation.delimiter) + +(param_rest + "..." @punctuation.delimiter) + +(param_type + ":" @punctuation.special) + +(param_value + "=" @punctuation.special) + +(param_cmd + "@" @punctuation.special) + +(attribute + "@" @punctuation.special) + +(param_opt + "?" @punctuation.special) + +(returns + "->" @punctuation.special) + +[ + "(" + ")" + "{" + "}" + "[" + "]" + "...[" + "...(" + "...{" +] @punctuation.bracket + +(val_record + (record_entry + ":" @punctuation.delimiter)) + +key: (identifier) @property + +; --- +; identifiers +(param_rest + name: (_) @variable.parameter) + +(param_opt + name: (_) @variable.parameter) + +(parameter + param_name: (_) @variable.parameter) + +(param_cmd + (cmd_identifier) @string) + +(param_long_flag + (long_flag_identifier) @attribute) + +(param_short_flag + (param_short_flag_identifier) @attribute) + +(attribute + (attribute_identifier) @attribute) + +(short_flag + (short_flag_identifier) @attribute) + +(long_flag_identifier) @attribute + +(scope_pattern + (wild_card) @function) + +(cmd_identifier) @function + +; generated with Nu 0.93.0 +; > help commands +; | filter { $in.command_type == builtin and $in.category != core } +; | each {$'"($in.name | split row " " | $in.0)"'} +; | uniq +; | str join ' ' +(command + head: (cmd_identifier) @function.builtin + (#any-of? @function.builtin + "all" "ansi" "any" "append" "ast" "bits" "bytes" "cal" "cd" "char" "clear" "collect" "columns" + "compact" "complete" "config" "cp" "date" "debug" "decode" "default" "detect" "dfr" "drop" "du" + "each" "encode" "enumerate" "every" "exec" "exit" "explain" "explore" "export-env" "fill" + "filter" "find" "first" "flatten" "fmt" "format" "from" "generate" "get" "glob" "grid" "group" + "group-by" "hash" "headers" "histogram" "history" "http" "input" "insert" "inspect" "interleave" + "into" "is-empty" "is-not-empty" "is-terminal" "items" "join" "keybindings" "kill" "last" + "length" "let-env" "lines" "load-env" "ls" "math" "merge" "metadata" "mkdir" "mktemp" "move" + "mv" "nu-check" "nu-highlight" "open" "panic" "par-each" "parse" "path" "plugin" "port" + "prepend" "print" "ps" "query" "random" "range" "reduce" "reject" "rename" "reverse" "rm" "roll" + "rotate" "run-external" "save" "schema" "select" "seq" "shuffle" "skip" "sleep" "sort" "sort-by" + "split" "split-by" "start" "stor" "str" "sys" "table" "take" "tee" "term" "timeit" "to" "touch" + "transpose" "tutor" "ulimit" "uname" "uniq" "uniq-by" "update" "upsert" "url" "values" "view" + "watch" "where" "which" "whoami" "window" "with-env" "wrap" "zip")) + +(command + head: (cmd_identifier) @keyword.repeat + (#any-of? @keyword.repeat "break" "continue" "return")) + +(command + head: (cmd_identifier) @keyword + (#any-of? @keyword "do" "source" "source-env" "hide" "hide-env")) + +(command + head: (cmd_identifier) @keyword + . + arg_str: (val_string) @keyword.import + (#any-of? @keyword "overlay" "error")) + +(command + head: (cmd_identifier) @cmd + arg_str: (val_string) @keyword + (#eq? @cmd "overlay") + (#eq? @keyword "as")) + +(command + "^" @punctuation.delimiter + head: (_) @function) + +"where" @function.builtin + +(where_predicate + [ + "?" + "!" + ] @punctuation.delimiter) + +(path + [ + "." + "?" + "!" + ]? @punctuation.delimiter) @variable.parameter + +(stmt_let + (identifier) @variable) + +(val_variable + "$"? @punctuation.special + "...$"? @punctuation.special + [ + (identifier) @variable + "in" @special + "nu" @namespace + "env" @constant + ]) @none + +(val_cellpath + "$" @punctuation.special) + +(record_entry + ":" @punctuation.special) + +; --- +; types +(flat_type) @type + +(list_type + "list" @type.enum + [ + "<" + ">" + ] @punctuation.bracket) + +(collection_type + [ + "record" + "table" + ] @type.enum + "<" @punctuation.bracket + key: (_) @variable.parameter + [ + "," + ":" + ] @punctuation.special + ">" @punctuation.bracket) + +(composite_type + "oneof" @type.enum + [ + "<" + ">" + ] @punctuation.bracket) + +[(comment) (shebang)] @comment + +((comment)+ @comment.documentation + . + (decl_def)) + +(parameter + (comment) @comment.documentation) + +(command + head: ((cmd_identifier) @_cmd + (#match? @_cmd "^\\s*(find|parse|split|str)$")) + flag: (_ + name: (_) @_flag + (#any-of? @_flag "r" "regex")) + . + arg: (_ + (string_content) @string.regexp)) + +(_ + opr: [ + "=~" + "!~" + "like" + "not-like" + ] + rhs: (_ + (string_content) @string.regexp)) + +(command + head: ((_) @_cmd + (#any-of? @_cmd "nu" "$nu.current-exe")) + flag: (_ + name: (_) @_flag + (#any-of? @_flag "c" "e" "commands" "execute")) + . + arg: (_ + (string_content) @string.code)) From 769b177d98d5bd72ba9d7c99992f7eaff8f55535 Mon Sep 17 00:00:00 2001 From: Axlefublr <101342105+Axlefublr@users.noreply.github.com> Date: Sun, 7 Sep 2025 19:19:53 +0800 Subject: [PATCH 08/19] bring back indents --- book/src/generated/lang-support.md | 2 +- runtime/queries/nu/indents.scm | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 runtime/queries/nu/indents.scm diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index c114faa13d82..864a83490237 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -175,7 +175,7 @@ | nickel | ✓ | | ✓ | | | `nls` | | nim | ✓ | ✓ | ✓ | | | `nimlangserver` | | nix | ✓ | ✓ | ✓ | | ✓ | `nil`, `nixd` | -| nu | ✓ | | | | | `nu` | +| nu | ✓ | | ✓ | | | `nu` | | nunjucks | ✓ | | | | | | | ocaml | ✓ | | ✓ | | | `ocamllsp` | | ocaml-interface | ✓ | | | | | `ocamllsp` | diff --git a/runtime/queries/nu/indents.scm b/runtime/queries/nu/indents.scm new file mode 100644 index 000000000000..e711f7e46c1e --- /dev/null +++ b/runtime/queries/nu/indents.scm @@ -0,0 +1,26 @@ +[ + (expr_parenthesized) + (parameter_bracks) + (ctrl_match) + + (val_record) + (val_list) + (val_closure) + (val_table) + + (block) +] @indent.begin + +[ + "}" + "]" + ")" +] @indent.end + +[ + "}" + "]" + ")" +] @indent.branch + +(comment) @indent.auto From b107050d777d46b11a44510a2495bac1b37677f3 Mon Sep 17 00:00:00 2001 From: Axlefublr <101342105+Axlefublr@users.noreply.github.com> Date: Sun, 7 Sep 2025 19:22:43 +0800 Subject: [PATCH 09/19] ci From 995fcf556f0b7423e51aa96d776504034526d5dc Mon Sep 17 00:00:00 2001 From: Axlefublr <101342105+Axlefublr@users.noreply.github.com> Date: Sun, 7 Sep 2025 19:38:17 +0800 Subject: [PATCH 10/19] bring back text objects --- book/src/generated/lang-support.md | 2 +- runtime/queries/nu/textobjects.scm | 78 ++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 runtime/queries/nu/textobjects.scm diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index 864a83490237..17f6149d0f8b 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -175,7 +175,7 @@ | nickel | ✓ | | ✓ | | | `nls` | | nim | ✓ | ✓ | ✓ | | | `nimlangserver` | | nix | ✓ | ✓ | ✓ | | ✓ | `nil`, `nixd` | -| nu | ✓ | | ✓ | | | `nu` | +| nu | ✓ | ✓ | ✓ | | | `nu` | | nunjucks | ✓ | | | | | | | ocaml | ✓ | | ✓ | | | `ocamllsp` | | ocaml-interface | ✓ | | | | | `ocamllsp` | diff --git a/runtime/queries/nu/textobjects.scm b/runtime/queries/nu/textobjects.scm new file mode 100644 index 000000000000..4b87084bbe2e --- /dev/null +++ b/runtime/queries/nu/textobjects.scm @@ -0,0 +1,78 @@ +(stmt_let) @assignment.outer + +(stmt_mut) @assignment.outer + +(stmt_const) @assignment.outer + +(stmt_let + value: (_) @assignment.inner) + +(stmt_mut + value: (_) @assignment.inner) + +(stmt_const + value: (_) @assignment.inner) + +(block) @block.outer + +(comment) @comment.outer + +(pipeline) @pipeline.outer + +(pipe_element) @pipeline.inner + +(decl_def) @function.outer + +(decl_def + body: (_) @function.inner) + +(ctrl_for) @loop.outer + +(ctrl_loop) @loop.outer + +(ctrl_while) @loop.outer + +(ctrl_for + body: (_) @loop.inner) + +(ctrl_loop + body: (_) @loop.inner) + +(ctrl_while + body: (_) @loop.inner) + +; Conditional inner counts the last one, rather than the current one. +(ctrl_if + then_branch: (_) @conditional.inner + else_block: (_)? @conditional.inner) @conditional.outer + +(parameter) @parameter.outer + +(command + head: (_) @call.inner) @call.outer + +(where_command + predicate: (_) @call.inner) @call.outer + +; define pipeline first, because it should only match as a fallback +; e.g., `let a = date now` should match the whole assignment. +; But a standalone `date now` should also match a statement +(pipeline) @statement.outer + +(stmt_let) @statement.outer + +(stmt_mut) @statement.outer + +(stmt_const) @statement.outer + +(ctrl_if) @statement.outer + +(ctrl_try) @statement.outer + +(ctrl_match) @statement.outer + +(ctrl_while) @statement.outer + +(ctrl_loop) @statement.outer + +(val_number) @number.inner From ca54d01df2eddc89a65e49d591d4636770063f70 Mon Sep 17 00:00:00 2001 From: Axlefublr <101342105+Axlefublr@users.noreply.github.com> Date: Sun, 7 Sep 2025 19:54:24 +0800 Subject: [PATCH 11/19] bring back injections --- runtime/queries/nu/injections.scm | 50 +++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 runtime/queries/nu/injections.scm diff --git a/runtime/queries/nu/injections.scm b/runtime/queries/nu/injections.scm new file mode 100644 index 000000000000..8005ffdc64bc --- /dev/null +++ b/runtime/queries/nu/injections.scm @@ -0,0 +1,50 @@ +((comment) @injection.content + (#set! injection.language "comment")) + +(command + head: ((cmd_identifier) @_cmd + (#match? @_cmd "^\\s*(find|parse|split|str)$")) + flag: (_ + name: (_) @_flag + (#any-of? @_flag "r" "regex")) + . + arg: (_ + (string_content) @injection.content + (#set! injection.language "regex"))) + +(_ + opr: [ + "=~" + "!~" + "like" + "not-like" + ] + rhs: (_ + (string_content) @injection.content + (#set! injection.language "regex"))) + +(command + head: (_) @_cmd + (#any-of? @_cmd "nu" "$nu.current-exe") + flag: (_ + name: (_) @_flag + (#any-of? @_flag "c" "e" "commands" "execute")) + . + arg: (_ + (string_content) @injection.content + (#set! injection.language "nu"))) + +(command + head: (cmd_identifier) @_command (#any-of? @_command "jq" "jaq") + . + arg: (_ (string_content) @injection.content) + (#set! injection.language "jq") +) + +(command + head: (cmd_identifier) @_command (#eq? @_command "fish") + flag: (short_flag "-") @_flag (#match? @_flag "^-.*c$") + . + arg: (_ (string_content) @injection.content) + (#set! injection.language "fish") +) From 2468c5e31ff88f40e2b12ccd40ca98d0c2f19ae8 Mon Sep 17 00:00:00 2001 From: Axlefublr <101342105+Axlefublr@users.noreply.github.com> Date: Mon, 8 Sep 2025 02:00:15 +0800 Subject: [PATCH 12/19] add missing `describe` function.builtin --- runtime/queries/nu/highlights.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/queries/nu/highlights.scm b/runtime/queries/nu/highlights.scm index df44bfab2287..9c23f6a7fb62 100644 --- a/runtime/queries/nu/highlights.scm +++ b/runtime/queries/nu/highlights.scm @@ -274,7 +274,7 @@ key: (identifier) @property head: (cmd_identifier) @function.builtin (#any-of? @function.builtin "all" "ansi" "any" "append" "ast" "bits" "bytes" "cal" "cd" "char" "clear" "collect" "columns" - "compact" "complete" "config" "cp" "date" "debug" "decode" "default" "detect" "dfr" "drop" "du" + "compact" "complete" "config" "cp" "date" "debug" "decode" "default" "describe" "detect" "dfr" "drop" "du" "each" "encode" "enumerate" "every" "exec" "exit" "explain" "explore" "export-env" "fill" "filter" "find" "first" "flatten" "fmt" "format" "from" "generate" "get" "glob" "grid" "group" "group-by" "hash" "headers" "histogram" "history" "http" "input" "insert" "inspect" "interleave" From ef1c55d79426a1be23e9431eb17ef1cbd6c43aaf Mon Sep 17 00:00:00 2001 From: Axlefublr <101342105+Axlefublr@users.noreply.github.com> Date: Mon, 8 Sep 2025 22:49:18 +0800 Subject: [PATCH 13/19] stringed function names are still colored as `@function` --- runtime/queries/nu/highlights.scm | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/runtime/queries/nu/highlights.scm b/runtime/queries/nu/highlights.scm index 9c23f6a7fb62..cb396b57b8b5 100644 --- a/runtime/queries/nu/highlights.scm +++ b/runtime/queries/nu/highlights.scm @@ -264,6 +264,12 @@ key: (identifier) @property (cmd_identifier) @function +(decl_def . "def" + (val_string + (string_content) @function + ) +) + ; generated with Nu 0.93.0 ; > help commands ; | filter { $in.command_type == builtin and $in.category != core } From 6db8b2085105fdd1ae64e20a0f71643b693b1f50 Mon Sep 17 00:00:00 2001 From: Axlefublr <101342105+Axlefublr@users.noreply.github.com> Date: Mon, 8 Sep 2025 23:42:15 +0800 Subject: [PATCH 14/19] regenerate list of builtins --- runtime/queries/nu/highlights.scm | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/runtime/queries/nu/highlights.scm b/runtime/queries/nu/highlights.scm index cb396b57b8b5..b88dea674783 100644 --- a/runtime/queries/nu/highlights.scm +++ b/runtime/queries/nu/highlights.scm @@ -270,28 +270,16 @@ key: (identifier) @property ) ) -; generated with Nu 0.93.0 -; > help commands -; | filter { $in.command_type == builtin and $in.category != core } -; | each {$'"($in.name | split row " " | $in.0)"'} -; | uniq -; | str join ' ' +; generated with Nu 0.107.0 +; help commands +; | where $it.command_type == built-in and $it.category != core +; | each {$'"($in.name | split row " " | $in.0)"'} +; | uniq +; | str join ' ' (command head: (cmd_identifier) @function.builtin (#any-of? @function.builtin - "all" "ansi" "any" "append" "ast" "bits" "bytes" "cal" "cd" "char" "clear" "collect" "columns" - "compact" "complete" "config" "cp" "date" "debug" "decode" "default" "describe" "detect" "dfr" "drop" "du" - "each" "encode" "enumerate" "every" "exec" "exit" "explain" "explore" "export-env" "fill" - "filter" "find" "first" "flatten" "fmt" "format" "from" "generate" "get" "glob" "grid" "group" - "group-by" "hash" "headers" "histogram" "history" "http" "input" "insert" "inspect" "interleave" - "into" "is-empty" "is-not-empty" "is-terminal" "items" "join" "keybindings" "kill" "last" - "length" "let-env" "lines" "load-env" "ls" "math" "merge" "metadata" "mkdir" "mktemp" "move" - "mv" "nu-check" "nu-highlight" "open" "panic" "par-each" "parse" "path" "plugin" "port" - "prepend" "print" "ps" "query" "random" "range" "reduce" "reject" "rename" "reverse" "rm" "roll" - "rotate" "run-external" "save" "schema" "select" "seq" "shuffle" "skip" "sleep" "sort" "sort-by" - "split" "split-by" "start" "stor" "str" "sys" "table" "take" "tee" "term" "timeit" "to" "touch" - "transpose" "tutor" "ulimit" "uname" "uniq" "uniq-by" "update" "upsert" "url" "values" "view" - "watch" "where" "which" "whoami" "window" "with-env" "wrap" "zip")) + "all" "ansi" "any" "append" "ast" "bits" "bytes" "cal" "cd" "char" "chunk-by" "chunks" "clear" "collect" "columns" "compact" "complete" "config" "cp" "date" "debug" "decode" "default" "detect" "drop" "du" "each" "encode" "enumerate" "every" "exec" "exit" "explain" "explore" "fill" "filter" "find" "first" "flatten" "format" "from" "generate" "get" "glob" "grid" "group-by" "hash" "headers" "histogram" "history" "http" "input" "insert" "inspect" "interleave" "into" "is-empty" "is-not-empty" "is-terminal" "items" "job" "join" "keybindings" "kill" "last" "length" "let-env" "lines" "load-env" "ls" "math" "merge" "metadata" "mkdir" "mktemp" "move" "mv" "nu-check" "nu-highlight" "open" "panic" "par-each" "parse" "path" "plugin" "port" "prepend" "print" "ps" "query" "random" "reduce" "reject" "rename" "reverse" "rm" "roll" "rotate" "run-external" "save" "schema" "select" "seq" "shuffle" "skip" "sleep" "slice" "sort" "sort-by" "split" "start" "stor" "str" "sys" "table" "take" "tee" "term" "timeit" "to" "touch" "transpose" "tutor" "ulimit" "uname" "uniq" "uniq-by" "update" "upsert" "url" "values" "version" "view" "watch" "which" "whoami" "window" "with-env" "wrap" "zip")) (command head: (cmd_identifier) @keyword.repeat From 5b4ea00057c92e8328f88cdf11ba570d1195c6cc Mon Sep 17 00:00:00 2001 From: Axlefublr <101342105+Axlefublr@users.noreply.github.com> Date: Fri, 12 Sep 2025 08:55:21 +0800 Subject: [PATCH 15/19] change runtime/queries/nu/highlights.scm --- runtime/queries/nu/highlights.scm | 34 +++++++++++++++---------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/runtime/queries/nu/highlights.scm b/runtime/queries/nu/highlights.scm index b88dea674783..f3279b5f6ac3 100644 --- a/runtime/queries/nu/highlights.scm +++ b/runtime/queries/nu/highlights.scm @@ -10,12 +10,12 @@ "if" "else" "match" -] @keyword.conditional +] @keyword.control.conditional [ "loop" "while" -] @keyword.repeat +] @keyword.control.repeat "def" @keyword.function @@ -23,30 +23,30 @@ "try" "catch" "error" -] @keyword.exception +] @keyword.control.exception [ "module" "use" -] @keyword.import +] @keyword.control.import [ "alias" "export-env" "export" "extern" -] @keyword.modifier +] @keyword.storage.modifier (decl_use - "use" @keyword) + "use" @keyword.control.import) (ctrl_for - "for" @keyword - "in" @keyword) + "for" @keyword.control.repeat + "in" @keyword.control.repeat) ; --- ; literals -(val_number) @number +(val_number) @constant.numeric (val_duration unit: _ @variable.parameter) @@ -59,15 +59,15 @@ "0b" "0o" "0x" - ] @number + ] @constant.numeric "[" @punctuation.bracket digit: [ "," @punctuation.delimiter - (hex_digit) @number + (hex_digit) @constant.numeric ] - "]" @punctuation.bracket) @number + "]" @punctuation.bracket) @constant.numeric -(val_bool) @constant.builtin +(val_bool) @constant.builtin.boolean (val_nothing) @constant.builtin @@ -77,7 +77,7 @@ arg_str: (val_string) @variable.parameter file_path: (val_string) @variable.parameter -(val_date) @number +(val_date) @constant.numeric (inter_escape_sequence) @constant.character.escape @@ -282,8 +282,8 @@ key: (identifier) @property "all" "ansi" "any" "append" "ast" "bits" "bytes" "cal" "cd" "char" "chunk-by" "chunks" "clear" "collect" "columns" "compact" "complete" "config" "cp" "date" "debug" "decode" "default" "detect" "drop" "du" "each" "encode" "enumerate" "every" "exec" "exit" "explain" "explore" "fill" "filter" "find" "first" "flatten" "format" "from" "generate" "get" "glob" "grid" "group-by" "hash" "headers" "histogram" "history" "http" "input" "insert" "inspect" "interleave" "into" "is-empty" "is-not-empty" "is-terminal" "items" "job" "join" "keybindings" "kill" "last" "length" "let-env" "lines" "load-env" "ls" "math" "merge" "metadata" "mkdir" "mktemp" "move" "mv" "nu-check" "nu-highlight" "open" "panic" "par-each" "parse" "path" "plugin" "port" "prepend" "print" "ps" "query" "random" "reduce" "reject" "rename" "reverse" "rm" "roll" "rotate" "run-external" "save" "schema" "select" "seq" "shuffle" "skip" "sleep" "slice" "sort" "sort-by" "split" "start" "stor" "str" "sys" "table" "take" "tee" "term" "timeit" "to" "touch" "transpose" "tutor" "ulimit" "uname" "uniq" "uniq-by" "update" "upsert" "url" "values" "version" "view" "watch" "which" "whoami" "window" "with-env" "wrap" "zip")) (command - head: (cmd_identifier) @keyword.repeat - (#any-of? @keyword.repeat "break" "continue" "return")) + head: (cmd_identifier) @keyword.control.repeat + (#any-of? @keyword.control.repeat "break" "continue" "return")) (command head: (cmd_identifier) @keyword @@ -292,7 +292,7 @@ key: (identifier) @property (command head: (cmd_identifier) @keyword . - arg_str: (val_string) @keyword.import + arg_str: (val_string) @keyword.control.import (#any-of? @keyword "overlay" "error")) (command From 71465805d69507904ec51449686224cd30f8ef2a Mon Sep 17 00:00:00 2001 From: Axlefublr <101342105+Axlefublr@users.noreply.github.com> Date: Fri, 12 Sep 2025 08:55:21 +0800 Subject: [PATCH 16/19] change runtime/queries/nu/indents.scm --- runtime/queries/nu/indents.scm | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/runtime/queries/nu/indents.scm b/runtime/queries/nu/indents.scm index e711f7e46c1e..5a1f109b7026 100644 --- a/runtime/queries/nu/indents.scm +++ b/runtime/queries/nu/indents.scm @@ -9,18 +9,10 @@ (val_table) (block) -] @indent.begin +] @indent [ "}" "]" ")" -] @indent.end - -[ - "}" - "]" - ")" -] @indent.branch - -(comment) @indent.auto +] @outdent From 9260c4f603dc6c1795896517b28afebe1dbbabc6 Mon Sep 17 00:00:00 2001 From: Axlefublr <101342105+Axlefublr@users.noreply.github.com> Date: Fri, 12 Sep 2025 08:55:21 +0800 Subject: [PATCH 17/19] change runtime/queries/nu/textobjects.scm --- runtime/queries/nu/textobjects.scm | 84 +++++++++++++++--------------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/runtime/queries/nu/textobjects.scm b/runtime/queries/nu/textobjects.scm index 4b87084bbe2e..ddf92ee2d364 100644 --- a/runtime/queries/nu/textobjects.scm +++ b/runtime/queries/nu/textobjects.scm @@ -1,78 +1,78 @@ -(stmt_let) @assignment.outer +; (stmt_let) @assignment.outer -(stmt_mut) @assignment.outer +; (stmt_mut) @assignment.outer -(stmt_const) @assignment.outer +; (stmt_const) @assignment.outer -(stmt_let - value: (_) @assignment.inner) +; (stmt_let +; value: (_) @assignment.inner) -(stmt_mut - value: (_) @assignment.inner) +; (stmt_mut +; value: (_) @assignment.inner) -(stmt_const - value: (_) @assignment.inner) +; (stmt_const +; value: (_) @assignment.inner) -(block) @block.outer +; (block) @block.outer -(comment) @comment.outer +(comment) @comment.around -(pipeline) @pipeline.outer +; (pipeline) @pipeline.outer -(pipe_element) @pipeline.inner +; (pipe_element) @pipeline.inner -(decl_def) @function.outer +(decl_def) @function.around (decl_def - body: (_) @function.inner) + body: (_) @function.inside) -(ctrl_for) @loop.outer +; (ctrl_for) @loop.outer -(ctrl_loop) @loop.outer +; (ctrl_loop) @loop.outer -(ctrl_while) @loop.outer +; (ctrl_while) @loop.outer -(ctrl_for - body: (_) @loop.inner) +; (ctrl_for +; body: (_) @loop.inner) -(ctrl_loop - body: (_) @loop.inner) +; (ctrl_loop +; body: (_) @loop.inner) -(ctrl_while - body: (_) @loop.inner) +; (ctrl_while +; body: (_) @loop.inner) ; Conditional inner counts the last one, rather than the current one. -(ctrl_if - then_branch: (_) @conditional.inner - else_block: (_)? @conditional.inner) @conditional.outer +; (ctrl_if +; then_branch: (_) @conditional.inner +; else_block: (_)? @conditional.inner) @conditional.outer -(parameter) @parameter.outer +(parameter) @parameter.around -(command - head: (_) @call.inner) @call.outer +; (command +; head: (_) @call.inner) @call.outer -(where_command - predicate: (_) @call.inner) @call.outer +; (where_command +; predicate: (_) @call.inner) @call.outer ; define pipeline first, because it should only match as a fallback ; e.g., `let a = date now` should match the whole assignment. ; But a standalone `date now` should also match a statement -(pipeline) @statement.outer +; (pipeline) @statement.outer -(stmt_let) @statement.outer +; (stmt_let) @statement.outer -(stmt_mut) @statement.outer +; (stmt_mut) @statement.outer -(stmt_const) @statement.outer +; (stmt_const) @statement.outer -(ctrl_if) @statement.outer +; (ctrl_if) @statement.outer -(ctrl_try) @statement.outer +; (ctrl_try) @statement.outer -(ctrl_match) @statement.outer +; (ctrl_match) @statement.outer -(ctrl_while) @statement.outer +; (ctrl_while) @statement.outer -(ctrl_loop) @statement.outer +; (ctrl_loop) @statement.outer -(val_number) @number.inner +; (val_number) @number.inner From 74326068f85838e312b522378c4e3a9a7fe79405 Mon Sep 17 00:00:00 2001 From: Axlefublr <101342105+Axlefublr@users.noreply.github.com> Date: Sun, 14 Sep 2025 15:49:40 +0800 Subject: [PATCH 18/19] don't lose highlighting when injecting regex --- runtime/queries/nu/highlights.scm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/runtime/queries/nu/highlights.scm b/runtime/queries/nu/highlights.scm index f3279b5f6ac3..559e1d995b28 100644 --- a/runtime/queries/nu/highlights.scm +++ b/runtime/queries/nu/highlights.scm @@ -380,11 +380,11 @@ key: (identifier) @property (comment) @comment.documentation) (command - head: ((cmd_identifier) @_cmd - (#match? @_cmd "^\\s*(find|parse|split|str)$")) + head: ((cmd_identifier) @function.builtin + (#match? @function.builtin "^\\s*(find|parse|split|str)$")) flag: (_ - name: (_) @_flag - (#any-of? @_flag "r" "regex")) + name: (_) @attribute + (#any-of? @attribute "r" "regex")) . arg: (_ (string_content) @string.regexp)) From bc5efe7366c105e105cffc4f2820ff20c8980474 Mon Sep 17 00:00:00 2001 From: Axlefublr <101342105+Axlefublr@users.noreply.github.com> Date: Sun, 14 Sep 2025 15:51:56 +0800 Subject: [PATCH 19/19] or when injecting nu into nu --- runtime/queries/nu/highlights.scm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/runtime/queries/nu/highlights.scm b/runtime/queries/nu/highlights.scm index 559e1d995b28..27583f2fea55 100644 --- a/runtime/queries/nu/highlights.scm +++ b/runtime/queries/nu/highlights.scm @@ -400,11 +400,11 @@ key: (identifier) @property (string_content) @string.regexp)) (command - head: ((_) @_cmd - (#any-of? @_cmd "nu" "$nu.current-exe")) + head: ((_) @function + (#any-of? @function "nu" "$nu.current-exe")) flag: (_ - name: (_) @_flag - (#any-of? @_flag "c" "e" "commands" "execute")) + name: (_) @attribute + (#any-of? @attribute "c" "e" "commands" "execute")) . arg: (_ (string_content) @string.code))