From f05351e4574b123660f151e4885c881990284521 Mon Sep 17 00:00:00 2001 From: Axel Kappel <69117984+Kl4rry@users.noreply.github.com> Date: Fri, 31 May 2024 21:18:41 +0200 Subject: [PATCH] add ini language --- Cargo.lock | 10 +++++++++ crates/ferrite-core/Cargo.toml | 2 ++ crates/ferrite-core/src/language.rs | 32 +++++++++++++++++++++++++++ crates/ferrite-tree-sitter/Cargo.toml | 2 ++ crates/ferrite-tree-sitter/src/lib.rs | 2 ++ queries/ini/highlights.scm | 6 +++++ src/main.rs | 1 + 7 files changed, 55 insertions(+) create mode 100644 queries/ini/highlights.scm diff --git a/Cargo.lock b/Cargo.lock index fd6be90..3678ef1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -998,6 +998,7 @@ dependencies = [ "tree-sitter-go", "tree-sitter-html", "tree-sitter-hyprlang", + "tree-sitter-ini", "tree-sitter-javascript", "tree-sitter-json", "tree-sitter-md", @@ -3183,6 +3184,15 @@ dependencies = [ "tree-sitter", ] +[[package]] +name = "tree-sitter-ini" +version = "0.0.1" +source = "git+https://github.com/justinmk/tree-sitter-ini?rev=4d247fb876b4ae6b347687de4a179511bf67fcbc#4d247fb876b4ae6b347687de4a179511bf67fcbc" +dependencies = [ + "cc", + "tree-sitter", +] + [[package]] name = "tree-sitter-javascript" version = "0.20.0" diff --git a/crates/ferrite-core/Cargo.toml b/crates/ferrite-core/Cargo.toml index aec4e6d..79bd096 100644 --- a/crates/ferrite-core/Cargo.toml +++ b/crates/ferrite-core/Cargo.toml @@ -65,6 +65,7 @@ lang-glsl = ["ferrite-tree-sitter/lang-glsl"] lang-go = ["ferrite-tree-sitter/lang-go"] lang-html = ["ferrite-tree-sitter/lang-html"] lang-hyprlang = ["ferrite-tree-sitter/lang-hyprlang"] +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"] @@ -89,6 +90,7 @@ default = [ "lang-go", "lang-html", "lang-hyprlang", + "lang-ini", "lang-json", "lang-md", "lang-python", diff --git a/crates/ferrite-core/src/language.rs b/crates/ferrite-core/src/language.rs index ae3f094..8aa7e30 100644 --- a/crates/ferrite-core/src/language.rs +++ b/crates/ferrite-core/src/language.rs @@ -86,6 +86,8 @@ static LANGUAGES: Lazy>> = Lazy:: langs.insert("go", OnceCell::new()); #[cfg(feature = "lang-typescript")] langs.insert("typescript", OnceCell::new()); + #[cfg(feature = "lang-ini")] + langs.insert("ini", OnceCell::new()); langs }); @@ -284,6 +286,14 @@ fn get_lang_config(name: &str) -> Option { include_str!("../../../queries/typescript/injections.scm"), include_str!("../../../queries/typescript/locals.scm"), ), + #[cfg(feature = "lang-ini")] + "ini" => LanguageConfig::new( + "ini", + ferrite_tree_sitter::tree_sitter_ini::language(), + include_str!("../../../queries/ini/highlights.scm"), + "", + "", + ), _ => return None, }) } @@ -372,6 +382,28 @@ pub fn get_language_from_path(path: impl AsRef) -> Option<&'static str> { (Name(".zprofile"), "bash"), (Name(".zshrc"), "bash"), (Name("PKGBUILD"), "bash"), + // ini + (Suffix(".ini"), "ini"), + (Suffix(".service"), "ini"), + (Suffix(".automount"), "ini"), + (Suffix(".device"), "ini"), + (Suffix(".mount"), "ini"), + (Suffix(".path"), "ini"), + (Suffix(".service"), "ini"), + (Suffix(".slice"), "ini"), + (Suffix(".socket"), "ini"), + (Suffix(".swap"), "ini"), + (Suffix(".target"), "ini"), + (Suffix(".timer"), "ini"), + (Suffix(".container"), "ini"), + (Suffix(".volume"), "ini"), + (Suffix(".kube"), "ini"), + (Suffix(".network"), "ini"), + (Suffix(".properties"), "ini"), + (Suffix(".cfg"), "ini"), + (Suffix(".directory"), "ini"), + (Name(".editorconfig"), "ini"), + (Name("rclone.conf"), "ini"), ] }); diff --git a/crates/ferrite-tree-sitter/Cargo.toml b/crates/ferrite-tree-sitter/Cargo.toml index 3754821..655f69c 100644 --- a/crates/ferrite-tree-sitter/Cargo.toml +++ b/crates/ferrite-tree-sitter/Cargo.toml @@ -18,6 +18,7 @@ tree-sitter-glsl = { git = "https://github.com/theHamsta/tree-sitter-glsl", rev tree-sitter-go = { git = "https://github.com/tree-sitter/tree-sitter-go", rev = "64457ea6b73ef5422ed1687178d4545c3e91334a", optional = true } tree-sitter-html = { version = "0.19.0", optional = true } tree-sitter-hyprlang = { git = "https://github.com/tree-sitter-grammars/tree-sitter-hyprlang", rev = "27af9b74acf89fa6bed4fb8cb8631994fcb2e6f3", optional = true } +tree-sitter-ini = { git = "https://github.com/justinmk/tree-sitter-ini", rev = "4d247fb876b4ae6b347687de4a179511bf67fcbc", optional = true } 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 } @@ -44,6 +45,7 @@ lang-glsl = ["dep:tree-sitter-glsl"] lang-go = ["dep:tree-sitter-go"] lang-html = ["dep:tree-sitter-html"] lang-hyprlang = ["dep:tree-sitter-hyprlang"] +lang-ini = ["dep:tree-sitter-ini"] lang-javascript = ["dep:tree-sitter-javascript"] lang-json = ["dep:tree-sitter-json"] lang-md = ["dep:tree-sitter-md"] diff --git a/crates/ferrite-tree-sitter/src/lib.rs b/crates/ferrite-tree-sitter/src/lib.rs index 0b75900..6c1e207 100644 --- a/crates/ferrite-tree-sitter/src/lib.rs +++ b/crates/ferrite-tree-sitter/src/lib.rs @@ -24,6 +24,8 @@ pub use tree_sitter_go; pub use tree_sitter_html; #[cfg(feature = "lang-hyprlang")] pub use tree_sitter_hyprlang; +#[cfg(feature = "lang-ini")] +pub use tree_sitter_ini; #[cfg(feature = "lang-javascript")] pub use tree_sitter_javascript; #[cfg(feature = "lang-json")] diff --git a/queries/ini/highlights.scm b/queries/ini/highlights.scm new file mode 100644 index 0000000..6277a06 --- /dev/null +++ b/queries/ini/highlights.scm @@ -0,0 +1,6 @@ +(section_name) @namespace + +(setting_name) @keyword +(setting_value) @string + +(comment) @comment diff --git a/src/main.rs b/src/main.rs index e1be5d7..ebea3be 100644 --- a/src/main.rs +++ b/src/main.rs @@ -61,6 +61,7 @@ fn main() -> Result { const GB: u64 = 1_000_000_000; if log_file.metadata()?.len() > GB { log_file.set_len(0)?; + tracing::warn!("Log file was truncated as it reached 1Gb in size"); } let var = args