From ee17ba62f51ba35aa435dee7750f98ba1d665810 Mon Sep 17 00:00:00 2001 From: Suraj Ghimire Date: Sun, 26 Jun 2022 10:35:03 +0530 Subject: [PATCH] add syntax highlighting support for Bash and Zig Signed-off-by: Suraj Ghimire --- Cargo.lock | 20 ++++++++++++++++++++ lapce-core/Cargo.toml | 5 +++++ lapce-core/src/language.rs | 32 ++++++++++++++++++++++++++++++++ lapce-ui/Cargo.toml | 9 ++++++--- 4 files changed, 63 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c0b1d75c..ed62a35f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2204,6 +2204,7 @@ dependencies = [ "strum_macros 0.24.0", "thiserror", "tree-sitter", + "tree-sitter-bash", "tree-sitter-c", "tree-sitter-cpp", "tree-sitter-css", @@ -2231,6 +2232,7 @@ dependencies = [ "tree-sitter-swift", "tree-sitter-toml", "tree-sitter-typescript", + "tree-sitter-zig", "xi-rope", ] @@ -4548,6 +4550,15 @@ dependencies = [ "regex", ] +[[package]] +name = "tree-sitter-bash" +version = "0.19.0" +source = "git+https://github.com/syntacti/tree-sitter-bash?branch=master#ba3adca745943b71b0c84bb4e4977788cc6a867b" +dependencies = [ + "cc", + "tree-sitter", +] + [[package]] name = "tree-sitter-c" version = "0.20.1" @@ -4806,6 +4817,15 @@ dependencies = [ "tree-sitter", ] +[[package]] +name = "tree-sitter-zig" +version = "0.0.1" +source = "git+https://github.com/maxxnino/tree-sitter-zig?branch=main#8d3224c3bd0890fe08358886ebf54fca2ed448a6" +dependencies = [ + "cc", + "tree-sitter", +] + [[package]] name = "try-lock" version = "0.2.3" diff --git a/lapce-core/Cargo.toml b/lapce-core/Cargo.toml index 8b740582..232c7416 100644 --- a/lapce-core/Cargo.toml +++ b/lapce-core/Cargo.toml @@ -42,6 +42,9 @@ tree-sitter-scss = { git = "https://github.com/VixieTSQ/tree-sitter-scss", versi tree-sitter-hare = { version = "0.20.7", optional = true } # switch to upstream version after this is merged https://github.com/tree-sitter/tree-sitter-css/pull/22 tree-sitter-css = { git = "https://github.com/syntacti/tree-sitter-css", branch = "master", optional = true } +tree-sitter-zig = { git = "https://github.com/maxxnino/tree-sitter-zig", branch = "main", optional = true } +# switch to upstream version after this is merged https://github.com/tree-sitter/tree-sitter-bash/pull/120 +tree-sitter-bash = { git = "https://github.com/syntacti/tree-sitter-bash", branch = "master", optional = true } lsp-types = { version = "0.89.2", features = ["proposed"] } xi-rope = { git = "https://github.com/lapce/xi-editor", features = ["serde"] } lapce-rpc = { path = "../lapce-rpc" } @@ -77,3 +80,5 @@ lang-hcl = ["dep:tree-sitter-hcl"] lang-scss = ["dep:tree-sitter-scss"] lang-hare = ["dep:tree-sitter-hare"] lang-css = ["dep:tree-sitter-css"] +lang-zig = ["dep:tree-sitter-zig"] +lang-bash = ["dep:tree-sitter-bash"] diff --git a/lapce-core/src/language.rs b/lapce-core/src/language.rs index 34226c7a..7b754f25 100644 --- a/lapce-core/src/language.rs +++ b/lapce-core/src/language.rs @@ -154,6 +154,10 @@ pub enum LapceLanguage { Hare, #[cfg(feature = "lang-css")] Css, + #[cfg(feature = "lang-zig")] + Zig, + #[cfg(feature = "lang-bash")] + Bash, } // NOTE: Elements in the array must be in the same order as the enum variants of @@ -472,6 +476,26 @@ pub enum LapceLanguage { code_lens: (DEFAULT_CODE_LENS_LIST, DEFAULT_CODE_LENS_IGNORE_LIST), extensions: &["css"], }, + #[cfg(feature = "lang-zig")] + SyntaxProperties { + id: LapceLanguage::Zig, + language: tree_sitter_zig::language, + highlight: tree_sitter_zig::HIGHLIGHTS_QUERY, + comment: "//", + indent: " ", + code_lens: (DEFAULT_CODE_LENS_LIST, DEFAULT_CODE_LENS_IGNORE_LIST), + extensions: &["zig"], + }, + #[cfg(feature = "lang-bash")] + SyntaxProperties { + id: LapceLanguage::Bash, + language: tree_sitter_bash::language, + highlight: tree_sitter_bash::HIGHLIGHTS_QUERY, + comment: "#", + indent: " ", + code_lens: (DEFAULT_CODE_LENS_LIST, DEFAULT_CODE_LENS_IGNORE_LIST), + extensions: &["sh", "bash"], + }, ]; impl LapceLanguage { @@ -739,4 +763,12 @@ fn test_hare_lang() { fn test_css_lang() { assert_language(LapceLanguage::Css, &["css"]); } + #[cfg(feature = "lang-zig")] + fn test_zig_lang() { + assert_language(LapceLanguage::Zig, &["zig"]); + } + #[cfg(feature = "lang-bash")] + fn test_bash_lang() { + assert_language(LapceLanguage::Bash, &["sh", "bash"]); + } } diff --git a/lapce-ui/Cargo.toml b/lapce-ui/Cargo.toml index 768e206f..15a2e09f 100644 --- a/lapce-ui/Cargo.toml +++ b/lapce-ui/Cargo.toml @@ -87,8 +87,9 @@ all-languages = [ "lang-hcl", "lang-scss", "lang-hare", - "lang-css" - + "lang-css", + "lang-zig", + "lang-bash", ] lang-rust = ["lapce-core/lang-rust"] @@ -116,4 +117,6 @@ lang-haxe = ["lapce-core/lang-haxe"] lang-hcl = ["lapce-core/lang-hcl"] lang-scss = ["lapce-core/lang-scss"] lang-hare = ["lapce-core/lang-hare"] -lang-css = ["lapce-core/lang-css"] \ No newline at end of file +lang-css = ["lapce-core/lang-css"] +lang-zig = ["lapce-core/lang-zig"] +lang-bash = ["lapce-core/lang-bash"]