| import { z } from 'zod/v4' |
| import { lazySchema } from '../../utils/lazySchema.js' |
|
|
| |
| |
| |
| |
| export const lspToolInputSchema = lazySchema(() => { |
| |
| |
| |
| |
| 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)'), |
| }) |
|
|
| |
| |
| |
| |
| 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)'), |
| }) |
|
|
| |
| |
| |
| |
| 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)'), |
| }) |
|
|
| |
| |
| |
| |
| 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)'), |
| }) |
|
|
| |
| |
| |
| |
| 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)'), |
| }) |
|
|
| |
| |
| |
| |
| 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)'), |
| }) |
|
|
| |
| |
| |
| |
| 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)'), |
| }) |
|
|
| |
| |
| |
| |
| 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)'), |
| }) |
|
|
| |
| |
| |
| |
| 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, |
| ]) |
| }) |
|
|
| |
| |
| |
| export type LSPToolInput = z.infer<ReturnType<typeof lspToolInputSchema>> |
|
|
| |
| |
| |
| export function isValidLSPOperation( |
| operation: string, |
| ): operation is LSPToolInput['operation'] { |
| return [ |
| 'goToDefinition', |
| 'findReferences', |
| 'hover', |
| 'documentSymbol', |
| 'workspaceSymbol', |
| 'goToImplementation', |
| 'prepareCallHierarchy', |
| 'incomingCalls', |
| 'outgoingCalls', |
| ].includes(operation) |
| } |
|
|