Skip to content

Commit

Permalink
add protobuf
Browse files Browse the repository at this point in the history
  • Loading branch information
Kl4rry committed Jul 1, 2024
1 parent 21064c7 commit 8258bf9
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions crates/ferrite-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -103,6 +104,7 @@ default = [
"lang-javascript",
"lang-json",
"lang-md",
"lang-protobuf",
"lang-python",
"lang-rebase",
"lang-ron",
Expand Down
11 changes: 11 additions & 0 deletions crates/ferrite-core/src/language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ static LANGUAGES: Lazy<HashMap<&'static str, OnceCell<TreeSitterConfig>>> = 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
});

Expand Down Expand Up @@ -345,6 +347,14 @@ fn get_lang_config(name: &str) -> Option<TreeSitterConfig> {
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,
})
}
Expand Down Expand Up @@ -385,6 +395,7 @@ pub fn get_language_from_path(path: impl AsRef<Path>) -> Option<&'static str> {
(Suffix(".zig"), "zig"),
(Suffix(".go"), "go"),
(Suffix(".ts"), "ts"),
(Suffix(".proto"), "protobuf"),
(Name("hyprland.conf"), "hyprlang"),
(Name("COMMIT_EDITMSG"), "git-commit"),
(Name("git-rebase-todo"), "git-rebase"),
Expand Down
2 changes: 2 additions & 0 deletions crates/ferrite-tree-sitter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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"]
Expand Down
2 changes: 2 additions & 0 deletions crates/ferrite-tree-sitter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
58 changes: 58 additions & 0 deletions queries/protobuf/highlights.scm
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions queries/protobuf/injections.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
((comment) @injection.content
(#set! injection.language "comment"))

0 comments on commit 8258bf9

Please sign in to comment.