Skip to content

Commit ae72489

Browse files
committed
feat: update
1 parent 035d424 commit ae72489

File tree

8 files changed

+111
-89
lines changed

8 files changed

+111
-89
lines changed

docs/java-context-tools-design.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,19 @@
2828
| Tool | 粒度 | 用途 | 典型 token 量 |
2929
|------|------|------|--------------|
3030
| `java_getProjectContext` | L0 | 项目级概览 | ~100 |
31-
| `java_getFileImports` | L0 | 文件的 import 列表 | ~80 |
31+
| `lsp_java_getFileImports` | L0 | 文件的 import 列表 | ~80 |
3232
| `java_getClassDetail` | L1 | 单个类的签名+方法列表 | ~150 |
3333
| `java_getDependencyDetails` | L1 | 指定依赖的 GAV+scope | ~50 |
3434

3535
### 与 LSP 标准 Tool 的配合
3636

3737
| 标准 LSP Tool(VS Code 内置命令封装) | 粒度 | 对应 LSP 请求 |
3838
|--------------------------------------|------|-------------|
39-
| `java_getFileStructure` | L0 | `textDocument/documentSymbol` |
40-
| `java_findSymbol` | L0 | `workspace/symbol` |
41-
| `java_getTypeAtPosition` | L1 | `textDocument/hover` (后处理) |
42-
| `java_getCallHierarchy` | L1 | `callHierarchy/incomingCalls` + `outgoingCalls` |
43-
| `java_getTypeHierarchy` | L1 | `typeHierarchy/supertypes` + `subtypes` |
39+
| `lsp_java_getFileStructure` | L0 | `textDocument/documentSymbol` |
40+
| `lsp_java_findSymbol` | L0 | `workspace/symbol` |
41+
| `lsp_java_getTypeAtPosition` | L1 | `textDocument/hover` (后处理) |
42+
| `lsp_java_getCallHierarchy` | L1 | `callHierarchy/incomingCalls` + `outgoingCalls` |
43+
| `lsp_java_getTypeHierarchy` | L1 | `typeHierarchy/supertypes` + `subtypes` |
4444

4545
---
4646

@@ -97,7 +97,7 @@ java.project.getProjectContext(fileUri) → ProjectContextResult
9797

9898
---
9999

100-
## Tool 2: `java_getFileImports`
100+
## Tool 2: `lsp_java_getFileImports`
101101

102102
**用途**:快速了解一个 Java 文件引用了哪些类型,但不展开细节。
103103

@@ -283,23 +283,23 @@ java.project.getDependencyDetails(fileUri, query?) → DependencyDetailsResult
283283

284284
这些工具直接封装 VS Code 内置命令,不需要新的 Java 后端命令。
285285

286-
### Tool 5: `java_getFileStructure`
286+
### Tool 5: `lsp_java_getFileStructure`
287287

288288
封装 `vscode.executeDocumentSymbolProvider`,返回文件的类/方法/字段树。
289289

290-
### Tool 6: `java_findSymbol`
290+
### Tool 6: `lsp_java_findSymbol`
291291

292292
封装 `vscode.executeWorkspaceSymbolProvider`,全局模糊搜索符号。
293293

294-
### Tool 7: `java_getTypeAtPosition`
294+
### Tool 7: `lsp_java_getTypeAtPosition`
295295

296296
封装 `vscode.executeHoverProvider` + 后处理提取类型签名。
297297

298-
### Tool 8: `java_getCallHierarchy`
298+
### Tool 8: `lsp_java_getCallHierarchy`
299299

300300
封装 `vscode.prepareCallHierarchy` + `vscode.provideIncomingCalls` / `vscode.provideOutgoingCalls`
301301

302-
### Tool 9: `java_getTypeHierarchy`
302+
### Tool 9: `lsp_java_getTypeHierarchy`
303303

304304
封装 `vscode.prepareTypeHierarchy` + `vscode.provideSupertypes` / `vscode.provideSubtypes`
305305

docs/java-context-tools-skill.md

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ You have access to 6 Java-specific tools that provide **compiler-accurate** info
2222

2323
## Tool Reference
2424

25-
### `java_getFileStructure`
25+
### `lsp_java_getFileStructure`
2626

2727
**Purpose:** Get the structural outline of a Java file — classes, methods, fields with line ranges.
2828

@@ -41,7 +41,7 @@ You have access to 6 Java-specific tools that provide **compiler-accurate** info
4141

4242
---
4343

44-
### `java_findSymbol`
44+
### `lsp_java_findSymbol`
4545

4646
**Purpose:** Find classes, interfaces, methods by name across the entire workspace.
4747

@@ -60,7 +60,7 @@ You have access to 6 Java-specific tools that provide **compiler-accurate** info
6060

6161
---
6262

63-
### `java_getFileImports`
63+
### `lsp_java_getFileImports`
6464

6565
**Purpose:** Get all import statements from a Java file, classified by source (jdk/project/external).
6666

@@ -75,11 +75,11 @@ You have access to 6 Java-specific tools that provide **compiler-accurate** info
7575

7676
**Typical output size:** ~80 tokens
7777

78-
**Important:** This tells you WHAT is imported but not HOW it's used. For details about a specific imported class, use `read_file` to read the relevant source or `java_getTypeAtPosition` on its usage.
78+
**Important:** This tells you WHAT is imported but not HOW it's used. For details about a specific imported class, use `read_file` to read the relevant source or `lsp_java_getTypeAtPosition` on its usage.
7979

8080
---
8181

82-
### `java_getTypeAtPosition`
82+
### `lsp_java_getTypeAtPosition`
8383

8484
**Purpose:** Get the exact resolved type of any expression at a specific source position.
8585

@@ -99,7 +99,7 @@ You have access to 6 Java-specific tools that provide **compiler-accurate** info
9999

100100
---
101101

102-
### `java_getCallHierarchy`
102+
### `lsp_java_getCallHierarchy`
103103

104104
**Purpose:** Find all callers of a method (incoming) or all methods it calls (outgoing).
105105

@@ -118,7 +118,7 @@ You have access to 6 Java-specific tools that provide **compiler-accurate** info
118118

119119
---
120120

121-
### `java_getTypeHierarchy`
121+
### `lsp_java_getTypeHierarchy`
122122

123123
**Purpose:** Find all supertypes or subtypes of a class/interface.
124124

@@ -142,10 +142,10 @@ You have access to 6 Java-specific tools that provide **compiler-accurate** info
142142
### Pattern 1: "Fix a bug in a Java file"
143143

144144
```
145-
1. java_getFileStructure(file) → Understand what's in the file (100 tokens)
145+
1. lsp_java_getFileStructure(file) → Understand what's in the file (100 tokens)
146146
2. read_file(file, relevant_lines) → Read the buggy method
147-
3. [If needed] java_getFileImports(file) → Check what types are used (80 tokens)
148-
4. [If needed] java_getTypeAtPosition() → Resolve ambiguous types (20 tokens)
147+
3. [If needed] lsp_java_getFileImports(file) → Check what types are used (80 tokens)
148+
4. [If needed] lsp_java_getTypeAtPosition() → Resolve ambiguous types (20 tokens)
149149
5. Edit the file
150150
```
151151
Total tool overhead: ~200 tokens (vs ~3000+ tokens if you blindly dump all imports)
@@ -154,44 +154,44 @@ Total tool overhead: ~200 tokens (vs ~3000+ tokens if you blindly dump all impor
154154

155155
```
156156
1. read_file(pom.xml or build.gradle) → Check build tool, Java version, deps
157-
2. java_findSymbol("Main") → Find entry points (60 tokens)
158-
3. java_getFileStructure(main_file) → Understand main file (100 tokens)
159-
4. java_getFileImports(main_file) → See what libraries are used (80 tokens)
157+
2. lsp_java_findSymbol("Main") → Find entry points (60 tokens)
158+
3. lsp_java_getFileStructure(main_file) → Understand main file (100 tokens)
159+
4. lsp_java_getFileImports(main_file) → See what libraries are used (80 tokens)
160160
```
161161
Total tool overhead: ~240 tokens
162162

163163
### Pattern 3: "Refactor a method signature"
164164

165165
```
166-
1. java_getCallHierarchy(method, "incoming") → Find all callers (80 tokens)
166+
1. lsp_java_getCallHierarchy(method, "incoming") → Find all callers (80 tokens)
167167
2. For each caller file:
168-
java_getFileStructure(caller_file) → Understand caller context (100 tokens)
168+
lsp_java_getFileStructure(caller_file) → Understand caller context (100 tokens)
169169
3. Edit all affected files
170170
```
171171

172172
### Pattern 4: "Find all implementations of an interface"
173173

174174
```
175-
1. java_findSymbol("MyInterface") → Locate the interface (60 tokens)
176-
2. java_getTypeHierarchy(interface_pos, "subtypes") → Find all impls (60 tokens)
175+
1. lsp_java_findSymbol("MyInterface") → Locate the interface (60 tokens)
176+
2. lsp_java_getTypeHierarchy(interface_pos, "subtypes") → Find all impls (60 tokens)
177177
3. For key implementations:
178-
java_getFileStructure(impl_file) → See what they override
178+
lsp_java_getFileStructure(impl_file) → See what they override
179179
```
180180

181181
### Pattern 5: "Understand dependency usage in a file"
182182

183183
```
184-
1. java_getFileImports(file) → See all imports classified (80 tokens)
184+
1. lsp_java_getFileImports(file) → See all imports classified (80 tokens)
185185
2. [For unfamiliar external types]:
186-
java_getTypeAtPosition() on usage → See the resolved type/method signature
186+
lsp_java_getTypeAtPosition() on usage → See the resolved type/method signature
187187
3. [If needed] read_file(pom.xml) → Check dependency coordinates
188188
```
189189

190190
---
191191

192192
## Anti-Patterns (What NOT to Do)
193193

194-
### ❌ Don't call java_getTypeAtPosition on obvious types
194+
### ❌ Don't call lsp_java_getTypeAtPosition on obvious types
195195

196196
```java
197197
String name = "hello"; // Obviously String — don't call the tool
@@ -202,11 +202,11 @@ var result = service.process(input); // Not obvious — DO call the tool
202202

203203
You already know `java.util.List`, `java.lang.String`, `java.io.File`. Don't waste a tool call on them.
204204

205-
### ❌ Don't call java_getFileStructure on small files
205+
### ❌ Don't call lsp_java_getFileStructure on small files
206206

207207
If a file is < 100 lines, just use `read_file` directly. File structure is most valuable for large files.
208208

209-
### ❌ Don't call java_getCallHierarchy without reading the method first
209+
### ❌ Don't call lsp_java_getCallHierarchy without reading the method first
210210

211211
Understand what the method does before tracing its callers.
212212

@@ -223,6 +223,6 @@ If a Java tool returns an error or empty result:
223223
**For dependency/project info not covered by these tools:**
224224
- Read `pom.xml` or `build.gradle` directly with `read_file`
225225
- Use `grep_search` to find dependency declarations
226-
- Use `java_getFileImports` to see what external libraries a file uses
226+
- Use `lsp_java_getFileImports` to see what external libraries a file uses
227227

228228
**General rule:** If a Java-specific tool fails, fall back to the universal tools (`read_file`, `grep_search`, `list_code_usages`). Don't retry more than once.

docs/package-json-tools-snippet.jsonc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
}
1919
},
2020
{
21-
"name": "java_getFileImports",
21+
"name": "lsp_java_getFileImports",
2222
"tags": ["java", "imports", "file"],
2323
"modelDescription": "Get the classified import list of a Java file. Each import is tagged with its kind (class/interface/enum/annotation) and source (project/external/jdk). Returns ~80 tokens. Use this to understand what a file depends on WITHOUT reading the full source. Follow up with java_getClassDetail only for the 1-2 classes you actually need to understand — do NOT expand every import.",
2424
"displayName": "Java: Get File Imports",
@@ -74,7 +74,7 @@
7474
}
7575
},
7676
{
77-
"name": "java_getFileStructure",
77+
"name": "lsp_java_getFileStructure",
7878
"tags": ["java", "structure", "symbols", "outline"],
7979
"modelDescription": "Get the structural outline of a Java file: classes, methods, fields, and their line ranges — WITHOUT reading the file content. Returns ~100 tokens. Use this BEFORE read_file to understand what's in a large file, then read_file on specific line ranges. Much more efficient than reading the entire file.",
8080
"displayName": "Java: Get File Structure",
@@ -90,7 +90,7 @@
9090
}
9191
},
9292
{
93-
"name": "java_findSymbol",
93+
"name": "lsp_java_findSymbol",
9494
"tags": ["java", "search", "symbol", "workspace"],
9595
"modelDescription": "Search for classes, interfaces, methods, or fields by name across the entire Java workspace. Returns precise symbol definitions only (no comments, no string literals, no import statements). More accurate than grep_search for finding Java symbol definitions. Supports partial names and camelCase matching.",
9696
"displayName": "Java: Find Symbol",
@@ -106,7 +106,7 @@
106106
}
107107
},
108108
{
109-
"name": "java_getTypeAtPosition",
109+
"name": "lsp_java_getTypeAtPosition",
110110
"tags": ["java", "type", "inference", "hover"],
111111
"modelDescription": "Get the compiler-resolved type of any expression at a specific source position. Returns the EXACT type (~20 tokens), using the Java compiler's own type inference. Use this for: var declarations, lambda parameters, generic type arguments, chained method call return types. Do NOT use for obvious types like String literals or explicit type declarations.",
112112
"displayName": "Java: Get Type at Position",
@@ -130,7 +130,7 @@
130130
}
131131
},
132132
{
133-
"name": "java_getCallHierarchy",
133+
"name": "lsp_java_getCallHierarchy",
134134
"tags": ["java", "calls", "hierarchy", "impact"],
135135
"modelDescription": "Find all callers of a method (incoming) or all methods it calls (outgoing). More precise than list_code_usages — returns only actual method CALLS, not imports, declarations, or comments. Use 'incoming' before modifying a method signature to find all callers. Use 'outgoing' to understand what a method depends on.",
136136
"displayName": "Java: Get Call Hierarchy",
@@ -159,7 +159,7 @@
159159
}
160160
},
161161
{
162-
"name": "java_getTypeHierarchy",
162+
"name": "lsp_java_getTypeHierarchy",
163163
"tags": ["java", "inheritance", "hierarchy", "interface"],
164164
"modelDescription": "Find all supertypes or subtypes of a class/interface. Catches things grep misses: indirect implementations, anonymous classes, lambda implementations of functional interfaces. Use 'subtypes' when modifying an interface to find ALL implementations. Use 'supertypes' to understand the inheritance chain.",
165165
"displayName": "Java: Get Type Hierarchy",

lsp-ai-tools.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ class TypeQueryTool implements vscode.LanguageModelTool<{ uri: string; line: num
695695
}
696696
},
697697
{
698-
"name": "java_findSymbol",
698+
"name": "lsp_java_findSymbol",
699699
"displayName": "Find Symbol in Workspace",
700700
"modelDescription": "Search for a class, interface, method or field by name across the entire workspace. Returns exact matches with kind (Class/Interface/Method) and file location. More precise than grep - no noise from comments or imports.",
701701
"inputSchema": {

package.json

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
],
5151
"languageModelTools": [
5252
{
53-
"name": "java_getFileStructure",
53+
"name": "lsp_java_getFileStructure",
5454
"toolReferenceName": "javaFileStructure",
5555
"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.",
5656
"displayName": "Java: Get File Structure",
@@ -68,7 +68,7 @@
6868
}
6969
},
7070
{
71-
"name": "java_findSymbol",
71+
"name": "lsp_java_findSymbol",
7272
"toolReferenceName": "javaFindSymbol",
7373
"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.",
7474
"displayName": "Java: Find Symbol",
@@ -90,7 +90,7 @@
9090
}
9191
},
9292
{
93-
"name": "java_getFileImports",
93+
"name": "lsp_java_getFileImports",
9494
"toolReferenceName": "javaFileImports",
9595
"modelDescription": "Get all import statements from a Java file, classified by source (jdk/project/external).",
9696
"displayName": "Java: Get File Imports",
@@ -108,7 +108,7 @@
108108
}
109109
},
110110
{
111-
"name": "java_getTypeAtPosition",
111+
"name": "lsp_java_getTypeAtPosition",
112112
"toolReferenceName": "javaTypeAtPosition",
113113
"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.",
114114
"displayName": "Java: Get Type at Position",
@@ -134,7 +134,7 @@
134134
}
135135
},
136136
{
137-
"name": "java_getCallHierarchy",
137+
"name": "lsp_java_getCallHierarchy",
138138
"toolReferenceName": "javaCallHierarchy",
139139
"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.",
140140
"displayName": "Java: Get Call Hierarchy",
@@ -166,7 +166,7 @@
166166
}
167167
},
168168
{
169-
"name": "java_getTypeHierarchy",
169+
"name": "lsp_java_getTypeHierarchy",
170170
"toolReferenceName": "javaTypeHierarchy",
171171
"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.",
172172
"displayName": "Java: Get Type Hierarchy",
@@ -1231,7 +1231,13 @@
12311231
],
12321232
"chatSkills": [
12331233
{
1234-
"path": "./resources/skills/java-context-tools/SKILL.md"
1234+
"path": "./resources/skills/java-lsp-tools/SKILL.md"
1235+
}
1236+
],
1237+
"chatInstructions": [
1238+
{
1239+
"path": "./resources/instruments/loadJavaSkills.md",
1240+
"when": "java:projectManagerActivated"
12351241
}
12361242
]
12371243
},
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
description: Guidelines for using Java LSP tools when working with Java codebases
3+
applyTo: '**/*.java'
4+
---
5+
6+
MANDATORY: For ANY Java code task (bug fixing, code analysis, refactoring):
7+
8+
1. LOAD TOOLS FIRST — Call tool_search_tool_regex with pattern:
9+
lsp_java_findSymbol|lsp_java_getFileStructure|lsp_java_getCallHierarchy|lsp_java_getTypeHierarchy|lsp_java_getTypeAtPosition|lsp_java_getFileImports
10+
11+
2. ALWAYS prefer lsp_java_* tools over grep_search/read_file for .java files.
12+
These tools provide compiler-accurate results with ~90% fewer tokens.
13+
14+
3. Read the "java-lsp-tools" skill for detailed per-tool usage guidance.
15+
16+
Do NOT skip step 1. Do NOT use grep_search as a substitute for lsp_java_* tools on .java files.

0 commit comments

Comments
 (0)