Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Use tree-sitter-go fork (#64562)

Nick Dell'Osa2c335b81dc94
diff --git a/Cargo.lock b/Cargo.lock
index 3b572384048..2793cf4f822 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -18911,8 +18911,7 @@ dependencies = [
[[package]]
name = "tree-sitter-go"
version = "0.25.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c8560a4d2f835cc0d4d2c2e03cbd0dde2f6114b43bc491164238d333e28b16ea"
+source = "git+https://github.com/zed-industries/tree-sitter-go?rev=6862a49e3c5a7567a6c576420e9a8f944e198a85#6862a49e3c5a7567a6c576420e9a8f944e198a85"
dependencies = [
"cc",
"tree-sitter-language",
diff --git a/Cargo.toml b/Cargo.toml
index 0f5c5dd6abb..e3b047aad65 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -948,7 +948,7 @@ tree-sitter-diff = "0.1.0"
tree-sitter-elixir = "0.3"
tree-sitter-embedded-template = "0.23.0"
tree-sitter-gitcommit = { git = "https://github.com/zed-industries/tree-sitter-git-commit", rev = "88309716a69dd13ab83443721ba6e0b491d37ee9" }
-tree-sitter-go = "0.25"
+tree-sitter-go = { git = "https://github.com/zed-industries/tree-sitter-go", rev = "6862a49e3c5a7567a6c576420e9a8f944e198a85" }
tree-sitter-go-mod = { git = "https://github.com/camdencheek/tree-sitter-go-mod", rev = "2e886870578eeba1927a2dc4bd2e2b3f598c5f9a", package = "tree-sitter-gomod" }
tree-sitter-gowork = { git = "https://github.com/zed-industries/tree-sitter-go-work", rev = "acb0617bf7f4fda02c6217676cc64acb89536dc7" }
tree-sitter-heex = { git = "https://github.com/zed-industries/tree-sitter-heex", rev = "1dd45142fbb05562e35b2040c6129c9bca346592" }
diff --git a/crates/grammars/src/go/highlights.scm b/crates/grammars/src/go/highlights.scm
index 25ec7cb18d4..8e670cc06a1 100644
--- a/crates/grammars/src/go/highlights.scm
+++ b/crates/grammars/src/go/highlights.scm
@@ -11,6 +11,9 @@
"int8" "int16" "int32" "int64" "rune" "string" "uint" "uint8" "uint16" "uint32" "uint64"
"uintptr"))
+(type_parameter_declaration
+ name: (identifier) @type)
+
(field_identifier) @property
(package_identifier) @namespace
diff --git a/crates/languages/src/go.rs b/crates/languages/src/go.rs
index 0cf9bf42f71..2d3fd4f6ccc 100644
--- a/crates/languages/src/go.rs
+++ b/crates/languages/src/go.rs
@@ -2150,6 +2150,36 @@ mod tests {
}
}
+ #[gpui::test]
+ async fn test_go_method_type_parameters_highlighted_as_type() {
+ let language = go_language();
+
+ let theme =
+ SyntaxTheme::new_test([("type", Hsla::default()), ("variable", Hsla::default())]);
+ language.set_theme(&theme);
+
+ let grammar = language.grammar().unwrap();
+ let highlight_type = grammar.highlight_id_for_name("type").unwrap();
+
+ // The `T` inside `[T any]` is a method type parameter declaration. It is
+ // only parsed as such by the regenerated tree-sitter-go fork; upstream
+ // 0.25 has no `type_parameters` field on `method_declaration`.
+ let source = "package main\n\ntype Recv struct{}\n\nfunc (r Recv) Do[T any](value T) {}\n";
+ let type_parameter_offset = source.find("[T any]").expect("type parameter present") + 1;
+
+ let runs = language.highlight_text(&Rope::from(source), 0..source.len());
+ let type_parameter_highlight = runs
+ .into_iter()
+ .find(|(range, _)| range.contains(&type_parameter_offset))
+ .map(|(_, highlight_id)| highlight_id);
+
+ assert_eq!(
+ type_parameter_highlight,
+ Some(highlight_type),
+ "method type parameter should be highlighted as a type, not a variable"
+ );
+ }
+
#[test]
fn test_extract_subtest_name() {
// Interpreted string literal