Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 570 kotlin support #573

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2862d27
feat(kotlin): add 'tree-sitter-kotlin' submodule
Alex-ley-scrub Oct 31, 2024
f57def5
feat(kotlin): update "vendor/tree-sitter-gritql" submodule commit and…
Alex-ley-scrub Oct 31, 2024
b7e617d
feat: copy kotlin grammar.js into 'metavariable-grammars/kotlin-metav…
Alex-ley-scrub Nov 2, 2024
219d8be
fix(kotlin-metavariable-grammar.js): add `grit_metavariable` in a bun…
Alex-ley-scrub Nov 8, 2024
56fd085
fix: copy "resources/language-submodules/tree-sitter-kotlin/" -> "res…
Alex-ley-scrub Nov 8, 2024
05448c3
fix(edit_grammars.mjs): add kotlin and fix `treeSitterGenerate()`
Alex-ley-scrub Nov 8, 2024
5d1dd0e
fix(kotlin-metavariable-grammar.js): add missing grit_metavariable co…
Alex-ley-scrub Nov 8, 2024
22a5a8f
fix(language-metavariables/tree-sitter-kotlin): update with 'resource…
Alex-ley-scrub Nov 8, 2024
23ea64e
fix: add script to automate adding a new language to the gritql metav…
Alex-ley-scrub Nov 9, 2024
28f3233
feat(kotlin): add kotlin.rs with `impl Language for Kotlin` and add `…
Alex-ley-scrub Nov 9, 2024
48b276b
fix(patterns_directory.rs): add kotlin to the `PatternsDirectory` str…
Alex-ley-scrub Nov 9, 2024
eeab266
fix(kotlin): add kotlin to missing enums and match statements in crat…
Alex-ley-scrub Nov 9, 2024
fb103e2
test(apply): add a couple of js array / py list append query/operatio…
Alex-ley-scrub Nov 10, 2024
90f250d
test(apply): add some basic string equivalence tests for kotlin and p…
Alex-ley-scrub Nov 15, 2024
d4e8689
test(core): add a bunch of kotlin metavariable tests that fail becaus…
Alex-ley-scrub Nov 15, 2024
f04d8f0
test(language/src): add more snippet tests for kotlin, java, javascri…
Alex-ley-scrub Nov 15, 2024
4247cbd
fix(node_with_source): add `print_node_tree()` method on `NodeWithSou…
Alex-ley-scrub Nov 15, 2024
62e5ec8
fix(kotlin-metavariable-grammar): try to implement it more like the p…
Alex-ley-scrub Nov 15, 2024
3b99c9c
fix(tree-sitter-kotlin/grammar.js): remove unecessary comments
Alex-ley-scrub Nov 15, 2024
b60b0ef
fix: clippy warnings
Alex-ley-scrub Jan 6, 2025
77684c2
fix(kotlin-metavariable-grammar): improve `function_declaration` matc…
Alex-ley-scrub Jan 6, 2025
3005a0c
fix(kotlin-metavariable-grammar): improve `property_declaration` and …
Alex-ley-scrub Jan 6, 2025
5da1d43
fix(core/src/test): typos/errors in patterns
Alex-ley-scrub Jan 6, 2025
3e785c9
fix(kotlin-metavariable-grammar): improve `import_header` matching
Alex-ley-scrub Jan 7, 2025
72f7379
fix(kotlin-metavariable-grammar): improve `value_arguments` and `call…
Alex-ley-scrub Jan 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,6 @@
[submodule "resources/language-submodules/tree-sitter-php"]
path = resources/language-submodules/tree-sitter-php
url = https://github.com/tree-sitter/tree-sitter-php
[submodule "resources/language-submodules/tree-sitter-kotlin"]
path = resources/language-submodules/tree-sitter-kotlin
url = https://github.com/fwcd/tree-sitter-kotlin
13 changes: 11 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions crates/cli_bin/fixtures/kotlin_examples/build.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// https://github.com/actions/runner-images/blob/main/README.md#available-images
val validImages = listOf(
"ubuntu-20.04",
"ubuntu-latest",
"""ubuntu-latest""",
"ubuntu-24.04",
)

fun hi(name: String) = "hi " + name
7 changes: 7 additions & 0 deletions crates/cli_bin/fixtures/python_examples/build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# https://github.com/actions/runner-images/blob/main/README.md#available-images
steps = [
"ubuntu-latest",
'ubuntu-latest',
r"ubuntu-latest",
"""ubuntu-latest""",
]
128 changes: 128 additions & 0 deletions crates/cli_bin/tests/apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2852,6 +2852,68 @@ fn apply_stdin_simple() -> Result<()> {
Ok(())
}

/// simple stdin example from documentation but with js array append query/operation
#[test]
fn apply_stdin_js_array_append() -> Result<()> {
let (_temp_dir, fixture_dir) = get_fixture("limit_files", false)?;

let input_file = r#"const allLanguages = ["python", "java",]"#;
let expected_output = r#"const allLanguages = ["python", "java", "kotlin",]"#;

let mut cmd = get_test_cmd()?;
cmd.arg("apply")
.arg(r#"`const allLanguages = [$langs]` where { $langs += `"kotlin",` }"#)
.arg("--stdin")
.arg("--lang")
.arg("js")
.current_dir(&fixture_dir);

cmd.write_stdin(String::from_utf8(input_file.into())?);

let result = cmd.output()?;

let stderr = String::from_utf8(result.stderr)?;
println!("stderr: {:?}", stderr);
let stdout = String::from_utf8(result.stdout)?;
println!("stdout: {:?}", stdout);

assert!(result.status.success(), "Command should have succeeded");
assert!(stdout.contains(expected_output));

Ok(())
}

/// simple stdin example from documentation but with python list append query/operation
morgante marked this conversation as resolved.
Show resolved Hide resolved
#[test]
fn apply_stdin_python_list_append() -> Result<()> {
let (_temp_dir, fixture_dir) = get_fixture("limit_files", false)?;

let input_file = r#"all_languages = ["python", "java"]"#;
let expected_output = r#"all_languages = ["python", "java", "kotlin",]"#;

let mut cmd = get_test_cmd()?;
cmd.arg("apply")
.arg(r#"`all_languages = [$langs]` where { $langs += `"kotlin",` }"#)
.arg("--stdin")
.arg("--lang")
.arg("py")
.current_dir(&fixture_dir);

cmd.write_stdin(String::from_utf8(input_file.into())?);

let result = cmd.output()?;

let stderr = String::from_utf8(result.stderr)?;
println!("stderr: {:?}", stderr);
let stdout = String::from_utf8(result.stdout)?;
println!("stdout: {:?}", stdout);

assert!(result.status.success(), "Command should have succeeded");
assert!(stdout.contains(expected_output));

Ok(())
}

/// simple stdin example from documentation, but using a language alias
#[test]
fn apply_stdin_with_lang_alias() -> Result<()> {
Expand Down Expand Up @@ -3084,6 +3146,72 @@ fn apply_to_yaml_with_multiple_equivalent_strings() -> Result<()> {
Ok(())
}

/// test that we can apply to a kotlin file containing equivalent strings
/// but with different formatting/representations (double quotes vs triple double quotes)
#[test]
fn apply_to_kotlin_with_multiple_equivalent_strings() -> Result<()> {
let (_temp_dir, fixture_dir) = get_fixture("kotlin_examples", false)?;

let mut cmd = get_test_cmd()?;
cmd.arg("apply")
.arg(r#"`"ubuntu-latest"` => `"ubuntu-22.04"`"#)
.arg("build.kt")
.arg("--lang=kotlin")
.arg("--force")
.current_dir(&fixture_dir);

let result = cmd.output()?;

let stderr = String::from_utf8(result.stderr)?;
println!("stderr: {:?}", stderr);
let stdout = String::from_utf8(result.stdout)?;
println!("stdout: {:?}", stdout);

assert!(result.status.success(), "Command failed");
// Read back the build.yml file to ensure it was processed correctly
let target_file = fixture_dir.join("build.kt");
let content: String = fs_err::read_to_string(target_file)?;
assert_snapshot!(content);

// ensure all equivalent strings were replaced
assert!(stdout.contains("Processed 1 files and found 2 matches"));

Ok(())
}

/// test that we can apply to a python file containing equivalent strings
/// but with different formatting/representations (single quotes vs double quotes vs triple double quotes)
#[test]
fn apply_to_python_with_multiple_equivalent_strings() -> Result<()> {
let (_temp_dir, fixture_dir) = get_fixture("python_examples", false)?;

let mut cmd = get_test_cmd()?;
cmd.arg("apply")
.arg(r#"`"ubuntu-latest"` => `"ubuntu-22.04"`"#)
.arg("build.py")
.arg("--lang=python")
.arg("--force")
.current_dir(&fixture_dir);

let result = cmd.output()?;

let stderr = String::from_utf8(result.stderr)?;
println!("stderr: {:?}", stderr);
let stdout = String::from_utf8(result.stdout)?;
println!("stdout: {:?}", stdout);

assert!(result.status.success(), "Command failed");
// Read back the build.yml file to ensure it was processed correctly
let target_file = fixture_dir.join("build.py");
let content: String = fs_err::read_to_string(target_file)?;
assert_snapshot!(content);

// ensure all equivalent strings were replaced
assert!(stdout.contains("Processed 1 files and found 4 matches"));

Ok(())
}

/// Ban multiple stdin paths
#[test]
fn apply_stdin_two_paths() -> Result<()> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
source: crates/cli_bin/tests/apply.rs
expression: content
---
// https://github.com/actions/runner-images/blob/main/README.md#available-images
val validImages = listOf(
"ubuntu-20.04",
"ubuntu-22.04",
"ubuntu-22.04",
"ubuntu-24.04",
)

fun hi(name: String) = "hi " + name
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
source: crates/cli_bin/tests/apply.rs
expression: content
---
# https://github.com/actions/runner-images/blob/main/README.md#available-images
steps = [
"ubuntu-22.04",
"ubuntu-22.04",
"ubuntu-22.04",
"ubuntu-22.04",
]
Loading
Loading