Skip to content

Commit 6222334

Browse files
wenytang-msCopilot
andcommitted
Remove speculative Java location suffix handling
Keep the PR focused on the evidence-backed findSymbol handoff contract. Do not claim getFileStructure accepts path:line inputs without telemetry proving that case. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent e5f1e9d commit 6222334

4 files changed

Lines changed: 5 additions & 27 deletions

File tree

package.json

Lines changed: 2 additions & 2 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 a known Java file's outline: classes, interfaces, methods, fields, symbol kinds, and line ranges, to pick a precise read_file range instead of reading the whole file.\n\nUse after lsp_java_findSymbol returns outlineInput/file, or when the user gave a Java file path; do not guess paths. This accepts a workspace-relative Java path and tolerates a trailing line suffix such as src/Foo.java:42. Not for workspace-wide search\u2014use lsp_java_findSymbol for that. Do not re-call for the same file unless the first result was empty.",
55+
"modelDescription": "Get a known Java file's outline: classes, interfaces, methods, fields, symbol kinds, and line ranges, to pick a precise read_file range instead of reading the whole file.\n\nUse after lsp_java_findSymbol returns outlineInput/file, or when the user gave a Java file path; do not guess paths. Not for workspace-wide search\u2014use lsp_java_findSymbol for that. Do not re-call for the same file unless the first result was empty.",
5656
"displayName": "Java: Get File Structure",
5757
"userDescription": "Get a Java file outline with classes, methods, fields, and line ranges.",
5858
"tags": [
@@ -69,7 +69,7 @@
6969
"properties": {
7070
"uri": {
7171
"type": "string",
72-
"description": "Workspace-relative path to a Java file. Prefer outlineInput or file returned by lsp_java_findSymbol. A trailing line suffix like src/Foo.java:42 is tolerated. Must be a known path from prior tool results or user input — do not guess."
72+
"description": "Workspace-relative path to a Java file. Prefer outlineInput or file returned by lsp_java_findSymbol. Must be a known path from prior tool results or user input — do not guess."
7373
}
7474
},
7575
"required": [

resources/instruments/javaLspContext.instructions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ If these tools are not already available in the current tool list, load them wit
1212

1313
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 `read_file` on the returned `file`/`range`, or call `lsp_java_getFileStructure` with `outlineInput` when broader file context is needed.
1414

15-
Use `lsp_java_getFileStructure` only with a path confirmed by the user or a previous tool result. Prefer `outlineInput` or `file` from `findSymbol`; a trailing line suffix such as `src/Foo.java:42` is tolerated, but 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.
15+
Use `lsp_java_getFileStructure` only with a path confirmed by the user or a previous tool result. Prefer `outlineInput` or `file` from `findSymbol`; 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.

resources/skills/java-lsp-tools/SKILL.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Search for Java symbol definitions (classes, methods, fields) by name across the
1818

1919
### `lsp_java_getFileStructure`
2020
Get hierarchical outline of a Java file (classes, methods, fields) with line ranges.
21-
- Input: `{ uri }` — workspace-relative path. Prefer `outlineInput` or `file` from `lsp_java_findSymbol`; a trailing line suffix such as `src/Foo.java:42` is tolerated. Must be a known path from prior tool results or user input — do not guess
21+
- Input: `{ uri }` — workspace-relative path. Prefer `outlineInput` or `file` from `lsp_java_findSymbol`. Must be a known path from prior tool results or user input — do not guess
2222
- Output: symbol tree with `L start-end` ranges (~100 tokens)
2323
- **Use before** `read_file` when you need to choose a precise line range in a known Java file
2424

src/copilot/tools/javaContextTools.ts

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -79,33 +79,11 @@ function getToolErrorCode(error: unknown): string {
7979
return "unexpectedError";
8080
}
8181

82-
function stripJavaLocationSuffix(input: string): string {
83-
let normalized = input.trim();
84-
if (normalized.length >= 2) {
85-
const first = normalized[0];
86-
const last = normalized[normalized.length - 1];
87-
if ((first === "\"" && last === "\"") || (first === "'" && last === "'") || (first === "`" && last === "`")) {
88-
normalized = normalized.substring(1, normalized.length - 1).trim();
89-
}
90-
}
91-
92-
const javaExt = ".java";
93-
const javaIndex = normalized.toLowerCase().lastIndexOf(javaExt);
94-
if (javaIndex < 0) {
95-
return normalized;
96-
}
97-
98-
const fileEnd = javaIndex + javaExt.length;
99-
const suffix = normalized.substring(fileEnd);
100-
return /^:L?\d+(?:[-:]\d+)?$/i.test(suffix) ? normalized.substring(0, fileEnd) : normalized;
101-
}
102-
10382
/**
10483
* Resolve a file path to a vscode.Uri.
10584
* Accepts:
10685
* - Full file URI: "file:///home/user/project/src/Main.java"
10786
* - Relative path: "src/main/java/Main.java"
108-
* - Location string: "src/main/java/Main.java:42"
10987
* - Absolute path: "/home/user/project/src/Main.java" or "C:\\Users\\...\\Main.java"
11088
*
11189
* Relative paths are resolved against the first workspace folder unless they
@@ -119,7 +97,7 @@ function resolveFileUri(input: string): vscode.Uri {
11997
}
12098

12199
let uri: vscode.Uri;
122-
const normalizedInput = stripJavaLocationSuffix(input);
100+
const normalizedInput = input.trim();
123101

124102
if (normalizedInput.includes("://")) {
125103
// URI string (e.g. "file:///home/user/project/src/Main.java")

0 commit comments

Comments
 (0)