Skip to content

Commit 8718b98

Browse files
authored
fix: pass workspace symbol query to experimental LSP tool (#24576)
1 parent c8b2f98 commit 8718b98

4 files changed

Lines changed: 40 additions & 4 deletions

File tree

packages/opencode/src/tool/lsp.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ export const Parameters = Schema.Struct({
2929
character: Schema.Number.check(Schema.isInt())
3030
.check(Schema.isGreaterThanOrEqualTo(1))
3131
.annotate({ description: "The character offset (1-based, as shown in editors)" }),
32+
query: Schema.optional(Schema.String).annotate({
33+
description: "Search query for workspaceSymbol. Empty string requests all symbols.",
34+
}),
3235
})
3336

3437
export const LspTool = Tool.define(
@@ -40,7 +43,7 @@ export const LspTool = Tool.define(
4043
description: DESCRIPTION,
4144
parameters: Parameters,
4245
execute: (
43-
args: { operation: (typeof operations)[number]; filePath: string; line: number; character: number },
46+
args: Schema.Schema.Type<typeof Parameters>,
4447
ctx: Tool.Context,
4548
) =>
4649
Effect.gen(function* () {
@@ -89,7 +92,7 @@ export const LspTool = Tool.define(
8992
case "documentSymbol":
9093
return lsp.documentSymbol(uri)
9194
case "workspaceSymbol":
92-
return lsp.workspaceSymbol("")
95+
return lsp.workspaceSymbol(args.query ?? "")
9396
case "goToImplementation":
9497
return lsp.implementation(position)
9598
case "prepareCallHierarchy":

packages/opencode/src/tool/lsp.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Supported operations:
55
- findReferences: Find all references to a symbol
66
- hover: Get hover information (documentation, type info) for a symbol
77
- documentSymbol: Get all symbols (functions, classes, variables) in a document
8-
- workspaceSymbol: Search for symbols across the entire workspace
8+
- workspaceSymbol: List project-wide symbols matching a query string
99
- goToImplementation: Find implementations of an interface or abstract method
1010
- prepareCallHierarchy: Get call hierarchy item at a position (functions/methods)
1111
- incomingCalls: Find all functions/methods that call the function at a position
@@ -16,4 +16,9 @@ All operations require:
1616
- line: The line number (1-based, as shown in editors)
1717
- character: The character offset (1-based, as shown in editors)
1818

19+
workspaceSymbol also accepts:
20+
- query: A query string to filter symbols by. Empty string requests all symbols.
21+
22+
For workspaceSymbol, filePath is not sent in the LSP workspace/symbol request. It is used by opencode to select and start the matching LSP server.
23+
1924
Note: LSP servers must be configured for the file type. If no server is available, an error will be returned.

packages/opencode/test/tool/__snapshots__/parameters.test.ts.snap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@ exports[`tool parameters JSON Schema (wire shape) lsp 1`] = `
209209
],
210210
"type": "string",
211211
},
212+
"query": {
213+
"description": "Search query for workspaceSymbol. Empty string requests all symbols.",
214+
"type": "string",
215+
},
212216
},
213217
"required": [
214218
"operation",

packages/opencode/test/tool/lsp.test.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ const ctx = {
2828
ask: () => Effect.void,
2929
}
3030

31+
const workspaceSymbolQueries: string[] = []
32+
3133
const lsp = Layer.succeed(
3234
LSP.Service,
3335
LSP.Service.of({
@@ -41,7 +43,11 @@ const lsp = Layer.succeed(
4143
references: () => Effect.succeed([]),
4244
implementation: () => Effect.succeed([]),
4345
documentSymbol: () => Effect.succeed([]),
44-
workspaceSymbol: () => Effect.succeed([]),
46+
workspaceSymbol: (query) =>
47+
Effect.sync(() => {
48+
workspaceSymbolQueries.push(query)
49+
return []
50+
}),
4551
prepareCallHierarchy: () => Effect.succeed([]),
4652
incomingCalls: () => Effect.succeed([]),
4753
outgoingCalls: () => Effect.succeed([]),
@@ -142,6 +148,7 @@ describe("tool.lsp", () => {
142148
provideTmpdirInstance(
143149
(dir) =>
144150
Effect.gen(function* () {
151+
workspaceSymbolQueries.length = 0
145152
const file = path.join(dir, "test.ts")
146153
yield* put(file)
147154

@@ -158,5 +165,22 @@ describe("tool.lsp", () => {
158165
{ git: true },
159166
),
160167
)
168+
169+
it.live("passes workspaceSymbol query to LSP", () =>
170+
provideTmpdirInstance(
171+
(dir) =>
172+
Effect.gen(function* () {
173+
workspaceSymbolQueries.length = 0
174+
const file = path.join(dir, "test.ts")
175+
yield* put(file)
176+
177+
yield* run({ operation: "workspaceSymbol", filePath: file, line: 3, character: 7, query: "TestSymbol" })
178+
yield* run({ operation: "workspaceSymbol", filePath: file, line: 3, character: 7 })
179+
180+
expect(workspaceSymbolQueries).toEqual(["TestSymbol", ""])
181+
}),
182+
{ git: true },
183+
),
184+
)
161185
})
162186
})

0 commit comments

Comments
 (0)