From b1d0eb4ffea45ac919e14d2be37bdbcec51f5e09 Mon Sep 17 00:00:00 2001 From: Johan von Forstner <5310424+johan12345@users.noreply.github.com> Date: Fri, 15 Dec 2023 15:01:40 +0100 Subject: [PATCH] add support for Kotlin language (#52) --- Cargo.lock | 11 +++++++++++ crates/llm-ls/Cargo.toml | 1 + crates/llm-ls/src/document.rs | 7 +++++++ crates/llm-ls/src/language_id.rs | 3 +++ 4 files changed, 22 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index ad417b0..c7185c2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -997,6 +997,7 @@ dependencies = [ "tree-sitter-java", "tree-sitter-javascript", "tree-sitter-json", + "tree-sitter-kotlin", "tree-sitter-lua", "tree-sitter-md", "tree-sitter-objc", @@ -2424,6 +2425,16 @@ dependencies = [ "tree-sitter", ] +[[package]] +name = "tree-sitter-kotlin" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b5f367466210220a194a2d8831fc12d15aa13305e7bcdf2dba47714aa328e86" +dependencies = [ + "cc", + "tree-sitter", +] + [[package]] name = "tree-sitter-lua" version = "0.0.19" diff --git a/crates/llm-ls/Cargo.toml b/crates/llm-ls/Cargo.toml index cdc75cc..62bb5b1 100644 --- a/crates/llm-ls/Cargo.toml +++ b/crates/llm-ls/Cargo.toml @@ -39,6 +39,7 @@ tree-sitter-html = "0.19" tree-sitter-java = "0.20" tree-sitter-javascript = "0.20" tree-sitter-json = "0.20" +tree-sitter-kotlin = "0.3.1" tree-sitter-lua = "0.0.19" tree-sitter-md = "0.1" tree-sitter-objc = "3" diff --git a/crates/llm-ls/src/document.rs b/crates/llm-ls/src/document.rs index 557a4f5..4b1bdae 100644 --- a/crates/llm-ls/src/document.rs +++ b/crates/llm-ls/src/document.rs @@ -85,6 +85,13 @@ fn get_parser(language_id: LanguageId) -> Result { .map_err(internal_error)?; Ok(parser) } + LanguageId::Kotlin => { + let mut parser = Parser::new(); + parser + .set_language(tree_sitter_kotlin::language()) + .map_err(internal_error)?; + Ok(parser) + } LanguageId::Lua => { let mut parser = Parser::new(); parser diff --git a/crates/llm-ls/src/language_id.rs b/crates/llm-ls/src/language_id.rs index c311958..31ce3d9 100644 --- a/crates/llm-ls/src/language_id.rs +++ b/crates/llm-ls/src/language_id.rs @@ -15,6 +15,7 @@ pub(crate) enum LanguageId { JavaScript, JavaScriptReact, Json, + Kotlin, Lua, Markdown, ObjectiveC, @@ -44,6 +45,7 @@ impl fmt::Display for LanguageId { Self::JavaScript => write!(f, "javascript"), Self::JavaScriptReact => write!(f, "javascriptreact"), Self::Json => write!(f, "json"), + Self::Kotlin => write!(f, "kotlin"), Self::Lua => write!(f, "lua"), Self::Markdown => write!(f, "markdown"), Self::ObjectiveC => write!(f, "objective-c"), @@ -84,6 +86,7 @@ impl From<&str> for LanguageId { "javascript" => Self::JavaScript, "javascriptreact" => Self::JavaScriptReact, "json" => Self::Json, + "kotlin" => Self::Kotlin, "lua" => Self::Lua, "markdown" => Self::Markdown, "objective-c" => Self::ObjectiveC,