From 2b7d0a125fb37f2abe8b8fa3e521f3415f42f54b Mon Sep 17 00:00:00 2001 From: hustcer Date: Fri, 22 Apr 2022 20:18:45 +0800 Subject: [PATCH] feat(lang): add nushell language support --- 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 ++++++++ 5 files changed, 86 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/languages.toml b/languages.toml index 76b4ca167e924..6b9388d885ea2 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 0000000000000..f6b5acb158352 --- /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 0000000000000..909dddb559558 --- /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 0000000000000..4bb7d675dfacd --- /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 0000000000000..2a341f80ea95f --- /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