fix: pass workspace symbol query to experimental LSP tool (#24576)
This commit is contained in:
@@ -29,6 +29,9 @@ export const Parameters = Schema.Struct({
|
|||||||
character: Schema.Number.check(Schema.isInt())
|
character: Schema.Number.check(Schema.isInt())
|
||||||
.check(Schema.isGreaterThanOrEqualTo(1))
|
.check(Schema.isGreaterThanOrEqualTo(1))
|
||||||
.annotate({ description: "The character offset (1-based, as shown in editors)" }),
|
.annotate({ description: "The character offset (1-based, as shown in editors)" }),
|
||||||
|
query: Schema.optional(Schema.String).annotate({
|
||||||
|
description: "Search query for workspaceSymbol. Empty string requests all symbols.",
|
||||||
|
}),
|
||||||
})
|
})
|
||||||
|
|
||||||
export const LspTool = Tool.define(
|
export const LspTool = Tool.define(
|
||||||
@@ -40,7 +43,7 @@ export const LspTool = Tool.define(
|
|||||||
description: DESCRIPTION,
|
description: DESCRIPTION,
|
||||||
parameters: Parameters,
|
parameters: Parameters,
|
||||||
execute: (
|
execute: (
|
||||||
args: { operation: (typeof operations)[number]; filePath: string; line: number; character: number },
|
args: Schema.Schema.Type<typeof Parameters>,
|
||||||
ctx: Tool.Context,
|
ctx: Tool.Context,
|
||||||
) =>
|
) =>
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
@@ -89,7 +92,7 @@ export const LspTool = Tool.define(
|
|||||||
case "documentSymbol":
|
case "documentSymbol":
|
||||||
return lsp.documentSymbol(uri)
|
return lsp.documentSymbol(uri)
|
||||||
case "workspaceSymbol":
|
case "workspaceSymbol":
|
||||||
return lsp.workspaceSymbol("")
|
return lsp.workspaceSymbol(args.query ?? "")
|
||||||
case "goToImplementation":
|
case "goToImplementation":
|
||||||
return lsp.implementation(position)
|
return lsp.implementation(position)
|
||||||
case "prepareCallHierarchy":
|
case "prepareCallHierarchy":
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ Supported operations:
|
|||||||
- findReferences: Find all references to a symbol
|
- findReferences: Find all references to a symbol
|
||||||
- hover: Get hover information (documentation, type info) for a symbol
|
- hover: Get hover information (documentation, type info) for a symbol
|
||||||
- documentSymbol: Get all symbols (functions, classes, variables) in a document
|
- documentSymbol: Get all symbols (functions, classes, variables) in a document
|
||||||
- workspaceSymbol: Search for symbols across the entire workspace
|
- workspaceSymbol: List project-wide symbols matching a query string
|
||||||
- goToImplementation: Find implementations of an interface or abstract method
|
- goToImplementation: Find implementations of an interface or abstract method
|
||||||
- prepareCallHierarchy: Get call hierarchy item at a position (functions/methods)
|
- prepareCallHierarchy: Get call hierarchy item at a position (functions/methods)
|
||||||
- incomingCalls: Find all functions/methods that call the function at a position
|
- incomingCalls: Find all functions/methods that call the function at a position
|
||||||
@@ -16,4 +16,9 @@ All operations require:
|
|||||||
- line: The line number (1-based, as shown in editors)
|
- line: The line number (1-based, as shown in editors)
|
||||||
- character: The character offset (1-based, as shown in editors)
|
- character: The character offset (1-based, as shown in editors)
|
||||||
|
|
||||||
|
workspaceSymbol also accepts:
|
||||||
|
- query: A query string to filter symbols by. Empty string requests all symbols.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
Note: LSP servers must be configured for the file type. If no server is available, an error will be returned.
|
Note: LSP servers must be configured for the file type. If no server is available, an error will be returned.
|
||||||
|
|||||||
@@ -209,6 +209,10 @@ exports[`tool parameters JSON Schema (wire shape) lsp 1`] = `
|
|||||||
],
|
],
|
||||||
"type": "string",
|
"type": "string",
|
||||||
},
|
},
|
||||||
|
"query": {
|
||||||
|
"description": "Search query for workspaceSymbol. Empty string requests all symbols.",
|
||||||
|
"type": "string",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
"required": [
|
"required": [
|
||||||
"operation",
|
"operation",
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ const ctx = {
|
|||||||
ask: () => Effect.void,
|
ask: () => Effect.void,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const workspaceSymbolQueries: string[] = []
|
||||||
|
|
||||||
const lsp = Layer.succeed(
|
const lsp = Layer.succeed(
|
||||||
LSP.Service,
|
LSP.Service,
|
||||||
LSP.Service.of({
|
LSP.Service.of({
|
||||||
@@ -41,7 +43,11 @@ const lsp = Layer.succeed(
|
|||||||
references: () => Effect.succeed([]),
|
references: () => Effect.succeed([]),
|
||||||
implementation: () => Effect.succeed([]),
|
implementation: () => Effect.succeed([]),
|
||||||
documentSymbol: () => Effect.succeed([]),
|
documentSymbol: () => Effect.succeed([]),
|
||||||
workspaceSymbol: () => Effect.succeed([]),
|
workspaceSymbol: (query) =>
|
||||||
|
Effect.sync(() => {
|
||||||
|
workspaceSymbolQueries.push(query)
|
||||||
|
return []
|
||||||
|
}),
|
||||||
prepareCallHierarchy: () => Effect.succeed([]),
|
prepareCallHierarchy: () => Effect.succeed([]),
|
||||||
incomingCalls: () => Effect.succeed([]),
|
incomingCalls: () => Effect.succeed([]),
|
||||||
outgoingCalls: () => Effect.succeed([]),
|
outgoingCalls: () => Effect.succeed([]),
|
||||||
@@ -142,6 +148,7 @@ describe("tool.lsp", () => {
|
|||||||
provideTmpdirInstance(
|
provideTmpdirInstance(
|
||||||
(dir) =>
|
(dir) =>
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
|
workspaceSymbolQueries.length = 0
|
||||||
const file = path.join(dir, "test.ts")
|
const file = path.join(dir, "test.ts")
|
||||||
yield* put(file)
|
yield* put(file)
|
||||||
|
|
||||||
@@ -158,5 +165,22 @@ describe("tool.lsp", () => {
|
|||||||
{ git: true },
|
{ git: true },
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
it.live("passes workspaceSymbol query to LSP", () =>
|
||||||
|
provideTmpdirInstance(
|
||||||
|
(dir) =>
|
||||||
|
Effect.gen(function* () {
|
||||||
|
workspaceSymbolQueries.length = 0
|
||||||
|
const file = path.join(dir, "test.ts")
|
||||||
|
yield* put(file)
|
||||||
|
|
||||||
|
yield* run({ operation: "workspaceSymbol", filePath: file, line: 3, character: 7, query: "TestSymbol" })
|
||||||
|
yield* run({ operation: "workspaceSymbol", filePath: file, line: 3, character: 7 })
|
||||||
|
|
||||||
|
expect(workspaceSymbolQueries).toEqual(["TestSymbol", ""])
|
||||||
|
}),
|
||||||
|
{ git: true },
|
||||||
|
),
|
||||||
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user