-
Notifications
You must be signed in to change notification settings - Fork 36
Add syntax highlighting for project symbol search #188
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
base: main
Are you sure you want to change the base?
Conversation
Implement `label_for_symbol` to provide syntax-highlighted labels in the
project symbol picker (cmd-t). Without this, Java symbols appear as
plain grey text.
Each symbol kind generates a Tree-sitter-parseable code snippet wrapped
in the appropriate context (e.g. methods/fields inside `class _ { }`)
so the Java grammar can produce correct AST nodes for highlighting.
Supported symbols:
- Class, Interface, Enum: keyword prefix + name
- Method/Function: return type + name + params (Java declaration order)
- Constructor: name + params
- Field/Property: type + name (Java declaration order)
- Constant, EnumMember, Variable: highlighted name
- Package/Module/Namespace: keyword prefix + name
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
We require contributors to sign our Contributor License Agreement, and we don't have @da-r-k on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'. |
|
@cla-bot check |
|
We require contributors to sign our Contributor License Agreement, and we don't have @da-r-k on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'. |
|
The cla-bot has been summoned, and re-checked this pull request! |
|
@cla-bot check |
|
The cla-bot has been summoned, and re-checked this pull request! |
|
Thanks for the PR. Please format the code with and push another commit |
|
@da-r-k I've tried the extension but it doesn't seem to be working as intended. For example, when searching for the symbol Media, see snippet below, I was just getting Media in the list without any of the additional information about it Are these changes depending on a change to the grammar? |
|
@da-r-k@da-r-k, I’ve been using the wrong branch. I assumed gh would have retrieved the correct one, but apparently, it wasn’t the case. Is fuzzy search something that the LSP needs to support to be used or is it up to us to enable it? |
|
@tartarughina Yes. JDTLS uses CamelCase fuzzy search. So if you search for |
|
@da-r-k interesting, I didn't know that it was using CamelCase fuzzy. Since that might be new to a lot, do you mind adding a small entry in the README explaining how project symbol works? The main points would be:
|
| SymbolKind::Class => { | ||
| // code: "class Name {}" → Tree-sitter: class_declaration | ||
| // display: "class Name" | ||
| let keyword = "class "; | ||
| let code = format!("{keyword}{name} {{}}"); | ||
|
|
||
| Some(CodeLabel { | ||
| spans: vec![CodeLabelSpan::code_range(0..keyword.len() + name.len())], | ||
| filter_range: (keyword.len()..keyword.len() + name.len()).into(), | ||
| code, | ||
| }) | ||
| } | ||
| SymbolKind::Interface => { | ||
| let keyword = "interface "; | ||
| let code = format!("{keyword}{name} {{}}"); | ||
|
|
||
| Some(CodeLabel { | ||
| spans: vec![CodeLabelSpan::code_range(0..keyword.len() + name.len())], | ||
| filter_range: (keyword.len()..keyword.len() + name.len()).into(), | ||
| code, | ||
| }) | ||
| } | ||
| SymbolKind::Enum => { | ||
| let keyword = "enum "; | ||
| let code = format!("{keyword}{name} {{}}"); | ||
|
|
||
| Some(CodeLabel { | ||
| spans: vec![CodeLabelSpan::code_range(0..keyword.len() + name.len())], | ||
| filter_range: (keyword.len()..keyword.len() + name.len()).into(), | ||
| code, | ||
| }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is pretty much the same if not for the keyword, cannot we simplify it removing repeated code?
| }) | ||
| } else { | ||
| // No type info, just show the name | ||
| let class_open = "class _ { int "; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does it default to int?
| } | ||
| SymbolKind::Constant => { | ||
| // Wrap in class; ALL_CAPS names get @constant from highlights.scm regex | ||
| let class_open = "class _ { static final int "; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why using int?
| }) | ||
| } | ||
| SymbolKind::Variable => { | ||
| let class_open = "class _ { int "; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as above regarding int usage

Summary
Implements
label_for_symbolto provide syntax-highlighted labels in the project symbol picker (cmd-t). Currently, Java symbols appear as plain grey text with no highlighting, unlike Rust and other languages that already implement this.Ref: zed-industries/zed#36383, zed-industries/zed#37176
Changes
label_for_symbolto theExtension for JavaimplSymbolandSymbolKindfrom the extension APIclass _ { }since Java's Tree-sitter grammar requires class context for these declarationsvoid doWork(String, int),String fieldNameclass,interface,enum,packageSupported symbol kinds
class MyClassclass MyClass {}interface Runnableinterface Runnable {}enum Statusenum Status {}MyClass(String, int)class MyClass { MyClass() {} }void doWork(String, int)class _ { void doWork() {} }String nameclass _ { String name; }MAX_SIZEclass _ { static final int MAX_SIZE; }ACTIVEenum _ { ACTIVE }countclass _ { int count; }package com.examplepackage com.example;Screenshot: