From ef03e206d625063c68954ca6717fa22f0fe7e3e2 Mon Sep 17 00:00:00 2001 From: Mikayla Date: Tue, 5 Sep 2023 11:01:55 -0700 Subject: [PATCH 1/2] WIP: Add nushell support --- Cargo.lock | 10 +++ Cargo.toml | 1 + .../LiveKitBridge/Package.resolved | 4 +- crates/zed/Cargo.toml | 1 + crates/zed/src/languages.rs | 1 + crates/zed/src/languages/nushell.rs | 0 crates/zed/src/languages/nushell/config.toml | 9 +++ .../zed/src/languages/nushell/highlights.scm | 61 +++++++++++++++++++ 8 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 crates/zed/src/languages/nushell.rs create mode 100644 crates/zed/src/languages/nushell/config.toml create mode 100644 crates/zed/src/languages/nushell/highlights.scm diff --git a/Cargo.lock b/Cargo.lock index d4b7beba7bd35541a5dd53c450f21fdae25880e2..4bbe29742c2449585b6b94774d940f6b3d7dc70b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8406,6 +8406,15 @@ dependencies = [ "tree-sitter", ] +[[package]] +name = "tree-sitter-nu" +version = "0.0.1" +source = "git+https://github.com/mikayla-maki/tree-sitter-nu/?rev=6cf9ee39ceb3da79501de7646b10e5e1da800ab8#6cf9ee39ceb3da79501de7646b10e5e1da800ab8" +dependencies = [ + "cc", + "tree-sitter", +] + [[package]] name = "tree-sitter-php" version = "0.19.1" @@ -9868,6 +9877,7 @@ dependencies = [ "tree-sitter-lua", "tree-sitter-markdown", "tree-sitter-nix", + "tree-sitter-nu", "tree-sitter-php", "tree-sitter-python", "tree-sitter-racket", diff --git a/Cargo.toml b/Cargo.toml index 5938ecb40240765844c1849662b082afeae07a3a..01f42c306219883950fa156121c073e384b48d82 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -141,6 +141,7 @@ tree-sitter-racket = { git = "https://github.com/zed-industries/tree-sitter-rack tree-sitter-yaml = { git = "https://github.com/zed-industries/tree-sitter-yaml", rev = "f545a41f57502e1b5ddf2a6668896c1b0620f930"} tree-sitter-lua = "0.0.14" tree-sitter-nix = { git = "https://github.com/nix-community/tree-sitter-nix", rev = "66e3e9ce9180ae08fc57372061006ef83f0abde7" } +tree-sitter-nu = { git = "https://github.com/mikayla-maki/tree-sitter-nu/", rev = "6cf9ee39ceb3da79501de7646b10e5e1da800ab8"} [patch.crates-io] tree-sitter = { git = "https://github.com/tree-sitter/tree-sitter", rev = "35a6052fbcafc5e5fc0f9415b8652be7dcaf7222" } diff --git a/crates/live_kit_client/LiveKitBridge/Package.resolved b/crates/live_kit_client/LiveKitBridge/Package.resolved index 85ae0885652d9054356ca19b9be6d5fd8642d16d..b925bc8f0d5ef290993fa0d49adcf221dd3570f6 100644 --- a/crates/live_kit_client/LiveKitBridge/Package.resolved +++ b/crates/live_kit_client/LiveKitBridge/Package.resolved @@ -42,8 +42,8 @@ "repositoryURL": "https://github.com/apple/swift-protobuf.git", "state": { "branch": null, - "revision": "0af9125c4eae12a4973fb66574c53a54962a9e1e", - "version": "1.21.0" + "revision": "ce20dc083ee485524b802669890291c0d8090170", + "version": "1.22.1" } } ] diff --git a/crates/zed/Cargo.toml b/crates/zed/Cargo.toml index e102a665191ee019531eac42d295d67965028e5c..1d014197e1e14262180763151c2649dd04158686 100644 --- a/crates/zed/Cargo.toml +++ b/crates/zed/Cargo.toml @@ -132,6 +132,7 @@ tree-sitter-racket.workspace = true tree-sitter-yaml.workspace = true tree-sitter-lua.workspace = true tree-sitter-nix.workspace = true +tree-sitter-nu.workspace = true url = "2.2" urlencoding = "2.1.2" diff --git a/crates/zed/src/languages.rs b/crates/zed/src/languages.rs index 3fbb5aa14f70bd0b295172104bdb607427367411..0b1fa750c084dd44a006cad258f4e7d11fc153f9 100644 --- a/crates/zed/src/languages.rs +++ b/crates/zed/src/languages.rs @@ -170,6 +170,7 @@ pub fn init(languages: Arc, node_runtime: Arc language("elm", tree_sitter_elm::language(), vec![]); language("glsl", tree_sitter_glsl::language(), vec![]); language("nix", tree_sitter_nix::language(), vec![]); + language("nu", tree_sitter_nu::language(), vec![]); } #[cfg(any(test, feature = "test-support"))] diff --git a/crates/zed/src/languages/nushell.rs b/crates/zed/src/languages/nushell.rs new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/crates/zed/src/languages/nushell/config.toml b/crates/zed/src/languages/nushell/config.toml new file mode 100644 index 0000000000000000000000000000000000000000..d382b0705aa32cf54624f4a38ad348e3a9502ad3 --- /dev/null +++ b/crates/zed/src/languages/nushell/config.toml @@ -0,0 +1,9 @@ +name = "Nu" +path_suffixes = ["nu"] +line_comment = "# " +autoclose_before = ";:.,=}])>` \n\t\"" +brackets = [ + { start = "{", end = "}", close = true, newline = true }, + { start = "[", end = "]", close = true, newline = true }, + { start = "(", end = ")", close = true, newline = true }, +] diff --git a/crates/zed/src/languages/nushell/highlights.scm b/crates/zed/src/languages/nushell/highlights.scm new file mode 100644 index 0000000000000000000000000000000000000000..b97ed9836e659a3822f845a188b103b6eca07895 --- /dev/null +++ b/crates/zed/src/languages/nushell/highlights.scm @@ -0,0 +1,61 @@ +(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" + "not" + "let" + "def" + "def-env" + "export" + "true" + "false" + "and" + "or" +] @keyword + +[ + ; "/" Not making / an operator may lead to better highlighting? + "$" + "|" + "+" + "-" + "*" + "=" + "!=" + "and" + "or" + "==" + ">" +] @operator + +["." + "," + ";" +] @delimiter From 2be34ef254f27ee22e3a5e586cc611db1732b629 Mon Sep 17 00:00:00 2001 From: Mikayla Date: Sat, 9 Sep 2023 14:44:52 -0700 Subject: [PATCH 2/2] Add syntax highlighting for nu scripts --- Cargo.lock | 2 +- Cargo.toml | 2 +- crates/zed/src/languages/nu/brackets.scm | 4 + .../src/languages/{nushell => nu}/config.toml | 0 crates/zed/src/languages/nu/highlights.scm | 302 ++++++++++++++++++ crates/zed/src/languages/nu/indents.scm | 3 + crates/zed/src/languages/nushell.rs | 0 .../zed/src/languages/nushell/highlights.scm | 61 ---- 8 files changed, 311 insertions(+), 63 deletions(-) create mode 100644 crates/zed/src/languages/nu/brackets.scm rename crates/zed/src/languages/{nushell => nu}/config.toml (100%) create mode 100644 crates/zed/src/languages/nu/highlights.scm create mode 100644 crates/zed/src/languages/nu/indents.scm delete mode 100644 crates/zed/src/languages/nushell.rs delete mode 100644 crates/zed/src/languages/nushell/highlights.scm diff --git a/Cargo.lock b/Cargo.lock index 4bbe29742c2449585b6b94774d940f6b3d7dc70b..d1cd868eaac92ed3456f00394e7337bc8ff88a0b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8409,7 +8409,7 @@ dependencies = [ [[package]] name = "tree-sitter-nu" version = "0.0.1" -source = "git+https://github.com/mikayla-maki/tree-sitter-nu/?rev=6cf9ee39ceb3da79501de7646b10e5e1da800ab8#6cf9ee39ceb3da79501de7646b10e5e1da800ab8" +source = "git+https://github.com/nushell/tree-sitter-nu?rev=786689b0562b9799ce53e824cb45a1a2a04dc673#786689b0562b9799ce53e824cb45a1a2a04dc673" dependencies = [ "cc", "tree-sitter", diff --git a/Cargo.toml b/Cargo.toml index 01f42c306219883950fa156121c073e384b48d82..c233c74b55816334347c88208624b294abd921f5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -141,7 +141,7 @@ tree-sitter-racket = { git = "https://github.com/zed-industries/tree-sitter-rack tree-sitter-yaml = { git = "https://github.com/zed-industries/tree-sitter-yaml", rev = "f545a41f57502e1b5ddf2a6668896c1b0620f930"} tree-sitter-lua = "0.0.14" tree-sitter-nix = { git = "https://github.com/nix-community/tree-sitter-nix", rev = "66e3e9ce9180ae08fc57372061006ef83f0abde7" } -tree-sitter-nu = { git = "https://github.com/mikayla-maki/tree-sitter-nu/", rev = "6cf9ee39ceb3da79501de7646b10e5e1da800ab8"} +tree-sitter-nu = { git = "https://github.com/nushell/tree-sitter-nu", rev = "786689b0562b9799ce53e824cb45a1a2a04dc673"} [patch.crates-io] tree-sitter = { git = "https://github.com/tree-sitter/tree-sitter", rev = "35a6052fbcafc5e5fc0f9415b8652be7dcaf7222" } diff --git a/crates/zed/src/languages/nu/brackets.scm b/crates/zed/src/languages/nu/brackets.scm new file mode 100644 index 0000000000000000000000000000000000000000..7ede7a61926f47e75000b99b8b1436b057fe8346 --- /dev/null +++ b/crates/zed/src/languages/nu/brackets.scm @@ -0,0 +1,4 @@ +("(" @open ")" @close) +("[" @open "]" @close) +("{" @open "}" @close) +(parameter_pipes "|" @open "|" @close) diff --git a/crates/zed/src/languages/nushell/config.toml b/crates/zed/src/languages/nu/config.toml similarity index 100% rename from crates/zed/src/languages/nushell/config.toml rename to crates/zed/src/languages/nu/config.toml diff --git a/crates/zed/src/languages/nu/highlights.scm b/crates/zed/src/languages/nu/highlights.scm new file mode 100644 index 0000000000000000000000000000000000000000..97f46d3879c28ab77cc6b641abf7bd4260836a4a --- /dev/null +++ b/crates/zed/src/languages/nu/highlights.scm @@ -0,0 +1,302 @@ +;;; --- +;;; keywords +[ + "def" + "def-env" + "alias" + "export-env" + "export" + "extern" + "module" + + "let" + "let-env" + "mut" + "const" + + "hide-env" + + "source" + "source-env" + + "overlay" + "register" + + "loop" + "while" + "error" + + "do" + "if" + "else" + "try" + "catch" + "match" + + "break" + "continue" + "return" + +] @keyword + +(hide_mod "hide" @keyword) +(decl_use "use" @keyword) + +(ctrl_for + "for" @keyword + "in" @keyword +) +(overlay_list "list" @keyword) +(overlay_hide "hide" @keyword) +(overlay_new "new" @keyword) +(overlay_use + "use" @keyword + "as" @keyword +) +(ctrl_error "make" @keyword) + +;;; --- +;;; literals +(val_number) @constant +(val_duration + unit: [ + "ns" "µs" "us" "ms" "sec" "min" "hr" "day" "wk" + ] @variable +) +(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" + "zb" "zB" "Zb" "ZB" + + "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" + "zib" "ziB" "zIB" "zIb" "Zib" "ZIb" "ZIB" + ] @variable +) +(val_binary + [ + "0b" + "0o" + "0x" + ] @constant + "[" @punctuation.bracket + digit: [ + "," @punctuation.delimiter + (hex_digit) @constant + ] + "]" @punctuation.bracket +) @constant +(val_bool) @constant.builtin +(val_nothing) @constant.builtin +(val_string) @string +(val_date) @constant +(inter_escape_sequence) @constant +(escape_sequence) @constant +(val_interpolated [ + "$\"" + "$\'" + "\"" + "\'" +] @string) +(unescaped_interpolated_content) @string +(escaped_interpolated_content) @string +(expr_interpolated ["(" ")"] @variable) + +;;; --- +;;; 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) + +(expr_binary opr: ([ + "and" + "or" + "xor" + "bit-or" + "bit-xor" + "bit-and" + "bit-shl" + "bit-shr" + "in" + "not-in" + "starts-with" + "ends-with" +]) @keyword) + +(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 [ + "=" + "+=" + "-=" + "*=" + "/=" + "++=" +] @operator) + +(expr_unary ["not" "-"] @operator) + +(val_range [ + ".." + "..=" + "..<" +] @operator) + +["=>" "=" "|"] @operator + +[ + "o>" "out>" + "e>" "err>" + "e+o>" "err+out>" + "o+e>" "out+err>" +] @special + +;;; --- +;;; 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.bracket + +(val_record + (record_entry ":" @punctuation.delimiter)) +;;; --- +;;; identifiers +(param_rest + name: (_) @variable) +(param_opt + name: (_) @variable) +(parameter + param_name: (_) @variable) +(param_cmd + (cmd_identifier) @string) +(param_long_flag) @variable +(param_short_flag) @variable + +(short_flag) @variable +(long_flag) @variable + +(scope_pattern [(wild_card) @function]) + +(cmd_identifier) @function + +(command + "^" @punctuation.delimiter + head: (_) @function +) + +"where" @function + +(path + ["." "?"] @punctuation.delimiter +) @variable + +(val_variable + "$" @operator + [ + (identifier) @variable + "in" @type.builtin + "nu" @type.builtin + "env" @type.builtin + "nothing" @type.builtin + ] ; If we have a special styling, use it here +) +;;; --- +;;; types +(flat_type) @type.builtin +(list_type + "list" @type + ["<" ">"] @punctuation.bracket +) +(collection_type + ["record" "table"] @type + "<" @punctuation.bracket + key: (_) @variable + ["," ":"] @punctuation.delimiter + ">" @punctuation.bracket +) + +(shebang) @comment +(comment) @comment diff --git a/crates/zed/src/languages/nu/indents.scm b/crates/zed/src/languages/nu/indents.scm new file mode 100644 index 0000000000000000000000000000000000000000..112b414aa45f277138d0c681851129a608ee96e0 --- /dev/null +++ b/crates/zed/src/languages/nu/indents.scm @@ -0,0 +1,3 @@ +(_ "[" "]" @end) @indent +(_ "{" "}" @end) @indent +(_ "(" ")" @end) @indent diff --git a/crates/zed/src/languages/nushell.rs b/crates/zed/src/languages/nushell.rs deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/crates/zed/src/languages/nushell/highlights.scm b/crates/zed/src/languages/nushell/highlights.scm deleted file mode 100644 index b97ed9836e659a3822f845a188b103b6eca07895..0000000000000000000000000000000000000000 --- a/crates/zed/src/languages/nushell/highlights.scm +++ /dev/null @@ -1,61 +0,0 @@ -(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" - "not" - "let" - "def" - "def-env" - "export" - "true" - "false" - "and" - "or" -] @keyword - -[ - ; "/" Not making / an operator may lead to better highlighting? - "$" - "|" - "+" - "-" - "*" - "=" - "!=" - "and" - "or" - "==" - ">" -] @operator - -["." - "," - ";" -] @delimiter