From 9a1a9813cbc5936f0da02088b3b70d5f5c445083 Mon Sep 17 00:00:00 2001 From: Nate Butler Date: Thu, 13 Jul 2023 11:56:53 -0400 Subject: [PATCH 1/3] WIP --- Cargo.lock | 10 ++++ crates/zed/Cargo.toml | 1 + crates/zed/src/languages.rs | 1 + crates/zed/src/languages/bash/brackets.scm | 3 ++ crates/zed/src/languages/bash/config.toml | 7 +++ crates/zed/src/languages/bash/highlights.scm | 56 ++++++++++++++++++++ 6 files changed, 78 insertions(+) create mode 100644 crates/zed/src/languages/bash/brackets.scm create mode 100644 crates/zed/src/languages/bash/config.toml create mode 100644 crates/zed/src/languages/bash/highlights.scm diff --git a/Cargo.lock b/Cargo.lock index 0ac6a2ee890418104d6851a961d321f1ef7e8f36..ec674aee2ce721077e3f5b9f6054afa9ac92d2cd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7953,6 +7953,15 @@ dependencies = [ "regex", ] +[[package]] +name = "tree-sitter-bash" +version = "0.19.0" +source = "git+https://github.com/tree-sitter/tree-sitter-bash?rev=1b0321ee85701d5036c334a6f04761cdc672e64c#1b0321ee85701d5036c334a6f04761cdc672e64c" +dependencies = [ + "cc", + "tree-sitter", +] + [[package]] name = "tree-sitter-c" version = "0.20.2" @@ -9539,6 +9548,7 @@ dependencies = [ "tiny_http", "toml", "tree-sitter", + "tree-sitter-bash", "tree-sitter-c", "tree-sitter-cpp", "tree-sitter-css", diff --git a/crates/zed/Cargo.toml b/crates/zed/Cargo.toml index 597e40161fb029eee16cf53208ce0e20d0c0a603..fb7cd6addab2d164bdfd60600ed582cb1f838f6c 100644 --- a/crates/zed/Cargo.toml +++ b/crates/zed/Cargo.toml @@ -104,6 +104,7 @@ thiserror.workspace = true tiny_http = "0.8" toml.workspace = true tree-sitter.workspace = true +tree-sitter-bash = { git = "https://github.com/tree-sitter/tree-sitter-bash", rev = "1b0321ee85701d5036c334a6f04761cdc672e64c" } tree-sitter-c = "0.20.1" tree-sitter-cpp = "0.20.0" tree-sitter-css = { git = "https://github.com/tree-sitter/tree-sitter-css", rev = "769203d0f9abe1a9a691ac2b9fe4bb4397a73c51" } diff --git a/crates/zed/src/languages.rs b/crates/zed/src/languages.rs index 820f5641510d8cc0f0d0eb216a8c2056e4916428..225bc4d0bce8f735a5f87cf5232c0787eb987445 100644 --- a/crates/zed/src/languages.rs +++ b/crates/zed/src/languages.rs @@ -38,6 +38,7 @@ pub fn init(languages: Arc, node_runtime: Arc) { languages.register(name, load_config(name), grammar, adapters, load_queries) }; + language("bash", tree_sitter_bash::language(), vec![]); language( "c", tree_sitter_c::language(), diff --git a/crates/zed/src/languages/bash/brackets.scm b/crates/zed/src/languages/bash/brackets.scm new file mode 100644 index 0000000000000000000000000000000000000000..191fd9c084a52eced37428281971ff9e569a4932 --- /dev/null +++ b/crates/zed/src/languages/bash/brackets.scm @@ -0,0 +1,3 @@ +("(" @open ")" @close) +("[" @open "]" @close) +("{" @open "}" @close) diff --git a/crates/zed/src/languages/bash/config.toml b/crates/zed/src/languages/bash/config.toml new file mode 100644 index 0000000000000000000000000000000000000000..f3dcee9b73ecc4ea272febfc40128a1bad4d5a2a --- /dev/null +++ b/crates/zed/src/languages/bash/config.toml @@ -0,0 +1,7 @@ +name = "Shell Script" +path_suffixes = [".sh", ".bash", ".bashrc", ".bash_profile", ".bash_aliases", ".bash_logout", ".profile", ".zsh", ".zshrc", ".zshenv", ".zsh_profile", ".zsh_aliases", ".zsh_histfile", ".zlogin"] +brackets = [ + { start = "[", end = "]", close = true, newline = false }, + { start = "(", end = ")", close = true, newline = false }, + { start = "\"", end = "\"", close = true, newline = false, not_in = ["comment", "string"] }, +] diff --git a/crates/zed/src/languages/bash/highlights.scm b/crates/zed/src/languages/bash/highlights.scm new file mode 100644 index 0000000000000000000000000000000000000000..f33a7c2d3ae8c63364845dbd8cef1242ffa07f04 --- /dev/null +++ b/crates/zed/src/languages/bash/highlights.scm @@ -0,0 +1,56 @@ +[ + (string) + (raw_string) + (heredoc_body) + (heredoc_start) +] @string + +(command_name) @function + +(variable_name) @property + +[ + "case" + "do" + "done" + "elif" + "else" + "esac" + "export" + "fi" + "for" + "function" + "if" + "in" + "select" + "then" + "unset" + "until" + "while" +] @keyword + +(comment) @comment + +(function_definition name: (word) @function) + +(file_descriptor) @number + +[ + (command_substitution) + (process_substitution) + (expansion) +]@embedded + +[ + "$" + "&&" + ">" + ">>" + "<" + "|" +] @operator + +( + (command (_) @constant) + (#match? @constant "^-") +) From ef7aa66959ca44fe99293d8352360f94d569e33c Mon Sep 17 00:00:00 2001 From: Nate Butler Date: Thu, 13 Jul 2023 12:09:43 -0400 Subject: [PATCH 2/3] Add first line pattern --- crates/zed/src/languages/bash/config.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/zed/src/languages/bash/config.toml b/crates/zed/src/languages/bash/config.toml index f3dcee9b73ecc4ea272febfc40128a1bad4d5a2a..80b8753d80105f91ea9c0b802a2fe11ea61557c4 100644 --- a/crates/zed/src/languages/bash/config.toml +++ b/crates/zed/src/languages/bash/config.toml @@ -1,5 +1,6 @@ name = "Shell Script" path_suffixes = [".sh", ".bash", ".bashrc", ".bash_profile", ".bash_aliases", ".bash_logout", ".profile", ".zsh", ".zshrc", ".zshenv", ".zsh_profile", ".zsh_aliases", ".zsh_histfile", ".zlogin"] +first_line_pattern = "^#!.*\\b(?:ba|z)?sh\\b" brackets = [ { start = "[", end = "]", close = true, newline = false }, { start = "(", end = ")", close = true, newline = false }, From bf2dcd4582adb2332c1298eff7d5d34185baf9cc Mon Sep 17 00:00:00 2001 From: Nate Butler Date: Tue, 18 Jul 2023 12:15:03 -0400 Subject: [PATCH 3/3] Update cargo.toml --- Cargo.toml | 1 + crates/zed/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 7a32938c378e8bbbfcd9d3fad6de1a79366c0b43..fa824115cb82b02c2428f2f1bd9889a0b93a5757 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -107,6 +107,7 @@ tree-sitter = "0.20" unindent = { version = "0.1.7" } pretty_assertions = "1.3.0" +tree-sitter-bash = { git = "https://github.com/tree-sitter/tree-sitter-bash", rev = "1b0321ee85701d5036c334a6f04761cdc672e64c" } tree-sitter-c = "0.20.1" tree-sitter-cpp = "0.20.0" tree-sitter-css = { git = "https://github.com/tree-sitter/tree-sitter-css", rev = "769203d0f9abe1a9a691ac2b9fe4bb4397a73c51" } diff --git a/crates/zed/Cargo.toml b/crates/zed/Cargo.toml index 478cdf226618473c38361999496a3021d82f2679..f749fb6e68df122a859f2a983dc2d5fa87afe27a 100644 --- a/crates/zed/Cargo.toml +++ b/crates/zed/Cargo.toml @@ -104,7 +104,7 @@ thiserror.workspace = true tiny_http = "0.8" toml.workspace = true tree-sitter.workspace = true -tree-sitter-bash = { git = "https://github.com/tree-sitter/tree-sitter-bash", rev = "1b0321ee85701d5036c334a6f04761cdc672e64c" } +tree-sitter-bash.workspace = true tree-sitter-c.workspace = true tree-sitter-cpp.workspace = true tree-sitter-css.workspace = true