-
Notifications
You must be signed in to change notification settings - Fork 99
perf: tune Java LSP tool selection guidance #1020
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
Merged
+105
−21
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,15 @@ | ||
| --- | ||
| description: REQUIRED for Java files. Provides compiler-accurate lsp_java_findSymbol and lsp_java_getFileStructure tools that replace grep_search, search_subagent, semantic_search, and file_search for Java symbol navigation. | ||
| description: Use Java LSP tools for precise Java symbol navigation. Prefer lsp_java_findSymbol and lsp_java_getFileStructure over generic search only when locating Java classes, methods, fields, or file outlines. | ||
| applyTo: '**/*.java' | ||
| --- | ||
|
|
||
| For Java files, two compiler-accurate `lsp_java_*` tools are available and return structured results in ~50 tokens vs ~500+ from generic search: | ||
| For Java symbol navigation, two compiler-accurate `lsp_java_*` tools are available and return structured results with smaller, easier-to-interpret payloads than generic search: | ||
|
|
||
| - `lsp_java_findSymbol(query)` — find class/method/field definitions by name across the workspace | ||
| - `lsp_java_getFileStructure(uri)` — get file outline (classes, methods, fields) with line ranges | ||
|
|
||
| These are deferred tools. Load them with `tool_search_tool_regex` using pattern `lsp_java_` before first use. | ||
| If these tools are not already available in the current tool list, load them with `tool_search` using a query such as `Java LSP symbol navigation lsp_java`. | ||
|
|
||
| Prefer these over `grep_search`, `search_subagent`, `semantic_search`, `file_search`, or full-file `read_file` when navigating Java symbols. Always use `findSymbol` to discover file paths before passing them to `getFileStructure` — do not guess paths. Fall back to `grep_search` if a tool returns empty or errors. | ||
| Use `lsp_java_findSymbol` before `grep_search`, `search_subagent`, `semantic_search`, or `file_search` only when the task is to locate Java symbols by name or partial identifier. If it returns relevant symbols, do not call it again with the same or similar query; next use `lsp_java_getFileStructure` for the returned file or `read_file` on the smallest useful line range. | ||
|
|
||
| Use `lsp_java_getFileStructure` only with a path confirmed by the user or a previous tool result. Do not guess paths. Use generic search for string literals, comments, XML, Gradle/Maven files, non-Java files, or broad conceptual exploration. `findSymbol` already retries internally with a normalized identifier, so do not re-issue the same search on an empty result: if it reports indexing in progress, retry once after a short pause; otherwise fall back to generic search. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,41 +1,45 @@ | ||
| --- | ||
| name: java-lsp-tools | ||
| description: Compiler-accurate Java code navigation via the Java Language Server. Use lsp_java_findSymbol to locate symbols and lsp_java_getFileStructure to inspect file outlines. Prefer over grep_search for Java symbol navigation. | ||
| description: Compiler-accurate Java symbol navigation via the Java Language Server. Use lsp_java_findSymbol for Java identifiers and lsp_java_getFileStructure for known Java files; prefer them over generic search only for symbol/file-outline navigation. | ||
| --- | ||
|
|
||
| # Java LSP Tools | ||
|
|
||
| Two compiler-accurate tools backed by the Java Language Server (jdtls). They return structured JSON with fewer tokens than `grep_search` or `read_file`. | ||
| Two compiler-accurate tools backed by the Java Language Server (jdtls). They return structured JSON that is easier to interpret than generic search results for Java symbol navigation. | ||
|
|
||
| ## Tools | ||
|
|
||
| ### `lsp_java_findSymbol` | ||
| Search for Java symbol definitions (classes, methods, fields) by name across the workspace. Supports partial matching. | ||
| - Input: `{ query, limit? }` — limit defaults to 20, max 50 | ||
| - Output: `{ name, kind, location }` per result (~60 tokens) | ||
| - **Use instead of** `grep_search` when looking for where a class/method is defined | ||
| - Output: `{ results: [{ name, kind, container?, location, range }], total }` (~60 tokens); `range` is `L start-end` | ||
| - **Use instead of** `grep_search`, `file_search`, `semantic_search`, or `search_subagent` when looking for where a Java class/method/field is defined by identifier | ||
|
wenytang-ms marked this conversation as resolved.
|
||
| - Do not repeat with the same or similar query after relevant results are returned | ||
|
|
||
| ### `lsp_java_getFileStructure` | ||
| Get hierarchical outline of a Java file (classes, methods, fields) with line ranges. | ||
| - Input: `{ uri }` — workspace-relative path. Must be a known path from prior tool results or user input — do not guess | ||
| - Output: symbol tree with `L start-end` ranges (~100 tokens) | ||
| - **Use instead of** `read_file` full scan when you need to understand a file's layout | ||
| - **Use before** `read_file` when you need to choose a precise line range in a known Java file | ||
|
|
||
| ## When to Use | ||
|
|
||
| | Task | Use | Not | | ||
| |---|---|---| | ||
| | Find class/method/field definition | `lsp_java_findSymbol` | `grep_search` | | ||
| | See file outline before reading | `lsp_java_getFileStructure` | `read_file` full file | | ||
| | See known Java file outline before reading | `lsp_java_getFileStructure` | `read_file` full file | | ||
| | Search non-Java files (xml, gradle) | `grep_search` | lsp tools | | ||
| | Search string literals or comments | `grep_search` | lsp tools | | ||
| | Explore broad concepts without identifiers | `semantic_search` or `search_subagent` | lsp tools | | ||
|
|
||
| ## Typical Workflow | ||
|
|
||
| **findSymbol → getFileStructure → read_file (specific lines only)** | ||
|
|
||
| If `findSymbol` returns relevant symbols, move forward to `getFileStructure` or `read_file`; do not call `findSymbol` again with the same or similar identifier. | ||
|
|
||
| ## Fallback | ||
|
|
||
| - `findSymbol` returns empty → retry with shorter keyword, then fall back to `grep_search` | ||
| - Path error → use `findSymbol` to discover correct path first | ||
| - `findSymbol` returns empty → it already retried internally with a normalized identifier, so do not re-issue the same search. If the result says indexing is in progress, retry once after a short pause; otherwise fall back to `grep_search` | ||
| - Path error (`fileNotFound`) → use `findSymbol` to discover the correct path first; do not guess paths | ||
| - Tool error / jdtls not ready → fall back to `grep_search` + `read_file`, don't retry more than once | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.