Skip to content

Commit 48c4a51

Browse files
committed
refactor(symbol): clean up label_for_symbol to match JDTLS output
Remove handlers for symbol kinds that JDTLS workspace/symbol never returns (Constructor, Field, Constant, EnumMember, Variable, Package). Deduplicate Class/Interface/Enum into a single match arm. Add README section documenting project symbol search and CamelCase fuzzy matching. JDTLS WorkspaceSymbolHandler only searches type names (Class, Interface, Enum, Annotation) and optionally method names when includeSourceMethodDeclarations is enabled: https://github.com/eclipse-jdtls/eclipse.jdt.ls/blob/main/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/WorkspaceSymbolHandler.java Zed only calls label_for_symbol for workspace/symbol results, not textDocument/documentSymbol: https://github.com/zed-industries/zed/blob/main/crates/language_extension/src/extension_lsp_adapter.rs
1 parent a1dffd9 commit 48c4a51

2 files changed

Lines changed: 17 additions & 40 deletions

File tree

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ Here is a common `settings.json` including the above mentioned configurations:
4545
}
4646
```
4747

48+
## Project Symbol Search
49+
50+
The extension supports project-wide symbol search with syntax-highlighted results. This feature is powered by JDTLS and can be accessed via Zed's symbol search.
51+
52+
JDTLS uses **CamelCase fuzzy matching** for symbol queries. For example, searching for `EmpMe` would match `EmptyMedia`. The pattern works like `Emp*Me*`, matching the capital letters of CamelCase names.
53+
4854
## Debugger
4955

5056
Debug support is enabled via our [Fork of Java Debug](https://github.com/zed-industries/java-debug), which the extension will automatically download and start for you. Please refer to the [Zed Documentation](https://zed.dev/docs/debugger#getting-started) for general information about how debugging works in Zed.

src/java.rs

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -544,30 +544,13 @@ impl Extension for Java {
544544
let name = &symbol.name;
545545

546546
match symbol.kind {
547-
SymbolKind::Class => {
548-
// code: "class Name {}" → Tree-sitter: class_declaration
549-
// display: "class Name"
550-
let keyword = "class ";
551-
let code = format!("{keyword}{name} {{}}");
552-
553-
Some(CodeLabel {
554-
spans: vec![CodeLabelSpan::code_range(0..keyword.len() + name.len())],
555-
filter_range: (keyword.len()..keyword.len() + name.len()).into(),
556-
code,
557-
})
558-
}
559-
SymbolKind::Interface => {
560-
let keyword = "interface ";
561-
let code = format!("{keyword}{name} {{}}");
562-
563-
Some(CodeLabel {
564-
spans: vec![CodeLabelSpan::code_range(0..keyword.len() + name.len())],
565-
filter_range: (keyword.len()..keyword.len() + name.len()).into(),
566-
code,
567-
})
568-
}
569-
SymbolKind::Enum => {
570-
let keyword = "enum ";
547+
SymbolKind::Class | SymbolKind::Interface | SymbolKind::Enum => {
548+
let keyword = match symbol.kind {
549+
SymbolKind::Class => "class ",
550+
SymbolKind::Interface => "interface ",
551+
SymbolKind::Enum => "enum ",
552+
_ => unreachable!(),
553+
};
571554
let code = format!("{keyword}{name} {{}}");
572555

573556
Some(CodeLabel {
@@ -660,8 +643,8 @@ impl Extension for Java {
660643
code,
661644
})
662645
} else {
663-
// No type info, just show the name
664-
let class_open = "class _ { int ";
646+
// No type info — use placeholder type for valid tree-sitter parse (not displayed)
647+
let class_open = "class _ { Object ";
665648
let code = format!("{class_open}{name}; }}");
666649
let name_start = class_open.len();
667650

@@ -676,7 +659,8 @@ impl Extension for Java {
676659
}
677660
SymbolKind::Constant => {
678661
// Wrap in class; ALL_CAPS names get @constant from highlights.scm regex
679-
let class_open = "class _ { static final int ";
662+
// Placeholder type for valid tree-sitter parse (not displayed)
663+
let class_open = "class _ { static final Object ";
680664
let code = format!("{class_open}{name}; }}");
681665
let name_start = class_open.len();
682666

@@ -702,19 +686,6 @@ impl Extension for Java {
702686
code,
703687
})
704688
}
705-
SymbolKind::Variable => {
706-
let class_open = "class _ { int ";
707-
let code = format!("{class_open}{name}; }}");
708-
let name_start = class_open.len();
709-
710-
Some(CodeLabel {
711-
spans: vec![CodeLabelSpan::code_range(
712-
name_start..name_start + name.len(),
713-
)],
714-
filter_range: (0..name.len()).into(),
715-
code,
716-
})
717-
}
718689
SymbolKind::Package | SymbolKind::Module | SymbolKind::Namespace => {
719690
let keyword = "package ";
720691
let code = format!("{keyword}{name};");

0 commit comments

Comments
 (0)