diff --git a/Cargo.lock b/Cargo.lock index 9eb9e1c..df35921 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -921,6 +921,7 @@ dependencies = [ "tree-sitter-javascript", "tree-sitter-json", "tree-sitter-md", + "tree-sitter-protobuf", "tree-sitter-python", "tree-sitter-rebase", "tree-sitter-ron", @@ -3174,6 +3175,15 @@ dependencies = [ "tree-sitter", ] +[[package]] +name = "tree-sitter-protobuf" +version = "0.0.1" +source = "git+https://github.com/yusdacra/tree-sitter-protobuf?rev=19c211a01434d9f03efff99f85e19f967591b175#19c211a01434d9f03efff99f85e19f967591b175" +dependencies = [ + "cc", + "tree-sitter", +] + [[package]] name = "tree-sitter-python" version = "0.20.4" diff --git a/crates/ferrite-core/Cargo.toml b/crates/ferrite-core/Cargo.toml index cace2ba..627b490 100644 --- a/crates/ferrite-core/Cargo.toml +++ b/crates/ferrite-core/Cargo.toml @@ -70,6 +70,7 @@ lang-ini = ["ferrite-tree-sitter/lang-ini"] lang-javascript = ["ferrite-tree-sitter/lang-javascript"] lang-json = ["ferrite-tree-sitter/lang-json"] lang-md = ["ferrite-tree-sitter/lang-md"] +lang-protobuf = ["ferrite-tree-sitter/lang-protobuf"] lang-python = ["ferrite-tree-sitter/lang-python"] lang-rebase = ["ferrite-tree-sitter/lang-rebase"] lang-ron = ["ferrite-tree-sitter/lang-ron"] @@ -103,6 +104,7 @@ default = [ "lang-javascript", "lang-json", "lang-md", + "lang-protobuf", "lang-python", "lang-rebase", "lang-ron", diff --git a/crates/ferrite-core/src/language.rs b/crates/ferrite-core/src/language.rs index 0cf961c..f6531c8 100644 --- a/crates/ferrite-core/src/language.rs +++ b/crates/ferrite-core/src/language.rs @@ -99,6 +99,8 @@ static LANGUAGES: Lazy>> = Lazy langs.insert("git-rebase", OnceCell::new()); #[cfg(feature = "lang-dockerfile")] langs.insert("dockerfile", OnceCell::new()); + #[cfg(feature = "lang-protobuf")] + langs.insert("protobuf", OnceCell::new()); langs }); @@ -345,6 +347,14 @@ fn get_lang_config(name: &str) -> Option { include_str!("../../../queries/dockerfile/injections.scm"), "", ), + #[cfg(feature = "lang-protobuf")] + "protobuf" => TreeSitterConfig::new( + "protobuf", + ferrite_tree_sitter::tree_sitter_protobuf::language(), + include_str!("../../../queries/protobuf/highlights.scm"), + include_str!("../../../queries/protobuf/injections.scm"), + "", + ), _ => return None, }) } diff --git a/crates/ferrite-tree-sitter/Cargo.toml b/crates/ferrite-tree-sitter/Cargo.toml index cddd6e7..2106f6c 100644 --- a/crates/ferrite-tree-sitter/Cargo.toml +++ b/crates/ferrite-tree-sitter/Cargo.toml @@ -26,6 +26,7 @@ tree-sitter-ini = { git = "https://github.com/justinmk/tree-sitter-ini", rev = " tree-sitter-javascript = { git = "https://github.com/tree-sitter/tree-sitter-javascript", rev = "f772967f7b7bc7c28f845be2420a38472b16a8ee", optional = true } tree-sitter-json = { version = "0.19.0", optional = true } tree-sitter-md = { git = "https://github.com/MDeiml/tree-sitter-markdown", rev = "272e080bca0efd19a06a7f4252d746417224959e", optional = true } +tree-sitter-protobuf = { git = "https://github.com/yusdacra/tree-sitter-protobuf", rev = "19c211a01434d9f03efff99f85e19f967591b175", optional = true } tree-sitter-python = { version = "0.20.2", optional = true } tree-sitter-rebase = { git = "https://github.com/the-mikedavis/tree-sitter-git-rebase", rev = "d8a4207ebbc47bd78bacdf48f883db58283f9fd8", optional = true } tree-sitter-ron = { git = "https://github.com/amaanq/tree-sitter-ron", rev = "ce6086b2c9e8e71065b8129d6c2289c5f66d1879", optional = true } @@ -58,6 +59,7 @@ lang-ini = ["dep:tree-sitter-ini"] lang-javascript = ["dep:tree-sitter-javascript"] lang-json = ["dep:tree-sitter-json"] lang-md = ["dep:tree-sitter-md"] +lang-protobuf = ["dep:tree-sitter-protobuf"] lang-python = ["dep:tree-sitter-python"] lang-rebase = ["dep:tree-sitter-rebase"] lang-ron = ["dep:tree-sitter-ron"] diff --git a/crates/ferrite-tree-sitter/src/lib.rs b/crates/ferrite-tree-sitter/src/lib.rs index 329cee0..a6b6041 100644 --- a/crates/ferrite-tree-sitter/src/lib.rs +++ b/crates/ferrite-tree-sitter/src/lib.rs @@ -40,6 +40,8 @@ pub use tree_sitter_javascript; pub use tree_sitter_json; #[cfg(feature = "lang-md")] pub use tree_sitter_md; +#[cfg(feature = "lang-protobuf")] +pub use tree_sitter_protobuf; #[cfg(feature = "lang-python")] pub use tree_sitter_python; #[cfg(feature = "lang-rebase")] diff --git a/queries/protobuf/highlights.scm b/queries/protobuf/highlights.scm new file mode 100644 index 0000000..c35c430 --- /dev/null +++ b/queries/protobuf/highlights.scm @@ -0,0 +1,58 @@ +[ + "syntax" + "package" + "option" + "import" + "service" + "rpc" + "returns" + "message" + "enum" + "oneof" + "repeated" + "reserved" + "to" + "stream" + "extend" + "optional" +] @keyword + +[ + (keyType) + (type) +] @type.builtin + +[ + (mapName) + (enumName) + (messageName) + (extendName) + (serviceName) + (rpcName) +] @type + +[ + (fieldName) + (optionName) +] @variable.other.member +(enumVariantName) @type.enum.variant + +(fullIdent) @namespace + +(intLit) @constant.numeric.integer +(floatLit) @constant.numeric.float +(boolLit) @constant.builtin.boolean +(strLit) @string + +(constant) @constant + +(comment) @comment + +[ + "(" + ")" + "[" + "]" + "{" + "}" +] @punctuation.bracket \ No newline at end of file diff --git a/queries/protobuf/injections.scm b/queries/protobuf/injections.scm new file mode 100644 index 0000000..321c90a --- /dev/null +++ b/queries/protobuf/injections.scm @@ -0,0 +1,2 @@ +((comment) @injection.content + (#set! injection.language "comment"))