From 7bfa584eb65be22034ffc4c6c7504df11a2af917 Mon Sep 17 00:00:00 2001 From: Derrick Laird Date: Tue, 30 Jan 2024 12:08:10 -0700 Subject: [PATCH] Add protobuf support (#6748) Release Notes: - Added protobuf syntax highlighting ([#5160](https://github.com/zed-industries/zed/issues/5160)). --- Cargo.lock | 10 +++ Cargo.toml | 1 + crates/zed/Cargo.toml | 1 + crates/zed/src/languages.rs | 1 + crates/zed/src/languages/proto/config.toml | 12 ++++ crates/zed/src/languages/proto/highlights.scm | 61 +++++++++++++++++++ crates/zed/src/languages/proto/outline.scm | 19 ++++++ docs/src/languages/proto.md | 4 ++ 8 files changed, 109 insertions(+) create mode 100644 crates/zed/src/languages/proto/config.toml create mode 100644 crates/zed/src/languages/proto/highlights.scm create mode 100644 crates/zed/src/languages/proto/outline.scm create mode 100644 docs/src/languages/proto.md diff --git a/Cargo.lock b/Cargo.lock index f0f7fb512a744..88cd36edcaf18 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8665,6 +8665,15 @@ dependencies = [ "tree-sitter", ] +[[package]] +name = "tree-sitter-proto" +version = "0.0.2" +source = "git+https://github.com/rewinfrey/tree-sitter-proto?rev=36d54f288aee112f13a67b550ad32634d0c2cb52#36d54f288aee112f13a67b550ad32634d0c2cb52" +dependencies = [ + "cc", + "tree-sitter", +] + [[package]] name = "tree-sitter-purescript" version = "1.0.0" @@ -9876,6 +9885,7 @@ dependencies = [ "tree-sitter-nix", "tree-sitter-nu", "tree-sitter-php", + "tree-sitter-proto", "tree-sitter-purescript", "tree-sitter-python", "tree-sitter-racket", diff --git a/Cargo.toml b/Cargo.toml index 0d49975536f3d..f3c558356c177 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -149,6 +149,7 @@ tree-sitter-json = { git = "https://github.com/tree-sitter/tree-sitter-json", re tree-sitter-rust = "0.20.3" tree-sitter-markdown = { git = "https://github.com/MDeiml/tree-sitter-markdown", rev = "330ecab87a3e3a7211ac69bbadc19eabecdb1cca" } tree-sitter-php = "0.21.1" +tree-sitter-proto = {git = "https://github.com/rewinfrey/tree-sitter-proto", rev = "36d54f288aee112f13a67b550ad32634d0c2cb52"} tree-sitter-purescript = { git = "https://github.com/ivanmoreau/tree-sitter-purescript", rev = "a37140f0c7034977b90faa73c94fcb8a5e45ed08" } tree-sitter-python = "0.20.2" tree-sitter-toml = { git = "https://github.com/tree-sitter/tree-sitter-toml", rev = "342d9be207c2dba869b9967124c679b5e6fd0ebe" } diff --git a/crates/zed/Cargo.toml b/crates/zed/Cargo.toml index ec0241dac86c5..d0c7e8d7d7675 100644 --- a/crates/zed/Cargo.toml +++ b/crates/zed/Cargo.toml @@ -127,6 +127,7 @@ tree-sitter-heex.workspace = true tree-sitter-json.workspace = true tree-sitter-rust.workspace = true tree-sitter-markdown.workspace = true +tree-sitter-proto.workspace = true tree-sitter-python.workspace = true tree-sitter-toml.workspace = true tree-sitter-typescript.workspace = true diff --git a/crates/zed/src/languages.rs b/crates/zed/src/languages.rs index 0faeb358fda50..8e923ac2fd43e 100644 --- a/crates/zed/src/languages.rs +++ b/crates/zed/src/languages.rs @@ -295,6 +295,7 @@ pub fn init( tree_sitter_uiua::language(), vec![Arc::new(uiua::UiuaLanguageServer {})], ); + language("proto", tree_sitter_proto::language(), vec![]); if let Ok(children) = std::fs::read_dir(&*PLUGINS_DIR) { for child in children { diff --git a/crates/zed/src/languages/proto/config.toml b/crates/zed/src/languages/proto/config.toml new file mode 100644 index 0000000000000..81fe1bdfb4d30 --- /dev/null +++ b/crates/zed/src/languages/proto/config.toml @@ -0,0 +1,12 @@ +name = "proto" +path_suffixes = ["proto"] +line_comments = ["// "] +autoclose_before = ";:.,=}])>" +brackets = [ + { start = "{", end = "}", close = true, newline = true }, + { start = "[", end = "]", close = true, newline = true }, + { start = "(", end = ")", close = true, newline = true }, + { start = "\"", end = "\"", close = true, newline = false, not_in = ["comment", "string"] }, + { start = "'", end = "'", close = true, newline = false, not_in = ["comment", "string"] }, + { start = "/*", end = " */", close = true, newline = false, not_in = ["comment", "string"] }, +] diff --git a/crates/zed/src/languages/proto/highlights.scm b/crates/zed/src/languages/proto/highlights.scm new file mode 100644 index 0000000000000..5d0a513bee1ca --- /dev/null +++ b/crates/zed/src/languages/proto/highlights.scm @@ -0,0 +1,61 @@ +[ + "syntax" + "package" + "option" + "optional" + "import" + "service" + "rpc" + "returns" + "message" + "enum" + "oneof" + "repeated" + "reserved" + "to" +] @keyword + +[ + (key_type) + (type) + (message_name) + (enum_name) + (service_name) + (rpc_name) + (message_or_enum_type) +] @type + +(enum_field + (identifier) @constant) + +[ + (string) + "\"proto3\"" +] @string + +(int_lit) @number + +[ + (true) + (false) +] @boolean + +(comment) @comment + +[ + "(" + ")" + "[" + "]" + "{" + "}" + "<" + ">" +] @punctuation.bracket + +[ + ";" + "," +] @punctuation.delimiter + +"=" @operator diff --git a/crates/zed/src/languages/proto/outline.scm b/crates/zed/src/languages/proto/outline.scm new file mode 100644 index 0000000000000..f90b1bae33eff --- /dev/null +++ b/crates/zed/src/languages/proto/outline.scm @@ -0,0 +1,19 @@ +(message + "message" @context + (message_name + (identifier) @name)) @item + +(service + "service" @context + (service_name + (identifier) @name)) @item + +(rpc + "rpc" @context + (rpc_name + (identifier) @name)) @item + +(enum + "enum" @context + (enum_name + (identifier) @name)) @item diff --git a/docs/src/languages/proto.md b/docs/src/languages/proto.md new file mode 100644 index 0000000000000..486542a76cda5 --- /dev/null +++ b/docs/src/languages/proto.md @@ -0,0 +1,4 @@ +# Proto + +- Tree-Sitter: [tree-sitter-proto](https://github.com/rewinfrey/tree-sitter-proto) +- Language-Server: N/A