From 527b47058417c9aa9d64bafd164f4ab490e64e99 Mon Sep 17 00:00:00 2001 From: hustcer Date: Fri, 22 Apr 2022 21:56:34 +0800 Subject: [PATCH 1/6] feat(lang): add nushell language support --- book/src/generated/lang-support.md | 1 + languages.toml | 13 +++++++ runtime/queries/nu/folds.scm | 4 +++ runtime/queries/nu/highlights.scm | 55 ++++++++++++++++++++++++++++++ runtime/queries/nu/injections.scm | 1 + runtime/queries/nu/locals.scm | 13 +++++++ 6 files changed, 87 insertions(+) create mode 100644 runtime/queries/nu/folds.scm create mode 100644 runtime/queries/nu/highlights.scm create mode 100644 runtime/queries/nu/injections.scm create mode 100644 runtime/queries/nu/locals.scm diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index ef3c94513984..7292b61bae3f 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -50,6 +50,7 @@ | mint | | | | `mint` | | nickel | ✓ | | ✓ | `nls` | | nix | ✓ | | ✓ | `rnix-lsp` | +| nu | ✓ | | | | | ocaml | ✓ | | ✓ | `ocamllsp` | | ocaml-interface | ✓ | | | `ocamllsp` | | org | ✓ | | | | diff --git a/languages.toml b/languages.toml index 76b4ca167e92..6b9388d885ea 100644 --- a/languages.toml +++ b/languages.toml @@ -1210,3 +1210,16 @@ indent = { tab-width = 4, unit = " " } [[grammar]] name = "gdscript" source = { git = "https://github.com/PrestonKnopp/tree-sitter-gdscript", rev = "2a6abdaa47fcb91397e09a97c7433fd995ea46c6" } + +[[language]] +name = "nu" +scope = "source.nu" +injection-regex = "nu" +file-types = ["nu"] +roots = [] +comment-token = "#" +indent = { tab-width = 2, unit = " " } + +[[grammar]] +name = "nu" +source = { git = "https://github.com/LhKipp/tree-sitter-nu.git", rev = "db4e990b78824c8abef3618e0f93b7fe1e8f4c0d" } diff --git a/runtime/queries/nu/folds.scm b/runtime/queries/nu/folds.scm new file mode 100644 index 000000000000..f6b5acb15835 --- /dev/null +++ b/runtime/queries/nu/folds.scm @@ -0,0 +1,4 @@ +[ + (function_definition) + (block) +] @fold diff --git a/runtime/queries/nu/highlights.scm b/runtime/queries/nu/highlights.scm new file mode 100644 index 000000000000..909dddb55955 --- /dev/null +++ b/runtime/queries/nu/highlights.scm @@ -0,0 +1,55 @@ +(string) @string +(type) @type +(value_path) @variable +(comment) @comment + +(number_literal) @number +(range from: (number_literal) @number) +(range to: (number_literal) @number) + +(command cmd_name: (identifier) @function) +(function_definition func_name: (identifier) @function) + +[ + (variable_declaration name: (identifier)) + (parameter (identifier)) + (flag (flag_name)) + (flag (flag_shorthand_name)) + (record_entry entry_name: (identifier)) + (block_args block_param: (identifier)) +] @property +; (parameter (identifier) @variable.parameter) ; -- alternative highlighting group? + +(cmd_invocation) @embedded + + +((identifier) @constant + (#match? @constant "^[A-Z][A-Z\\d_]*$")) + +[ + "if" + "else" + "let" + "def" + "export" +] @keyword + +[ + ; "/" Not making / an operator may lead to better highlighting? + "$" + "|" + "+" + "-" + "*" + "=" + "!=" + "&&" + "||" + "==" + ">" +] @operator + +["." + "," + ";" +] @delimiter diff --git a/runtime/queries/nu/injections.scm b/runtime/queries/nu/injections.scm new file mode 100644 index 000000000000..4bb7d675dfac --- /dev/null +++ b/runtime/queries/nu/injections.scm @@ -0,0 +1 @@ +(comment) @comment diff --git a/runtime/queries/nu/locals.scm b/runtime/queries/nu/locals.scm new file mode 100644 index 000000000000..2a341f80ea95 --- /dev/null +++ b/runtime/queries/nu/locals.scm @@ -0,0 +1,13 @@ +; Scopes +(function_definition) @scope + +; Definitions +(variable_declaration + name: (identifier) @definition.var) + +(function_definition + func_name: (identifier) @definition.function) + +; References +(value_path) @reference +(word) @reference From 20e1bc5d57573fb8179dbf8b05b50aca1ad634db Mon Sep 17 00:00:00 2001 From: Justin Ma Date: Fri, 22 Apr 2022 22:04:34 +0800 Subject: [PATCH 2/6] Update languages.toml Co-authored-by: Michael Davis --- languages.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/languages.toml b/languages.toml index 6b9388d885ea..3b2eedf2c37d 100644 --- a/languages.toml +++ b/languages.toml @@ -1222,4 +1222,4 @@ indent = { tab-width = 2, unit = " " } [[grammar]] name = "nu" -source = { git = "https://github.com/LhKipp/tree-sitter-nu.git", rev = "db4e990b78824c8abef3618e0f93b7fe1e8f4c0d" } +source = { git = "https://github.com/LhKipp/tree-sitter-nu", rev = "db4e990b78824c8abef3618e0f93b7fe1e8f4c0d" } From e2bb07b9844faa1b7068c90bf501b9c232c30560 Mon Sep 17 00:00:00 2001 From: Justin Ma Date: Fri, 22 Apr 2022 22:04:43 +0800 Subject: [PATCH 3/6] Update runtime/queries/nu/highlights.scm Co-authored-by: Michael Davis --- runtime/queries/nu/highlights.scm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/runtime/queries/nu/highlights.scm b/runtime/queries/nu/highlights.scm index 909dddb55955..ff2adeeb01b8 100644 --- a/runtime/queries/nu/highlights.scm +++ b/runtime/queries/nu/highlights.scm @@ -3,9 +3,9 @@ (value_path) @variable (comment) @comment -(number_literal) @number -(range from: (number_literal) @number) -(range to: (number_literal) @number) +(number_literal) @constant.numeric +(range from: (number_literal) @constant.numeric) +(range to: (number_literal) @constant.numeric) (command cmd_name: (identifier) @function) (function_definition func_name: (identifier) @function) From c63622b0516fe627019c2230c1c3074d6352c5a9 Mon Sep 17 00:00:00 2001 From: hustcer Date: Fri, 22 Apr 2022 22:08:05 +0800 Subject: [PATCH 4/6] [ci skip] --- runtime/queries/nu/injections.scm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/runtime/queries/nu/injections.scm b/runtime/queries/nu/injections.scm index 4bb7d675dfac..321c90add371 100644 --- a/runtime/queries/nu/injections.scm +++ b/runtime/queries/nu/injections.scm @@ -1 +1,2 @@ -(comment) @comment +((comment) @injection.content + (#set! injection.language "comment")) From 466d31f16c239eb709542a219147f977aed65688 Mon Sep 17 00:00:00 2001 From: Justin Ma Date: Fri, 22 Apr 2022 22:27:01 +0800 Subject: [PATCH 5/6] Update runtime/queries/nu/highlights.scm Co-authored-by: Michael Davis --- 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 ff2adeeb01b8..4e8c373611da 100644 --- a/runtime/queries/nu/highlights.scm +++ b/runtime/queries/nu/highlights.scm @@ -17,7 +17,7 @@ (flag (flag_shorthand_name)) (record_entry entry_name: (identifier)) (block_args block_param: (identifier)) -] @property +] @variable.other.member ; (parameter (identifier) @variable.parameter) ; -- alternative highlighting group? (cmd_invocation) @embedded From fa0457c9cbac059f61ec90e923b7a6e84d4944b9 Mon Sep 17 00:00:00 2001 From: Justin Ma Date: Fri, 22 Apr 2022 22:30:20 +0800 Subject: [PATCH 6/6] Update runtime/queries/nu/highlights.scm Co-authored-by: Michael Davis --- 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 4e8c373611da..b643a63afcbb 100644 --- a/runtime/queries/nu/highlights.scm +++ b/runtime/queries/nu/highlights.scm @@ -52,4 +52,4 @@ ["." "," ";" -] @delimiter +] @punctuation.delimiter