Skip to content

Commit

Permalink
fix(kotlin): add kotlin to missing enums and match statements in crat…
Browse files Browse the repository at this point in the history
…es/lsp and crates/wasm-bindings

fixes getgrit#570
  • Loading branch information
Alex-ley-scrub committed Jan 6, 2025
1 parent 48b276b commit eeab266
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions crates/lsp/src/language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub fn language_id_to_pattern_language(language_id: &str) -> Option<PatternLangu
"css" => Some(PatternLanguage::Css),
"json" | "jsonc" => Some(PatternLanguage::Json),
"java" => Some(PatternLanguage::Java),
"kotlin" => Some(PatternLanguage::Kotlin),
"csharp" => Some(PatternLanguage::CSharp),
"python" => Some(PatternLanguage::Python),
"markdown" => Some(PatternLanguage::MarkdownInline),
Expand Down Expand Up @@ -36,6 +37,7 @@ pub fn target_language_to_language_id(target_language: TargetLanguage) -> &'stat
TargetLanguage::Css(_) => "css",
TargetLanguage::Json(_) => "json",
TargetLanguage::Java(_) => "java",
TargetLanguage::Kotlin(_) => "kotlin",
TargetLanguage::CSharp(_) => "csharp",
TargetLanguage::Python(_) => "python",
TargetLanguage::MarkdownInline(_) => "markdown",
Expand Down
3 changes: 3 additions & 0 deletions crates/wasm-bindings/src/match_pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ static HTML_LANGUAGE: OnceLock<TSLanguage> = OnceLock::new();
static CSS_LANGUAGE: OnceLock<TSLanguage> = OnceLock::new();
static JSON_LANGUAGE: OnceLock<TSLanguage> = OnceLock::new();
static JAVA_LANGUAGE: OnceLock<TSLanguage> = OnceLock::new();
static KOTLIN_LANGUAGE: OnceLock<TSLanguage> = OnceLock::new();
static CSHARP_LANGUAGE: OnceLock<TSLanguage> = OnceLock::new();
static PYTHON_LANGUAGE: OnceLock<TSLanguage> = OnceLock::new();
static MARKDOWN_BLOCK_LANGUAGE: OnceLock<TSLanguage> = OnceLock::new();
Expand Down Expand Up @@ -468,6 +469,7 @@ fn pattern_language_to_path(lang: &PatternLanguage) -> anyhow::Result<String> {
PatternLanguage::Css => Ok("/tree-sitter-css.wasm"),
PatternLanguage::Json => Ok("/tree-sitter-json.wasm"),
PatternLanguage::Java => Ok("/tree-sitter-java.wasm"),
PatternLanguage::Kotlin => Ok("/tree-sitter-kotlin.wasm"),
PatternLanguage::CSharp => Err(anyhow::anyhow!("CSharp wasm is not currently supported")),
PatternLanguage::Python => Ok("/tree-sitter-python.wasm"),
PatternLanguage::MarkdownBlock => Ok("/tree-sitter-markdown-block.wasm"), // def wrong
Expand Down Expand Up @@ -513,6 +515,7 @@ fn get_lang_store(language: &PatternLanguage) -> anyhow::Result<&'static OnceLoc
PatternLanguage::Css => Ok(&CSS_LANGUAGE),
PatternLanguage::Json => Ok(&JSON_LANGUAGE),
PatternLanguage::Java => Ok(&JAVA_LANGUAGE),
PatternLanguage::Kotlin => Ok(&KOTLIN_LANGUAGE),
PatternLanguage::CSharp => Ok(&CSHARP_LANGUAGE),
PatternLanguage::Python => Ok(&PYTHON_LANGUAGE),
PatternLanguage::MarkdownBlock => Ok(&MARKDOWN_BLOCK_LANGUAGE),
Expand Down
7 changes: 5 additions & 2 deletions resources/add_language.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
def main(args: Namespace):
"""Automate the process of adding a new language to the gritql metavariable-grammars."""
language = args.language.lower()
language_upper_case = language.upper()
language_title_case = language.title()
language_rs = LANGUAGE_TEMPLATE_RS.format(
language=language, language_title_case=language_title_case
Expand Down Expand Up @@ -172,8 +173,10 @@ def main(args: Namespace):
2. add `tree-sitter-{language}` to crates/language/Cargo.toml [dependencies] and [features.builtin-parser]
3. add `pub mod {language};` to crates/language/src/lib.rs
4. add `use crate::{language}::{language_title_case}` to crates/language/src/target_language.rs and add it to all enums and match statements
5. add {language} to the `PatternsDirectory` struct in crates/gritmodule/src/patterns_directory.rs add it to all match statements
6. add test cases for {language} in crates/core/src/test.rs
5. add {language} to the `PatternsDirectory` struct in crates/gritmodule/src/patterns_directory.rs and add it to all match statements
6. add {language_title_case} to all match statements in crates/lsp/src/language.rs
7. add {language_upper_case}_LANGUAGE as a static in crates/wasm-bindings/src/match_pattern.rs and add it to all match statements
8. add test cases for {language} in crates/core/src/test.rs
""")


Expand Down

0 comments on commit eeab266

Please sign in to comment.