get_completion
Provides code completion suggestions for Svelte development by analyzing symbols to reveal available members, methods, and types.
Instructions
Get code completion suggestions at a symbol position. Useful for discovering available members, methods, and types.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filePath | Yes | Absolute path to the file | |
| symbolName | Yes | Name of the symbol to get completions at (positions cursor at the symbol) | |
| symbolKind | No | Kind of symbol | |
| limit | No | Max items to return. Default: 30 |
Implementation Reference
- src/tools/intellisense.ts:38-101 (handler)Handler function for the 'get_completion' tool that uses the LSP client to fetch and format completion suggestions.
async ({ filePath, symbolName, symbolKind, limit, }): Promise<ToolResult> => { try { const prep = await prepareSymbolRequest(lsp, filePath, symbolName, symbolKind); if ("error" in prep) return textResult(prep.error); const params = { ...makePositionParams(prep.ctx), context: { triggerKind: 1 }, // Invoked }; const result = await lsp.request("textDocument/completion", params); if (!result) return textResult("No completions available."); let items: any[]; if (Array.isArray(result)) { items = result; } else if (Array.isArray(result.items)) { items = result.items; } else { return textResult("No completions available."); } if (items.length === 0) return textResult("No completions available."); const lines: string[] = []; let shown = 0; for (const item of items) { if (shown >= limit) break; const label = item.label ?? "?"; const kindVal = item.kind ?? 0; const kindName = completionItemKindName(kindVal); const detail = item.detail; const labelDetail = item.labelDetails?.detail; const labelDesc = item.labelDetails?.description; let entry = ` ${label}`; if (labelDetail) entry += labelDetail; entry += ` (${kindName})`; if (detail) entry += ` - ${detail}`; if (labelDesc) entry += ` [${labelDesc}]`; lines.push(entry); shown++; } const header = shown < items.length ? `Showing ${shown} of ${items.length} completion(s)` : `Found ${items.length} completion(s)`; return textResult( `${header} at '${symbolName}':\n\n` + lines.join("\n") ); } catch (ex) { return textResult(formatError(ex)); } } ); - src/tools/intellisense.ts:22-36 (schema)Input schema definition for the 'get_completion' tool.
inputSchema: z.object({ filePath: z .string() .describe("Absolute path to the file"), symbolName: z .string() .describe( "Name of the symbol to get completions at (positions cursor at the symbol)" ), symbolKind: z.string().optional().describe("Kind of symbol"), limit: z .number() .default(30) .describe("Max items to return. Default: 30"), }), - src/tools/intellisense.ts:16-101 (registration)Registration of the 'get_completion' tool within the registerIntelliSenseTools function.
server.registerTool( "get_completion", { title: "Get Completion", description: "Get code completion suggestions at a symbol position. Useful for discovering available members, methods, and types.", inputSchema: z.object({ filePath: z .string() .describe("Absolute path to the file"), symbolName: z .string() .describe( "Name of the symbol to get completions at (positions cursor at the symbol)" ), symbolKind: z.string().optional().describe("Kind of symbol"), limit: z .number() .default(30) .describe("Max items to return. Default: 30"), }), }, async ({ filePath, symbolName, symbolKind, limit, }): Promise<ToolResult> => { try { const prep = await prepareSymbolRequest(lsp, filePath, symbolName, symbolKind); if ("error" in prep) return textResult(prep.error); const params = { ...makePositionParams(prep.ctx), context: { triggerKind: 1 }, // Invoked }; const result = await lsp.request("textDocument/completion", params); if (!result) return textResult("No completions available."); let items: any[]; if (Array.isArray(result)) { items = result; } else if (Array.isArray(result.items)) { items = result.items; } else { return textResult("No completions available."); } if (items.length === 0) return textResult("No completions available."); const lines: string[] = []; let shown = 0; for (const item of items) { if (shown >= limit) break; const label = item.label ?? "?"; const kindVal = item.kind ?? 0; const kindName = completionItemKindName(kindVal); const detail = item.detail; const labelDetail = item.labelDetails?.detail; const labelDesc = item.labelDetails?.description; let entry = ` ${label}`; if (labelDetail) entry += labelDetail; entry += ` (${kindName})`; if (detail) entry += ` - ${detail}`; if (labelDesc) entry += ` [${labelDesc}]`; lines.push(entry); shown++; } const header = shown < items.length ? `Showing ${shown} of ${items.length} completion(s)` : `Found ${items.length} completion(s)`; return textResult( `${header} at '${symbolName}':\n\n` + lines.join("\n") ); } catch (ex) { return textResult(formatError(ex)); } } );