From 533a3b10b24f92e8aeaacb2a254c88d49f8f2786 Mon Sep 17 00:00:00 2001 From: "dheeraj.reddy" Date: Fri, 10 Nov 2023 11:39:42 +0530 Subject: [PATCH] feat: Add support for C/C++ Add support for C/C++ by relying on tree-sitter-c and tree-sitter-cpp respectively. --- Cargo.lock | 20 ++++++++++++ crates/tabby-common/assets/languages.toml | 37 ++++++++++++++++++++++ crates/tabby-scheduler/Cargo.toml | 4 ++- crates/tabby-scheduler/src/dataset.rs | 2 +- crates/tabby-scheduler/src/dataset/tags.rs | 22 +++++++++++++ website/docs/programming-languages.md | 1 - 6 files changed, 83 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ecbe2ef20991..2d57db31ec13 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4651,6 +4651,8 @@ dependencies = [ "tokio", "tracing", "tracing-test", + "tree-sitter-c", + "tree-sitter-cpp", "tree-sitter-go", "tree-sitter-java", "tree-sitter-python", @@ -5486,6 +5488,24 @@ dependencies = [ "regex", ] +[[package]] +name = "tree-sitter-c" +version = "0.20.6" +source = "git+https://github.com/tree-sitter/tree-sitter-c/?rev=212a80f#212a80f86452bb1316324fa0db730cf52f29e05a" +dependencies = [ + "cc", + "tree-sitter", +] + +[[package]] +name = "tree-sitter-cpp" +version = "0.20.3" +source = "git+https://github.com/tree-sitter/tree-sitter-cpp?rev=a714740#a71474021410973b29bfe99440d57bcd750246b1" +dependencies = [ + "cc", + "tree-sitter", +] + [[package]] name = "tree-sitter-go" version = "0.20.0" diff --git a/crates/tabby-common/assets/languages.toml b/crates/tabby-common/assets/languages.toml index d6e5b9f35c29..b37c3cf4ca0a 100644 --- a/crates/tabby-common/assets/languages.toml +++ b/crates/tabby-common/assets/languages.toml @@ -89,3 +89,40 @@ top_level_keywords = [ "rescue", "self", ] + +[[config]] +languages = ["c"] +line_comment = "//" +top_level_keywords = [ + "const", + "enum", + "extern", + "inline", + "register", + "static", + "struct", + "typedef", + "union", + "volatile", +] + +[[config]] +languages = ["cpp"] +line_comment = "//" +top_level_keywords = [ + "auto", + "class", + "const", + "concept", + "enum", + "extern", + "inline", + "namespace", + "register", + "static", + "struct", + "template", + "typedef", + "union", + "volatile", +] diff --git a/crates/tabby-scheduler/Cargo.toml b/crates/tabby-scheduler/Cargo.toml index e0f49e85ed90..c4f161890013 100644 --- a/crates/tabby-scheduler/Cargo.toml +++ b/crates/tabby-scheduler/Cargo.toml @@ -20,7 +20,9 @@ tree-sitter-java = "0.20.2" tree-sitter-rust = "0.20.3" tree-sitter-typescript = "0.20.3" tree-sitter-go = "0.20.0" -tree-sitter-ruby= "0.20.0" +tree-sitter-ruby = "0.20.0" +tree-sitter-c = { git = "https://github.com/tree-sitter/tree-sitter-c/", rev = "212a80f" } +tree-sitter-cpp = { git = "https://github.com/tree-sitter/tree-sitter-cpp", rev = "a714740" } ignore = "0.4.20" kdam = { version = "0.5.0" } requirements = "0.3.0" diff --git a/crates/tabby-scheduler/src/dataset.rs b/crates/tabby-scheduler/src/dataset.rs index 4cd4ca007a33..8a94db8155b0 100644 --- a/crates/tabby-scheduler/src/dataset.rs +++ b/crates/tabby-scheduler/src/dataset.rs @@ -149,7 +149,7 @@ lazy_static! { ("csharp", vec!["cs"]), ( "cpp", - vec!["cpp", "hpp", "c++", "h++", "cc", "hh", "C", "H"], + vec!["cpp", "hpp", "c++", "h++", "cc", "hh", "C", "H", "tcc"], ), ("css", vec!["css"]), ("dockerfile", vec!["Dockerfile"]), diff --git a/crates/tabby-scheduler/src/dataset/tags.rs b/crates/tabby-scheduler/src/dataset/tags.rs index 7fbf87da68d5..4a6fd714e341 100644 --- a/crates/tabby-scheduler/src/dataset/tags.rs +++ b/crates/tabby-scheduler/src/dataset/tags.rs @@ -106,6 +106,28 @@ lazy_static! { .unwrap(), ), ), + ( + "c", + TagsConfigurationSync( + TagsConfiguration::new( + tree_sitter_c::language(), + tree_sitter_c::TAGS_QUERY, + "", + ) + .unwrap(), + ), + ), + ( + "cpp", + TagsConfigurationSync( + TagsConfiguration::new( + tree_sitter_cpp::language(), + tree_sitter_cpp::TAGS_QUERY, + "", + ) + .unwrap(), + ), + ), ]) }; } diff --git a/website/docs/programming-languages.md b/website/docs/programming-languages.md index 23a11a8e9e9d..926c1fadcc43 100644 --- a/website/docs/programming-languages.md +++ b/website/docs/programming-languages.md @@ -33,7 +33,6 @@ For an actual example of an issue or pull request adding the above support, plea | Language | Stop Words (time to contribute: <5 min) | Repository Context (time to contribute: <1 hr) | | :------: | :-------------------------------------: | :--------------------------------------------: | -| C/C++ | 🚫 | 🚫 | | C# | 🚫 | 🚫 | | CSS | 🚫 | 🚫 | | Haskell | 🚫 | 🚫 |