Skip to content

Commit 9fdb617

Browse files
authored
perf: adjust exp (#994)
* perf: adjust instrument and skill, add more telemetry to lsp tool * perf: adjust the instrument * ci: fix ci * chore: update
1 parent adfdb2e commit 9fdb617

4 files changed

Lines changed: 92 additions & 265 deletions

File tree

package.json

Lines changed: 2 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
{
5353
"name": "lsp_java_getFileStructure",
5454
"toolReferenceName": "javaFileStructure",
55-
"modelDescription": "Get the structure (classes, methods, fields, inner classes) of a Java file. Returns a hierarchical outline with symbol kinds and line ranges. Use this first when you need to understand a file's layout before reading specific sections.",
55+
"modelDescription": "Get the structure (classes, methods, fields, inner classes) of a Java file. Returns a hierarchical outline with symbol kinds and line ranges in ~100 tokens.\n\nWhen to use:\n- Before reading a Java file, to understand its layout and find specific line ranges\n- Instead of read_file on the entire file — use this first, then read_file on specific lines\n- When you need to know what methods/fields a class has\n\nWhen NOT to use:\n- For non-Java files (use read_file instead)\n- To search across multiple files (use lsp_java_findSymbol instead)",
5656
"displayName": "Java: Get File Structure",
5757
"canBeReferencedInPrompt": true,
5858
"icon": "$(symbol-class)",
@@ -71,7 +71,7 @@
7171
{
7272
"name": "lsp_java_findSymbol",
7373
"toolReferenceName": "javaFindSymbol",
74-
"modelDescription": "Search for Java symbols (classes, interfaces, methods, fields) across the workspace by name. Supports partial/fuzzy matching. Use this to find where a class or method is defined.",
74+
"modelDescription": "Search for Java symbol definitions (classes, interfaces, methods, fields) across the entire workspace by name. Returns precise locations in ~60 tokens vs ~500+ tokens from grep_search.\n\nWhen to use:\n- To find where a class, method, or field is defined — faster and more precise than grep_search\n- To discover file paths before using other tools\n- Supports partial matching (e.g. 'UserSvc' finds 'UserServiceImpl')\n\nWhen NOT to use:\n- For non-Java files\n- To search for string literals, comments, or non-symbol text (use grep_search)",
7575
"displayName": "Java: Find Symbol",
7676
"canBeReferencedInPrompt": true,
7777
"icon": "$(search)",
@@ -90,118 +90,6 @@
9090
},
9191
"required": ["query"]
9292
}
93-
},
94-
{
95-
"name": "lsp_java_getFileImports",
96-
"toolReferenceName": "javaFileImports",
97-
"modelDescription": "Get all import statements from a Java file, classified by source (jdk/project/external).",
98-
"displayName": "Java: Get File Imports",
99-
"canBeReferencedInPrompt": true,
100-
"icon": "$(references)",
101-
"when": "config.vscode-java-dependency.enableLspTools && javaLSReady",
102-
"inputSchema": {
103-
"type": "object",
104-
"properties": {
105-
"uri": {
106-
"type": "string",
107-
"description": "Java file path (workspace-relative or full URI)"
108-
}
109-
},
110-
"required": ["uri"]
111-
}
112-
},
113-
{
114-
"name": "lsp_java_getTypeAtPosition",
115-
"toolReferenceName": "javaTypeAtPosition",
116-
"modelDescription": "Get the compiler-resolved type signature at a specific position. Returns fully qualified type, method signature, or field declaration. Use this when you see var, lambdas, or generics and need the exact type.",
117-
"displayName": "Java: Get Type at Position",
118-
"canBeReferencedInPrompt": true,
119-
"icon": "$(symbol-field)",
120-
"when": "config.vscode-java-dependency.enableLspTools && javaLSReady",
121-
"inputSchema": {
122-
"type": "object",
123-
"properties": {
124-
"uri": {
125-
"type": "string",
126-
"description": "Java file path (workspace-relative or full URI)"
127-
},
128-
"line": {
129-
"type": "number",
130-
"description": "Zero-based line number"
131-
},
132-
"character": {
133-
"type": "number",
134-
"description": "Zero-based character offset"
135-
}
136-
},
137-
"required": ["uri", "line", "character"]
138-
}
139-
},
140-
{
141-
"name": "lsp_java_getCallHierarchy",
142-
"toolReferenceName": "javaCallHierarchy",
143-
"modelDescription": "Get incoming callers or outgoing callees of a method. PREFER THIS over grep_search when you need to find which methods call a specific method — returns precise call sites without noise from comments, imports, or string matches. Use 'incoming' for callers, 'outgoing' for callees.",
144-
"displayName": "Java: Get Call Hierarchy",
145-
"canBeReferencedInPrompt": true,
146-
"icon": "$(call-incoming)",
147-
"when": "config.vscode-java-dependency.enableLspTools && javaLSReady",
148-
"inputSchema": {
149-
"type": "object",
150-
"properties": {
151-
"uri": {
152-
"type": "string",
153-
"description": "Java file path (workspace-relative or full URI)"
154-
},
155-
"line": {
156-
"type": "number",
157-
"description": "Zero-based line number of the method"
158-
},
159-
"character": {
160-
"type": "number",
161-
"description": "Zero-based character offset within the method name"
162-
},
163-
"direction": {
164-
"type": "string",
165-
"enum": ["incoming", "outgoing"],
166-
"default": "incoming",
167-
"description": "'incoming' for callers, 'outgoing' for callees"
168-
}
169-
},
170-
"required": ["uri", "line", "character", "direction"]
171-
}
172-
},
173-
{
174-
"name": "lsp_java_getTypeHierarchy",
175-
"toolReferenceName": "javaTypeHierarchy",
176-
"modelDescription": "Get supertypes or subtypes/implementors of a type. PREFER THIS over grep_search('extends|implements') — returns only actual inheritance relationships. Use 'supertypes' for parents, 'subtypes' for children.",
177-
"displayName": "Java: Get Type Hierarchy",
178-
"canBeReferencedInPrompt": true,
179-
"icon": "$(type-hierarchy)",
180-
"when": "config.vscode-java-dependency.enableLspTools && javaLSReady",
181-
"inputSchema": {
182-
"type": "object",
183-
"properties": {
184-
"uri": {
185-
"type": "string",
186-
"description": "Java file path (workspace-relative or full URI)"
187-
},
188-
"line": {
189-
"type": "number",
190-
"description": "Zero-based line number of the type"
191-
},
192-
"character": {
193-
"type": "number",
194-
"description": "Zero-based character offset within the type name"
195-
},
196-
"direction": {
197-
"type": "string",
198-
"enum": ["supertypes", "subtypes"],
199-
"default": "supertypes",
200-
"description": "'supertypes' for parents, 'subtypes' for children"
201-
}
202-
},
203-
"required": ["uri", "line", "character", "direction"]
204-
}
20593
}
20694
],
20795
"commands": [
Lines changed: 7 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,14 @@
11
---
2-
description: Unconditionally loaded for all Java projects. Provides Java LSP tools (lsp_java_*) for compiler-accurate code navigation — significantly faster and more precise than grep_search, search_subagent, or read_file for locating Java symbols, callers, implementations, and types.
3-
applyTo: '*'
2+
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.
3+
applyTo: '**/*.java'
44
---
55

6-
# Java LSP Tools — Mandatory Initialization
6+
For Java files, two compiler-accurate `lsp_java_*` tools are available and return structured results in ~50 tokens vs ~500+ from generic search:
77

8-
This workspace contains Java code. You have access to 6 compiler-accurate LSP tools that are **faster and more precise** than generic search for Java code navigation. These tools return structured results in ~20-100 tokens vs ~500-3000 tokens from grep_search, with zero false positives.
8+
- `lsp_java_findSymbol(query)` — find class/method/field definitions by name across the workspace
9+
- `lsp_java_getFileStructure(uri)` — get file outline (classes, methods, fields) with line ranges
910

10-
## Step 1: Load Tools (REQUIRED — do this FIRST)
11+
These are deferred tools. Load them with `tool_search_tool_regex` using pattern `lsp_java_` before first use.
1112

12-
Before ANY operation, load all 6 tools by calling `tool_search_tool_regex` **twice** (the API returns at most 5 tools per call):
13-
14-
**Call 1** — basic navigation tools:
15-
```
16-
lsp_java_findSymbol|lsp_java_getFileStructure|lsp_java_getFileImports
17-
```
18-
19-
**Call 2** — hierarchy and type tools:
20-
```
21-
lsp_java_getCallHierarchy|lsp_java_getTypeHierarchy|lsp_java_getTypeAtPosition
22-
```
23-
24-
All 6 tools must be returned across the two calls. If any are missing, retry that call once. Do NOT use `grep_search`, `read_file`, `semantic_search`, `search_subagent`, or `runSubagent` on `.java` files until all tools are loaded.
25-
26-
## Step 2: Always Prefer LSP Tools for Java
27-
28-
| Task | ✅ Use | ❌ Not |
29-
|---|---|---|
30-
| Find class/method/field definition | `lsp_java_findSymbol` | `grep_search`, `semantic_search`, `search_subagent` |
31-
| See file outline (methods, fields) | `lsp_java_getFileStructure` | `read_file` full scan |
32-
| Find all callers of a method | `lsp_java_getCallHierarchy("incoming")` | `grep_search`, `search_subagent` |
33-
| Find all implementations | `lsp_java_getTypeHierarchy("subtypes")` | `grep_search`, `search_subagent` |
34-
| Resolve var/lambda/generic type | `lsp_java_getTypeAtPosition` | Guessing from code |
35-
| Check imports | `lsp_java_getFileImports` | `read_file` first lines |
36-
| Explore Java codebase structure | `lsp_java_*` tools above | `search_subagent`, `runSubagent` |
37-
38-
**Keep using `grep_search`** for: non-Java files (xml, yaml, gradle), string literals, comments.
39-
40-
**Self-check**: Before every `.java` operation, ask: "Is there a `lsp_java_*` tool for this?" If yes, use it instead of `grep_search`, `search_subagent`, or `runSubagent`.
41-
42-
## Typical Workflow
43-
44-
**findSymbol → getFileStructure → targeted tool → read_file (specific lines only)**
45-
46-
## Fallback
47-
48-
- `findSymbol` returns empty → retry with shorter keyword, then fall back to `grep_search`
49-
- Path error → use `findSymbol` to discover correct path first
50-
- Tool error / jdtls not ready → fall back to `read_file` + `grep_search`, don't retry more than once
13+
Prefer these over `grep_search`, `search_subagent`, `semantic_search`, `file_search`, or full-file `read_file` when navigating Java symbols. Fall back to `grep_search` if a tool returns empty or errors.
5114

Lines changed: 23 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,41 @@
11
---
22
name: java-lsp-tools
3-
description: Compiler-accurate Java code intelligence tools powered by the Java Language Server. ALWAYS load this skill when the workspace contains Java, Maven (pom.xml), or Gradle (build.gradle) projects. Use these tools to find symbol definitions, get type/call hierarchies, resolve types, inspect file outlines, and check imports in Java source files. Prefer over grep_search or read_file for any Java code navigation, understanding, debugging, or refactoring task.
3+
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.
44
---
55

66
# Java LSP Tools
77

8-
Compiler-accurate Java code intelligence via the Java Language Server (jdtls). These 6 tools provide structured, low-token answers that are more precise than `grep_search` or `read_file` for Java code.
9-
10-
## Activation
11-
12-
These tools are **deferred** and must be discovered before first use. Activate all 6 tools at once with `tool_search_tool_regex` using pattern:
13-
14-
`lsp_java_findSymbol|lsp_java_getFileStructure|lsp_java_getCallHierarchy|lsp_java_getTypeHierarchy|lsp_java_getTypeAtPosition|lsp_java_getFileImports`
15-
16-
You only need to do this **once per session**.
17-
18-
## When to Replace grep_search
19-
20-
For Java source files, **always prefer these tools over generic alternatives**:
21-
22-
| You're doing... | Use instead | Why |
23-
|---|---|---|
24-
| Find where a class/method is defined | `lsp_java_findSymbol` | ~60 tokens vs ~500 for grep (no comment/import noise) |
25-
| Find all callers of a method | `lsp_java_getCallHierarchy("incoming")` | ~80 tokens vs ~3000 for grep (precise call sites only) |
26-
| Find all implementations of an interface | `lsp_java_getTypeHierarchy("subtypes")` | ~60 tokens vs ~1000 for grep |
27-
| Check a `var`/lambda/generic type | `lsp_java_getTypeAtPosition` | ~20 tokens vs guessing wrong |
28-
| Search in non-Java files (xml, yaml, gradle) | Keep using `grep_search` | lsp_java_* tools only work on Java source |
29-
| Search for string literals or comments | Keep using `grep_search` | lsp_java_* tools return symbol definitions only |
30-
31-
**Rule of thumb**: If you're searching for a Java symbol name in `.java` files, there is almost always a `lsp_java_*` tool that returns more precise results with fewer tokens than `grep_search`.
32-
33-
## Anti-patterns (Avoid these)
34-
35-
**Don't**: Use `grep_search("decodeLbs")` to find who calls `decodeLbs()`
36-
- Returns 8+ matches including declaration, comments, imports → ~3000 output tokens
37-
38-
**Do**: Use `lsp_java_getCallHierarchy(uri, line, char, "incoming")`
39-
- Returns only actual call sites → ~80 output tokens
40-
41-
**Don't**: Use `grep_search("class.*extends BaseDecoder")` to find subclasses
42-
**Do**: Use `lsp_java_getTypeHierarchy(uri, line, char, "subtypes")`
43-
44-
**Don't**: Read entire 1000+ line file to understand its structure
45-
**Do**: Use `lsp_java_getFileStructure(uri)` first, then `read_file` on specific line ranges
8+
Two compiler-accurate tools backed by the Java Language Server (jdtls). They return structured JSON with fewer tokens than `grep_search` or `read_file`.
469

4710
## Tools
4811

49-
All tools accept **workspace-relative paths** (e.g. `src/main/java/com/example/MyClass.java`) or full file URIs. All return structured JSON, each response < 200 tokens.
50-
51-
### `lsp_java_getFileStructure`
52-
Get hierarchical outline (classes, methods, fields) with line ranges.
53-
Input: `{ uri }` → Output: symbol tree with `[L start-end]` ranges (~100 tokens)
54-
5512
### `lsp_java_findSymbol`
56-
Search for symbol definitions by name across the workspace. Supports partial/fuzzy matching.
57-
Input: `{ query }` → Output: up to 20 results with `{ name, kind, location }` (~60 tokens)
13+
Search for Java symbol definitions (classes, methods, fields) by name across the workspace. Supports partial matching.
14+
- Input: `{ query, limit? }` — limit defaults to 20, max 50
15+
- Output: `{ name, kind, location }` per result (~60 tokens)
16+
- **Use instead of** `grep_search` when looking for where a class/method is defined
5817

59-
### `lsp_java_getFileImports`
60-
Get all imports classified by source (jdk/project/external).
61-
Input: `{ uri }` → Output: classified import list (~80 tokens)
62-
63-
### `lsp_java_getTypeAtPosition`
64-
Get compiler-resolved type signature at a specific position.
65-
Input: `{ uri, line, character }` (0-based) → Output: fully resolved type (~20 tokens)
66-
67-
### `lsp_java_getCallHierarchy`
68-
Find all callers (incoming) or callees (outgoing) of a method.
69-
Input: `{ uri, line, character, direction }` (0-based, direction: `"incoming"` | `"outgoing"`) → Output: list of `{ name, detail, location }` (~80 tokens)
18+
### `lsp_java_getFileStructure`
19+
Get hierarchical outline of a Java file (classes, methods, fields) with line ranges.
20+
- Input: `{ uri }` — workspace-relative path or full URI
21+
- Output: symbol tree with `L start-end` ranges (~100 tokens)
22+
- **Use instead of** `read_file` full scan when you need to understand a file's layout
7023

71-
### `lsp_java_getTypeHierarchy`
72-
Find supertypes or subtypes/implementors of a type.
73-
Input: `{ uri, line, character, direction }` (0-based, direction: `"supertypes"` | `"subtypes"`) → Output: list of `{ name, kind, location }` (~60 tokens)
24+
## When to Use
7425

75-
## Common Workflows
26+
| Task | Use | Not |
27+
|---|---|---|
28+
| Find class/method/field definition | `lsp_java_findSymbol` | `grep_search` |
29+
| See file outline before reading | `lsp_java_getFileStructure` | `read_file` full file |
30+
| Search non-Java files (xml, gradle) | `grep_search` | lsp tools |
31+
| Search string literals or comments | `grep_search` | lsp tools |
7632

77-
Most tasks follow the pattern: **findSymbol → getFileStructure → targeted tool**.
33+
## Typical Workflow
7834

79-
| Scenario | Workflow | Trigger |
80-
|---|---|---|
81-
| Debug a bug | `findSymbol``getFileStructure``read_file` (buggy method) → **`getCallHierarchy("incoming")`**`read_file` (caller context) | When you found the buggy method and need to know ALL callers |
82-
| Analyze impact | `findSymbol``getFileStructure``getCallHierarchy("incoming")` | Before editing a method, check who depends on it |
83-
| Understand inheritance | `findSymbol``getTypeHierarchy("subtypes")` | When you see a base class and need all implementations |
84-
| Check dependencies | `getFileImports``findSymbol` (dependency) → `getFileStructure` | When understanding external library usage |
85-
| Resolve type ambiguity | `getFileStructure``getTypeAtPosition` | When you see `var`, generics, or lambda and need exact type |
35+
**findSymbol → getFileStructure → read_file (specific lines only)**
8636

8737
## Fallback
8838

89-
- **`lsp_java_findSymbol` returns empty**:
90-
- Symbol may not exist yet → switch to `read_file` + `grep_search` to confirm, then create it
91-
- Spelling/query too specific → retry once with a shorter keyword (e.g. `"UserSvc"` instead of `"UserServiceImpl"`)
92-
- **Path error** (e.g. "Unable to resolve nonexistent file"): Use `lsp_java_findSymbol` to discover the correct file path first, then retry.
93-
- **Tool error / empty result** (jdtls not ready, file not in project): Fall back to `read_file` + `grep_search`. Don't retry more than once.
39+
- `findSymbol` returns empty → retry with shorter keyword, then fall back to `grep_search`
40+
- Path error → use `findSymbol` to discover correct path first
41+
- Tool error / jdtls not ready → fall back to `grep_search` + `read_file`, don't retry more than once

0 commit comments

Comments
 (0)