Skip to main content
Glama

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
NameRequiredDescriptionDefault
filePathYesAbsolute path to the file
symbolNameYesName of the symbol to get completions at (positions cursor at the symbol)
symbolKindNoKind of symbol
limitNoMax items to return. Default: 30

Implementation Reference

  • 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));
        }
      }
    );
  • 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"),
    }),
  • 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));
        }
      }
    );

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/adainrivers/SvelteLS.MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server