├── .gitignore ├── Cargo.lock ├── Cargo.toml ├── README.md ├── extension.toml ├── languages └── nu │ ├── brackets.scm │ ├── config.toml │ ├── highlights.scm │ ├── indents.scm │ ├── injections.scm │ └── textobjects.scm └── src └── nu.rs /.gitignore: -------------------------------------------------------------------------------- 1 | grammars 2 | *.wasm 3 | target 4 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 4 4 | 5 | [[package]] 6 | name = "anyhow" 7 | version = "1.0.82" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "f538837af36e6f6a9be0faa67f9a314f8119e4e4b5867c6ab40ed60360142519" 10 | 11 | [[package]] 12 | name = "bitflags" 13 | version = "2.5.0" 14 | source = "registry+https://github.com/rust-lang/crates.io-index" 15 | checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" 16 | 17 | [[package]] 18 | name = "equivalent" 19 | version = "1.0.1" 20 | source = "registry+https://github.com/rust-lang/crates.io-index" 21 | checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" 22 | 23 | [[package]] 24 | name = "hashbrown" 25 | version = "0.14.3" 26 | source = "registry+https://github.com/rust-lang/crates.io-index" 27 | checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" 28 | 29 | [[package]] 30 | name = "heck" 31 | version = "0.4.1" 32 | source = "registry+https://github.com/rust-lang/crates.io-index" 33 | checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" 34 | dependencies = [ 35 | "unicode-segmentation", 36 | ] 37 | 38 | [[package]] 39 | name = "id-arena" 40 | version = "2.2.1" 41 | source = "registry+https://github.com/rust-lang/crates.io-index" 42 | checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" 43 | 44 | [[package]] 45 | name = "indexmap" 46 | version = "2.2.6" 47 | source = "registry+https://github.com/rust-lang/crates.io-index" 48 | checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" 49 | dependencies = [ 50 | "equivalent", 51 | "hashbrown", 52 | "serde", 53 | ] 54 | 55 | [[package]] 56 | name = "itoa" 57 | version = "1.0.11" 58 | source = "registry+https://github.com/rust-lang/crates.io-index" 59 | checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" 60 | 61 | [[package]] 62 | name = "leb128" 63 | version = "0.2.5" 64 | source = "registry+https://github.com/rust-lang/crates.io-index" 65 | checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" 66 | 67 | [[package]] 68 | name = "log" 69 | version = "0.4.21" 70 | source = "registry+https://github.com/rust-lang/crates.io-index" 71 | checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" 72 | 73 | [[package]] 74 | name = "proc-macro2" 75 | version = "1.0.80" 76 | source = "registry+https://github.com/rust-lang/crates.io-index" 77 | checksum = "a56dea16b0a29e94408b9aa5e2940a4eedbd128a1ba20e8f7ae60fd3d465af0e" 78 | dependencies = [ 79 | "unicode-ident", 80 | ] 81 | 82 | [[package]] 83 | name = "quote" 84 | version = "1.0.36" 85 | source = "registry+https://github.com/rust-lang/crates.io-index" 86 | checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" 87 | dependencies = [ 88 | "proc-macro2", 89 | ] 90 | 91 | [[package]] 92 | name = "ryu" 93 | version = "1.0.17" 94 | source = "registry+https://github.com/rust-lang/crates.io-index" 95 | checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" 96 | 97 | [[package]] 98 | name = "semver" 99 | version = "1.0.22" 100 | source = "registry+https://github.com/rust-lang/crates.io-index" 101 | checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca" 102 | 103 | [[package]] 104 | name = "serde" 105 | version = "1.0.197" 106 | source = "registry+https://github.com/rust-lang/crates.io-index" 107 | checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" 108 | dependencies = [ 109 | "serde_derive", 110 | ] 111 | 112 | [[package]] 113 | name = "serde_derive" 114 | version = "1.0.197" 115 | source = "registry+https://github.com/rust-lang/crates.io-index" 116 | checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" 117 | dependencies = [ 118 | "proc-macro2", 119 | "quote", 120 | "syn", 121 | ] 122 | 123 | [[package]] 124 | name = "serde_json" 125 | version = "1.0.115" 126 | source = "registry+https://github.com/rust-lang/crates.io-index" 127 | checksum = "12dc5c46daa8e9fdf4f5e71b6cf9a53f2487da0e86e55808e2d35539666497dd" 128 | dependencies = [ 129 | "itoa", 130 | "ryu", 131 | "serde", 132 | ] 133 | 134 | [[package]] 135 | name = "smallvec" 136 | version = "1.13.2" 137 | source = "registry+https://github.com/rust-lang/crates.io-index" 138 | checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" 139 | 140 | [[package]] 141 | name = "spdx" 142 | version = "0.10.4" 143 | source = "registry+https://github.com/rust-lang/crates.io-index" 144 | checksum = "29ef1a0fa1e39ac22972c8db23ff89aea700ab96aa87114e1fb55937a631a0c9" 145 | dependencies = [ 146 | "smallvec", 147 | ] 148 | 149 | [[package]] 150 | name = "syn" 151 | version = "2.0.59" 152 | source = "registry+https://github.com/rust-lang/crates.io-index" 153 | checksum = "4a6531ffc7b071655e4ce2e04bd464c4830bb585a61cabb96cf808f05172615a" 154 | dependencies = [ 155 | "proc-macro2", 156 | "quote", 157 | "unicode-ident", 158 | ] 159 | 160 | [[package]] 161 | name = "unicode-ident" 162 | version = "1.0.12" 163 | source = "registry+https://github.com/rust-lang/crates.io-index" 164 | checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" 165 | 166 | [[package]] 167 | name = "unicode-segmentation" 168 | version = "1.11.0" 169 | source = "registry+https://github.com/rust-lang/crates.io-index" 170 | checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" 171 | 172 | [[package]] 173 | name = "unicode-xid" 174 | version = "0.2.4" 175 | source = "registry+https://github.com/rust-lang/crates.io-index" 176 | checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" 177 | 178 | [[package]] 179 | name = "wasm-encoder" 180 | version = "0.201.0" 181 | source = "registry+https://github.com/rust-lang/crates.io-index" 182 | checksum = "b9c7d2731df60006819b013f64ccc2019691deccf6e11a1804bc850cd6748f1a" 183 | dependencies = [ 184 | "leb128", 185 | ] 186 | 187 | [[package]] 188 | name = "wasm-metadata" 189 | version = "0.201.0" 190 | source = "registry+https://github.com/rust-lang/crates.io-index" 191 | checksum = "0fd83062c17b9f4985d438603cde0a5e8c5c8198201a6937f778b607924c7da2" 192 | dependencies = [ 193 | "anyhow", 194 | "indexmap", 195 | "serde", 196 | "serde_derive", 197 | "serde_json", 198 | "spdx", 199 | "wasm-encoder", 200 | "wasmparser", 201 | ] 202 | 203 | [[package]] 204 | name = "wasmparser" 205 | version = "0.201.0" 206 | source = "registry+https://github.com/rust-lang/crates.io-index" 207 | checksum = "84e5df6dba6c0d7fafc63a450f1738451ed7a0b52295d83e868218fa286bf708" 208 | dependencies = [ 209 | "bitflags", 210 | "indexmap", 211 | "semver", 212 | ] 213 | 214 | [[package]] 215 | name = "wit-bindgen" 216 | version = "0.22.0" 217 | source = "registry+https://github.com/rust-lang/crates.io-index" 218 | checksum = "288f992ea30e6b5c531b52cdd5f3be81c148554b09ea416f058d16556ba92c27" 219 | dependencies = [ 220 | "bitflags", 221 | "wit-bindgen-rt", 222 | "wit-bindgen-rust-macro", 223 | ] 224 | 225 | [[package]] 226 | name = "wit-bindgen-core" 227 | version = "0.22.0" 228 | source = "registry+https://github.com/rust-lang/crates.io-index" 229 | checksum = "e85e72719ffbccf279359ad071497e47eb0675fe22106dea4ed2d8a7fcb60ba4" 230 | dependencies = [ 231 | "anyhow", 232 | "wit-parser", 233 | ] 234 | 235 | [[package]] 236 | name = "wit-bindgen-rt" 237 | version = "0.22.0" 238 | source = "registry+https://github.com/rust-lang/crates.io-index" 239 | checksum = "fcb8738270f32a2d6739973cbbb7c1b6dd8959ce515578a6e19165853272ee64" 240 | 241 | [[package]] 242 | name = "wit-bindgen-rust" 243 | version = "0.22.0" 244 | source = "registry+https://github.com/rust-lang/crates.io-index" 245 | checksum = "d8a39a15d1ae2077688213611209849cad40e9e5cccf6e61951a425850677ff3" 246 | dependencies = [ 247 | "anyhow", 248 | "heck", 249 | "indexmap", 250 | "wasm-metadata", 251 | "wit-bindgen-core", 252 | "wit-component", 253 | ] 254 | 255 | [[package]] 256 | name = "wit-bindgen-rust-macro" 257 | version = "0.22.0" 258 | source = "registry+https://github.com/rust-lang/crates.io-index" 259 | checksum = "d376d3ae5850526dfd00d937faea0d81a06fa18f7ac1e26f386d760f241a8f4b" 260 | dependencies = [ 261 | "anyhow", 262 | "proc-macro2", 263 | "quote", 264 | "syn", 265 | "wit-bindgen-core", 266 | "wit-bindgen-rust", 267 | ] 268 | 269 | [[package]] 270 | name = "wit-component" 271 | version = "0.201.0" 272 | source = "registry+https://github.com/rust-lang/crates.io-index" 273 | checksum = "421c0c848a0660a8c22e2fd217929a0191f14476b68962afd2af89fd22e39825" 274 | dependencies = [ 275 | "anyhow", 276 | "bitflags", 277 | "indexmap", 278 | "log", 279 | "serde", 280 | "serde_derive", 281 | "serde_json", 282 | "wasm-encoder", 283 | "wasm-metadata", 284 | "wasmparser", 285 | "wit-parser", 286 | ] 287 | 288 | [[package]] 289 | name = "wit-parser" 290 | version = "0.201.0" 291 | source = "registry+https://github.com/rust-lang/crates.io-index" 292 | checksum = "196d3ecfc4b759a8573bf86a9b3f8996b304b3732e4c7de81655f875f6efdca6" 293 | dependencies = [ 294 | "anyhow", 295 | "id-arena", 296 | "indexmap", 297 | "log", 298 | "semver", 299 | "serde", 300 | "serde_derive", 301 | "serde_json", 302 | "unicode-xid", 303 | "wasmparser", 304 | ] 305 | 306 | [[package]] 307 | name = "zed_extension_api" 308 | version = "0.2.0" 309 | source = "registry+https://github.com/rust-lang/crates.io-index" 310 | checksum = "9fd16b8b30a9dc920fc1678ff852f696b5bdf5b5843bc745a128be0aac29859e" 311 | dependencies = [ 312 | "serde", 313 | "serde_json", 314 | "wit-bindgen", 315 | ] 316 | 317 | [[package]] 318 | name = "zed_nu" 319 | version = "0.0.6" 320 | dependencies = [ 321 | "zed_extension_api", 322 | ] 323 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "zed_nu" 3 | version = "0.0.6" 4 | edition = "2021" 5 | publish = false 6 | license = "Apache-2.0" 7 | 8 | [lib] 9 | path = "src/nu.rs" 10 | crate-type = ["cdylib"] 11 | 12 | [dependencies] 13 | zed_extension_api = "0.2.0" 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Zed Nu 2 | 3 | This extension adds support for the [Nu](https://github.com/nushell/nushell) language. 4 | 5 | ## Override Default Configuration (Optional) 6 | 7 | You can minimize the configuration autoloaded when the server starts, 8 | which may improve performance as complicated Nushell configurations can slow down the language server. 9 | 10 | ```json 11 | { 12 | "lsp": { 13 | "nu": { 14 | "binary": { 15 | "path": "nu", 16 | "arguments": ["--config", "~/.config/nushell/lsp.nu", "--lsp"] 17 | } 18 | } 19 | } 20 | } 21 | ``` 22 | 23 | ### Example of Minimal lsp.nu 24 | 25 | ```nushell 26 | # Configure PATH to search for external command completions 27 | $env.path = $env.path 28 | | split row (char esep) 29 | | append ($env.HOME | path join ".cargo" "bin") 30 | | uniq 31 | 32 | # Set up external completer (requires carapace) 33 | $env.CARAPACE_LENIENT = 1 34 | $env.CARAPACE_BRIDGES = 'zsh' 35 | $env.config.completions.external.completer = {|spans: list| 36 | carapace $spans.0 nushell ...$spans 37 | | from json 38 | | if ($in | default [] | where value =~ '^-.*ERR$' | is-empty) { $in } else { null } 39 | } 40 | 41 | # Define extra library directories to load definitions from 42 | const NU_LIB_DIRS = ["some/extra/lib"] 43 | ``` 44 | -------------------------------------------------------------------------------- /extension.toml: -------------------------------------------------------------------------------- 1 | id = "nu" 2 | name = "Nu" 3 | description = "Nushell language support for Zed" 4 | version = "0.0.6" 5 | schema_version = 1 6 | authors = [ 7 | "Mikayla Maki ", 8 | "Joseph Lyons ", 9 | "Darren Schroeder", 10 | ] 11 | repository = "https://github.com/zed-extensions/nu" 12 | 13 | [grammars.nu] 14 | repository = "https://github.com/nushell/tree-sitter-nu" 15 | commit = "b99dc3b7b26337d84f95c0de4dda81077b03e5c7" 16 | 17 | [language_servers.nu] 18 | languages = ["Nu"] 19 | name = "nu" 20 | -------------------------------------------------------------------------------- /languages/nu/brackets.scm: -------------------------------------------------------------------------------- 1 | ("(" @open ")" @close) 2 | ("[" @open "]" @close) 3 | ("{" @open "}" @close) 4 | (parameter_pipes "|" @open "|" @close) 5 | -------------------------------------------------------------------------------- /languages/nu/config.toml: -------------------------------------------------------------------------------- 1 | name = "Nu" 2 | grammar = "nu" 3 | path_suffixes = ["nu"] 4 | line_comments = ["# "] 5 | autoclose_before = ";:.,=}])>` \n\t\"" 6 | first_line_pattern = '^#!.*\b(?:nu)\b' 7 | brackets = [ 8 | { start = "{", end = "}", close = true, newline = true }, 9 | { start = "[", end = "]", close = true, newline = true }, 10 | { start = "(", end = ")", close = true, newline = true }, 11 | ] 12 | -------------------------------------------------------------------------------- /languages/nu/highlights.scm: -------------------------------------------------------------------------------- 1 | ; Forked from https://github.com/nushell/tree-sitter-nu 2 | ; Copyright (c) 2019 - 2022 The Nushell Project Developers 3 | ; Licensed under the MIT license. 4 | ;;; --- 5 | ;;; keywords 6 | [ 7 | "def" 8 | "alias" 9 | "export-env" 10 | "export" 11 | "extern" 12 | "module" 13 | 14 | "let" 15 | "let-env" 16 | "mut" 17 | "const" 18 | 19 | "hide-env" 20 | 21 | "source" 22 | "source-env" 23 | 24 | "overlay" 25 | 26 | "loop" 27 | "while" 28 | "error" 29 | 30 | "do" 31 | "if" 32 | "else" 33 | "try" 34 | "catch" 35 | "match" 36 | 37 | "break" 38 | "continue" 39 | "return" 40 | 41 | ] @keyword 42 | 43 | (hide_mod "hide" @keyword) 44 | (decl_use "use" @keyword) 45 | 46 | (ctrl_for 47 | "for" @keyword 48 | "in" @keyword 49 | ) 50 | (overlay_list "list" @keyword.storage.modifier) 51 | (overlay_hide "hide" @keyword.storage.modifier) 52 | (overlay_new "new" @keyword.storage.modifier) 53 | (overlay_use 54 | "use" @keyword.storage.modifier 55 | "as" @keyword 56 | ) 57 | (ctrl_error "make" @keyword.storage.modifier) 58 | 59 | ;;; --- 60 | ;;; literals 61 | (val_number) @number 62 | (val_duration unit: _ @variable.parameter) 63 | (val_filesize unit: _ @variable.parameter) 64 | (val_binary 65 | [ 66 | "0b" 67 | "0o" 68 | "0x" 69 | ] @number 70 | "[" @punctuation.bracket 71 | digit: [ 72 | "," @punctuation.delimiter 73 | (hex_digit) @number 74 | ] 75 | "]" @punctuation.bracket 76 | ) @number 77 | (val_bool) @constant.builtin 78 | (val_nothing) @constant.builtin 79 | (val_string) @string 80 | arg_str: (val_string) @variable.parameter 81 | file_path: (val_string) @variable.parameter 82 | (val_date) @number 83 | (inter_escape_sequence) @constant.character.escape 84 | (escape_sequence) @constant.character.escape 85 | (val_interpolated [ 86 | "$\"" 87 | "$\'" 88 | "\"" 89 | "\'" 90 | ] @string) 91 | (unescaped_interpolated_content) @string 92 | (escaped_interpolated_content) @string 93 | (expr_interpolated ["(" ")"] @variable.parameter) 94 | 95 | (raw_string_begin) @punctuation.special 96 | (raw_string_content) @string 97 | (raw_string_end) @punctuation.special 98 | 99 | ;;; --- 100 | ;;; operators 101 | (expr_binary 102 | opr: _ @operator) 103 | 104 | (where_command 105 | opr: _ @operator) 106 | 107 | (assignment [ 108 | "=" 109 | "+=" 110 | "-=" 111 | "*=" 112 | "/=" 113 | "++=" 114 | ] @operator) 115 | 116 | (expr_unary ["not" "-"] @operator) 117 | 118 | (val_range [ 119 | ".." 120 | "..=" 121 | "..<" 122 | ] @operator) 123 | 124 | ["=>" "=" "|"] @operator 125 | 126 | [ 127 | "o>" "out>" 128 | "e>" "err>" 129 | "e+o>" "err+out>" 130 | "o+e>" "out+err>" 131 | "o>>" "out>>" 132 | "e>>" "err>>" 133 | "e+o>>" "err+out>>" 134 | "o+e>>" "out+err>>" 135 | "e>|" "err>|" 136 | "e+o>|" "err+out>|" 137 | "o+e>|" "out+err>|" 138 | ] @operator 139 | 140 | ;;; --- 141 | ;;; punctuation 142 | [ 143 | "," 144 | ";" 145 | ] @punctuation.special 146 | 147 | (param_long_flag ["--"] @punctuation.delimiter) 148 | (long_flag ["--"] @punctuation.delimiter) 149 | (short_flag ["-"] @punctuation.delimiter) 150 | (long_flag ["="] @punctuation.special) 151 | (short_flag ["="] @punctuation.special) 152 | (param_short_flag ["-"] @punctuation.delimiter) 153 | (param_rest "..." @punctuation.delimiter) 154 | (param_type [":"] @punctuation.special) 155 | (param_value ["="] @punctuation.special) 156 | (param_cmd ["@"] @punctuation.special) 157 | (attribute ["@"] @punctuation.special) 158 | (param_opt ["?"] @punctuation.special) 159 | (returns "->" @punctuation.special) 160 | 161 | [ 162 | "(" ")" 163 | "{" "}" 164 | "[" "]" 165 | "...[" 166 | "...(" 167 | "...{" 168 | ] @punctuation.bracket 169 | 170 | (val_record 171 | (record_entry ":" @punctuation.delimiter)) 172 | key: (identifier) @property 173 | 174 | ;;; --- 175 | ;;; identifiers 176 | (param_rest 177 | name: (_) @variable.parameter) 178 | (param_opt 179 | name: (_) @variable.parameter) 180 | (parameter 181 | param_name: (_) @variable.parameter) 182 | (param_cmd 183 | (cmd_identifier) @string) 184 | 185 | (param_long_flag (long_flag_identifier) @attribute) 186 | (param_short_flag (param_short_flag_identifier) @attribute) 187 | (attribute (attribute_identifier) @attribute) 188 | 189 | (short_flag (short_flag_identifier) @attribute) 190 | (long_flag_identifier) @attribute 191 | 192 | (scope_pattern [(wild_card) @function]) 193 | 194 | (cmd_identifier) @function 195 | ; generated with Nu 0.93.0 196 | ; > help commands 197 | ; | filter { $in.command_type == builtin and $in.category != core } 198 | ; | each {$'"($in.name | split row " " | $in.0)"'} 199 | ; | uniq 200 | ; | str join ' ' 201 | (command 202 | head: [ 203 | (cmd_identifier) @function.builtin 204 | (#any-of? @function.builtin 205 | "all" "ansi" "any" "append" "ast" "bits" "bytes" "cal" "cd" "char" "clear" 206 | "collect" "columns" "compact" "complete" "config" "cp" "date" "debug" 207 | "decode" "default" "detect" "dfr" "drop" "du" "each" "encode" "enumerate" 208 | "every" "exec" "exit" "explain" "explore" "export-env" "fill" "filter" 209 | "find" "first" "flatten" "fmt" "format" "from" "generate" "get" "glob" 210 | "grid" "group" "group-by" "hash" "headers" "histogram" "history" "http" 211 | "input" "insert" "inspect" "interleave" "into" "is-empty" "is-not-empty" 212 | "is-terminal" "items" "join" "keybindings" "kill" "last" "length" 213 | "let-env" "lines" "load-env" "ls" "math" "merge" "metadata" "mkdir" 214 | "mktemp" "move" "mv" "nu-check" "nu-highlight" "open" "panic" "par-each" 215 | "parse" "path" "plugin" "port" "prepend" "print" "ps" "query" "random" 216 | "range" "reduce" "reject" "rename" "reverse" "rm" "roll" "rotate" 217 | "run-external" "save" "schema" "select" "seq" "shuffle" "skip" "sleep" 218 | "sort" "sort-by" "split" "split-by" "start" "stor" "str" "sys" "table" 219 | "take" "tee" "term" "timeit" "to" "touch" "transpose" "tutor" "ulimit" 220 | "uname" "uniq" "uniq-by" "update" "upsert" "url" "values" "view" "watch" 221 | "where" "which" "whoami" "window" "with-env" "wrap" "zip" 222 | ) 223 | ]) 224 | 225 | (command 226 | "^" @punctuation.delimiter 227 | head: (_) @function 228 | ) 229 | 230 | "where" @function.builtin 231 | 232 | (path 233 | ["." "?"] @punctuation.delimiter 234 | ) @variable.parameter 235 | 236 | (stmt_let (identifier) @variable) 237 | 238 | (val_variable 239 | "$"? @punctuation.special 240 | "...$"? @punctuation.special 241 | [ 242 | (identifier) @variable 243 | "in" @special 244 | "nu" @namespace 245 | "env" @constant 246 | ] 247 | ) @none 248 | 249 | (record_entry 250 | ":" @punctuation.special) 251 | 252 | ;;; --- 253 | ;;; types 254 | (flat_type) @type 255 | (list_type 256 | "list" @type.enum 257 | ["<" ">"] @punctuation.bracket 258 | ) 259 | (collection_type 260 | ["record" "table"] @type.enum 261 | "<" @punctuation.bracket 262 | key: (_) @variable.parameter 263 | ["," ":"] @punctuation.special 264 | ">" @punctuation.bracket 265 | ) 266 | 267 | (shebang) @keyword.directive 268 | (comment) @comment 269 | ((comment)+ @comment.documentation @spell 270 | . 271 | (decl_def)) 272 | 273 | (parameter 274 | (comment) @comment.documentation @spell) 275 | -------------------------------------------------------------------------------- /languages/nu/indents.scm: -------------------------------------------------------------------------------- 1 | ; Forked from https://github.com/nushell/tree-sitter-nu 2 | ; Copyright (c) 2019 - 2022 The Nushell Project Developers 3 | ; Licensed under the MIT license. 4 | [ 5 | (expr_parenthesized) 6 | (parameter_bracks) 7 | (ctrl_match) 8 | 9 | (val_record) 10 | (val_list) 11 | (val_closure) 12 | (val_table) 13 | 14 | (block) 15 | ] @indent.begin 16 | 17 | [ 18 | "}" 19 | "]" 20 | ")" 21 | ] @indent.end 22 | 23 | [ 24 | "}" 25 | "]" 26 | ")" 27 | ] @indent.branch 28 | 29 | (comment) @indent.auto 30 | -------------------------------------------------------------------------------- /languages/nu/injections.scm: -------------------------------------------------------------------------------- 1 | ; Forked from https://github.com/nushell/tree-sitter-nu 2 | ; Copyright (c) 2019 - 2022 The Nushell Project Developers 3 | ; Licensed under the MIT license. 4 | ((comment) @injection.content 5 | (#set! injection.language "comment")) 6 | -------------------------------------------------------------------------------- /languages/nu/textobjects.scm: -------------------------------------------------------------------------------- 1 | ; Forked from https://github.com/nushell/tree-sitter-nu 2 | ; Copyright (c) 2019 - 2022 The Nushell Project Developers 3 | ; Licensed under the MIT license. 4 | (stmt_let) @assignment.outer 5 | (stmt_mut) @assignment.outer 6 | (stmt_const) @assignment.outer 7 | 8 | (stmt_let 9 | value: (_) @assignment.inner) 10 | (stmt_mut 11 | value: (_) @assignment.inner) 12 | (stmt_const 13 | value: (_) @assignment.inner) 14 | 15 | (block) @block.outer 16 | 17 | (comment) @comment.outer 18 | 19 | (pipeline) @pipeline.outer 20 | (pipe_element) @pipeline.inner 21 | 22 | (decl_def) @function.outer 23 | (decl_def 24 | body: (_) @function.inner) 25 | 26 | (ctrl_for) @loop.outer 27 | (ctrl_loop) @loop.outer 28 | (ctrl_while) @loop.outer 29 | 30 | (ctrl_for 31 | body: (_) @loop.inner) 32 | (ctrl_loop 33 | body: (_) @loop.inner) 34 | (ctrl_while 35 | body: (_) @loop.inner) 36 | 37 | ; Conditional inner counts the last one, rather than the current one. 38 | (ctrl_if 39 | then_branch: (_) @conditional.inner 40 | else_block: (_)? @conditional.inner 41 | ) @conditional.outer 42 | 43 | (parameter) @parameter.outer 44 | 45 | (command 46 | head: (_) @call.inner) @call.outer 47 | (where_command 48 | predicate: (_) @call.inner) @call.outer 49 | 50 | ; define pipeline first, because it should only match as a fallback 51 | ; e.g., `let a = date now` should match the whole assignment. 52 | ; But a standalone `date now` should also match a statement 53 | (pipeline) @statement.outer 54 | 55 | (stmt_let) @statement.outer 56 | (stmt_mut) @statement.outer 57 | (stmt_const) @statement.outer 58 | (ctrl_return) @statement.outer @return.outer 59 | (ctrl_do) @statement.outer 60 | (ctrl_if) @statement.outer 61 | (ctrl_try) @statement.outer 62 | (ctrl_match) @statement.outer 63 | (ctrl_while) @statement.outer 64 | (ctrl_loop) @statement.outer 65 | ("break" "continue") @statement.outer 66 | 67 | (val_number) @number.inner 68 | -------------------------------------------------------------------------------- /src/nu.rs: -------------------------------------------------------------------------------- 1 | use zed::LanguageServerId; 2 | use zed_extension_api::{self as zed, Result}; 3 | 4 | struct NuExtension; 5 | 6 | impl zed::Extension for NuExtension { 7 | fn new() -> Self { 8 | Self 9 | } 10 | 11 | fn language_server_command( 12 | &mut self, 13 | _: &LanguageServerId, 14 | worktree: &zed::Worktree, 15 | ) -> Result { 16 | let path = worktree 17 | .which("nu") 18 | .ok_or_else(|| "nu is not installed".to_string())?; 19 | 20 | Ok(zed::Command { 21 | command: path, 22 | args: vec!["--lsp".to_string()], 23 | env: Default::default(), 24 | }) 25 | } 26 | } 27 | 28 | zed::register_extension!(NuExtension); 29 | --------------------------------------------------------------------------------