π File detail
tools/LSPTool/schemas.ts
π§© .tsπ 216 linesπΎ 6,064 bytesπ text
β Back to All Filesπ― Use case
This module implements the βLSPToolβ tool (L S P) β something the model can call at runtime alongside other agent tools. On the API surface it exposes lspToolInputSchema, LSPToolInput, and isValidLSPOperation β mainly functions, hooks, or classes. Dependencies touch schema validation. It composes internal code from utils (relative imports).
Generated from folder role, exports, dependency roots, and inline comments β not hand-reviewed for every path.
π§ Inline summary
import { z } from 'zod/v4' import { lazySchema } from '../../utils/lazySchema.js' /** * Discriminated union of all LSP operations
π€ Exports (heuristic)
lspToolInputSchemaLSPToolInputisValidLSPOperation
π External import roots
Package roots from from "β¦" (relative paths omitted).
zod
π₯οΈ Source preview
import { z } from 'zod/v4'
import { lazySchema } from '../../utils/lazySchema.js'
/**
* Discriminated union of all LSP operations
* Uses 'operation' as the discriminator field
*/
export const lspToolInputSchema = lazySchema(() => {
/**
* Go to Definition operation
* Finds the definition location of a symbol at the given position
*/
const goToDefinitionSchema = z.strictObject({
operation: z.literal('goToDefinition'),
filePath: z.string().describe('The absolute or relative path to the file'),
line: z
.number()
.int()
.positive()
.describe('The line number (1-based, as shown in editors)'),
character: z
.number()
.int()
.positive()
.describe('The character offset (1-based, as shown in editors)'),
})
/**
* Find References operation
* Finds all references to a symbol at the given position
*/
const findReferencesSchema = z.strictObject({
operation: z.literal('findReferences'),
filePath: z.string().describe('The absolute or relative path to the file'),
line: z
.number()
.int()
.positive()
.describe('The line number (1-based, as shown in editors)'),
character: z
.number()
.int()
.positive()
.describe('The character offset (1-based, as shown in editors)'),
})
/**
* Hover operation
* Gets hover information (documentation, type info) for a symbol at the given position
*/
const hoverSchema = z.strictObject({
operation: z.literal('hover'),
filePath: z.string().describe('The absolute or relative path to the file'),
line: z
.number()
.int()
.positive()
.describe('The line number (1-based, as shown in editors)'),
character: z
.number()
.int()
.positive()
.describe('The character offset (1-based, as shown in editors)'),
})
/**
* Document Symbol operation
* Gets all symbols (functions, classes, variables) in a document
*/
const documentSymbolSchema = z.strictObject({
operation: z.literal('documentSymbol'),
filePath: z.string().describe('The absolute or relative path to the file'),
line: z
.number()
.int()
.positive()
.describe('The line number (1-based, as shown in editors)'),
character: z
.number()
.int()
.positive()
.describe('The character offset (1-based, as shown in editors)'),
})
/**
* Workspace Symbol operation
* Searches for symbols across the entire workspace
*/
const workspaceSymbolSchema = z.strictObject({
operation: z.literal('workspaceSymbol'),
filePath: z.string().describe('The absolute or relative path to the file'),
line: z
.number()
.int()
.positive()
.describe('The line number (1-based, as shown in editors)'),
character: z
.number()
.int()
.positive()
.describe('The character offset (1-based, as shown in editors)'),
})
/**
* Go to Implementation operation
* Finds the implementation locations of an interface or abstract method
*/
const goToImplementationSchema = z.strictObject({
operation: z.literal('goToImplementation'),
filePath: z.string().describe('The absolute or relative path to the file'),
line: z
.number()
.int()
.positive()
.describe('The line number (1-based, as shown in editors)'),
character: z
.number()
.int()
.positive()
.describe('The character offset (1-based, as shown in editors)'),
})
/**
* Prepare Call Hierarchy operation
* Prepares a call hierarchy item at the given position (first step for call hierarchy)
*/
const prepareCallHierarchySchema = z.strictObject({
operation: z.literal('prepareCallHierarchy'),
filePath: z.string().describe('The absolute or relative path to the file'),
line: z
.number()
.int()
.positive()
.describe('The line number (1-based, as shown in editors)'),
character: z
.number()
.int()
.positive()
.describe('The character offset (1-based, as shown in editors)'),
})
/**
* Incoming Calls operation
* Finds all functions/methods that call the function at the given position
*/
const incomingCallsSchema = z.strictObject({
operation: z.literal('incomingCalls'),
filePath: z.string().describe('The absolute or relative path to the file'),
line: z
.number()
.int()
.positive()
.describe('The line number (1-based, as shown in editors)'),
character: z
.number()
.int()
.positive()
.describe('The character offset (1-based, as shown in editors)'),
})
/**
* Outgoing Calls operation
* Finds all functions/methods called by the function at the given position
*/
const outgoingCallsSchema = z.strictObject({
operation: z.literal('outgoingCalls'),
filePath: z.string().describe('The absolute or relative path to the file'),
line: z
.number()
.int()
.positive()
.describe('The line number (1-based, as shown in editors)'),
character: z
.number()
.int()
.positive()
.describe('The character offset (1-based, as shown in editors)'),
})
return z.discriminatedUnion('operation', [
goToDefinitionSchema,
findReferencesSchema,
hoverSchema,
documentSymbolSchema,
workspaceSymbolSchema,
goToImplementationSchema,
prepareCallHierarchySchema,
incomingCallsSchema,
outgoingCallsSchema,
])
})
/**
* TypeScript type for LSPTool input
*/
export type LSPToolInput = z.infer<ReturnType<typeof lspToolInputSchema>>
/**
* Type guard to check if an operation is a valid LSP operation
*/
export function isValidLSPOperation(
operation: string,
): operation is LSPToolInput['operation'] {
return [
'goToDefinition',
'findReferences',
'hover',
'documentSymbol',
'workspaceSymbol',
'goToImplementation',
'prepareCallHierarchy',
'incomingCalls',
'outgoingCalls',
].includes(operation)
}