Sitelet https://github.com/zed-extensions/java/commit/7350ecc29fa031319b17a26f7b610a527bcf28d7
Skip to content

Commit 7350ecc

Browse files
authored
fix(gradle-kts): pin the Kotlin grammar the Kotlin extension ships, so the queries load (#312)
- `extension.toml`: pin `grammars.kotlin` to `1852ea1`, the commit the Kotlin extension uses. - `languages/gradle-kts/highlights.scm` and `outline.scm`: port the patterns above, matching what the Kotlin extension's own queries already do. The Gradle DSL outline patterns are untouched and compile as they are. - `tests/gradle_kts.rs`: compiles every `languages/gradle-kts/*.scm` against `tree-sitter-kotlin` at the pinned commit (new dev-dependency, pinned by git rev to match `extension.toml`). It fails on `main` with the outline error above and passes on this branch, so the next grammar bump that breaks a query fails in `cargo test` instead of in the editor. `cargo test` (all suites) and `cargo fmt --check` pass. `ts_query_ls format` was not run; the edited lines keep the files' existing indentation. Pinning the same commit fixes the clash only while the two extensions stay in step. Each bump in one of them should be followed by the other.
1 parent 5c4b765 commit 7350ecc

6 files changed

Lines changed: 40 additions & 15 deletions

File tree

‎Cargo.lock‎

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,6 @@ zed_extension_api = "0.7.0"
3232
[dev-dependencies]
3333
tree-sitter = "0.26.8"
3434
tree-sitter-java = "0.23.5"
35+
# Same commit as `grammars.kotlin` in extension.toml, so the test compiles the queries Zed loads.
36+
tree-sitter-kotlin = { git = "https://github.com/fwcd/tree-sitter-kotlin", rev = "1852ea17b7f60fb3f9d84e0b1555d56b46b39fb1" }
3537
insta = { version = "1.46", features = ["yaml"] }

‎extension.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ commit = "deb0dcf8c4544f07564060f6e9b9f6e4b0bfc27d"
2424
# extension uses). Bundled so KTS highlighting works without that extension.
2525
[grammars.kotlin]
2626
repository = "https://github.com/fwcd/tree-sitter-kotlin"
27-
commit = "4e909d6cc9ac96b4eaecb3fb538eaca48e9e9ee9"
27+
commit = "1852ea17b7f60fb3f9d84e0b1555d56b46b39fb1"
2828

2929
[language_servers.jdtls]
3030
name = "Eclipse JDT Language Server"

‎languages/gradle-kts/highlights.scm‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133
] @number
134134

135135
[
136-
"null" ; should be highlighted the same as booleans
136+
(null_literal) ; should be highlighted the same as booleans
137137
(boolean_literal)
138138
] @boolean
139139

@@ -275,9 +275,7 @@
275275
"?:"
276276
"!!"
277277
"is"
278-
"!is"
279278
"in"
280-
"!in"
281279
"as"
282280
"as?"
283281
".."
@@ -303,10 +301,10 @@
303301

304302
; NOTE: `interpolated_identifier`s can be highlighted in any way
305303
(string_literal
306-
"$" @punctuation.special
304+
(interpolation_identifier_start) @punctuation.special
307305
(interpolated_identifier) @none)
308306

309307
(string_literal
310-
"${" @punctuation.special
308+
(interpolation_expression_start) @punctuation.special
311309
(interpolated_expression) @none
312-
"}" @punctuation.special)
310+
(interpolation_expression_end) @punctuation.special)

‎languages/gradle-kts/outline.scm‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,12 @@
2222
(simple_identifier) @name) @item
2323

2424
(property_declaration
25-
[
26-
"val"
27-
"var"
28-
] @context
25+
(binding_pattern_kind) @context
2926
(variable_declaration
3027
(simple_identifier) @name)) @item
3128

3229
(property_declaration
33-
[
34-
"val"
35-
"var"
36-
] @context
30+
(binding_pattern_kind) @context
3731
(multi_variable_declaration
3832
(variable_declaration
3933
(simple_identifier) @name) @item))

‎tests/gradle_kts.rs‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use tree_sitter::Query;
2+
3+
/// Zed refuses to load a language whose query names a node the grammar does not have, and the
4+
/// file then renders with no highlighting at all. Every Gradle KTS query must compile against the
5+
/// Kotlin grammar pinned in extension.toml.
6+
#[test]
7+
fn gradle_kts_queries_compile_against_pinned_kotlin_grammar() {
8+
let language = tree_sitter_kotlin::LANGUAGE.into();
9+
let dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("languages/gradle-kts");
10+
let mut checked = 0;
11+
for entry in std::fs::read_dir(&dir).expect("Failed to read languages/gradle-kts") {
12+
let path = entry.expect("Failed to read directory entry").path();
13+
if path.extension().is_some_and(|ext| ext == "scm") {
14+
let source = std::fs::read_to_string(&path).expect("Failed to read query");
15+
Query::new(&language, &source)
16+
.unwrap_or_else(|error| panic!("{} does not compile: {error}", path.display()));
17+
checked += 1;
18+
}
19+
}
20+
assert!(checked > 0, "No queries found in {}", dir.display());
21+
}

0 commit comments

Comments
 (0)