import type { EditorView } from "@codemirror/view"; import type { Text } from "@codemirror/state"; import { LSPClient } from "@codemirror/lsp-client"; import { LspTransportAdapter } from "./transport-adapter"; import { type DisplayFileFn } from "./workspace"; import type { CompletionItem, CompletionList, Hover, Position } from "./types"; import type { LogContext } from "../log/log"; import type { LspServerConfig } from "../../mini-code"; import { Signal, type ReadonlySignal } from "@ncpa0cpl/vanilla-jsx/signals"; export type LspStatus = "initializing" | "running" | "exited"; export interface LspEntry { id: number; name: string; client: LSPClient | null; /** Whether this is the primary server for its extensions. */ primary: boolean; /** Extensions this entry serves (e.g. [".ts", ".tsx", ".js", ".jsx"]). */ extensions: string[]; /** The original server config used to create this entry. */ config: LspServerConfig; awaiter: Promise; status: Signal; transport?: LspTransportAdapter; } export declare function languageIdForExt(ext: string): string; export declare class LspManager { private servers; private rootUri; private displayFileFn; private logs?; private clients; private documents; private diagnosticsByUri; private watchedFiles; private nextLspID; constructor(servers: LspServerConfig[], rootUri: string, displayFileFn: DisplayFileFn, logs?: LogContext | undefined); updateClients(update: (client: Map) => void): void; /** * Returns a derived signal of all unique LSP entries (deduplicated by ID, * since the same entry appears under multiple extensions in the clients map). */ allEntries(): ReadonlySignal; hasLsp(ext: string | undefined): boolean; /** Whether minicode's custom hover tooltip should be used for this file. */ useCustomHover(ext: string | undefined): boolean; getClientsFor(ext: string): LSPClient[]; /** * Eagerly creates the LSP clients for a file extension (if not already * created) and returns the primary client. The client starts initializing * immediately; `client.plugin(...)` may be called on the returned client * even before it is connected — its `didOpen` waits on `client.initializing`. */ ensurePrimaryClient(ext: string): LSPClient | null; /** * Finds the LSP entry with the given ID, disconnects its client, creates a * fresh client from the same server config, and replaces the old entry. * * For secondary entries, re-sends `textDocument/didOpen` for all currently * open documents matching the entry's extensions. * * For primary entries, the caller is responsible for reconfiguring editor * extensions (which triggers `workspace.openFile` → `didOpen` to the new * server through the plugin lifecycle). * * Returns the new entry, or null if no entry with the given ID exists. */ restartLsp(id: number): LspEntry | null; /** * Returns the extensions served by the LSP entry with the given ID, or * null if no such entry exists. Used by the caller to determine which * editors need reconfiguration after a restart. */ getLspExtensions(id: number): string[] | null; private getEntries; private createServerEntry; /** * Handles server-initiated requests. Currently only `client/registerCapability` * is processed — when the server registers `workspace/didChangeWatchedFiles`, * the watcher glob patterns are parsed and added to the file-watching * registry. All other requests are acknowledged with `result: null`. */ private handleServerRequest; /** * Registers fallback file patterns for a client based on the file * extension. Used for servers (like tsserver) that don't dynamically * register `workspace/didChangeWatchedFiles`. */ private setupFallbackFileWatching; private registerWatchedFiles; /** * Called by the host (MiniCodeContext) when a file change is detected by the * filesystem watcher. Forwards `workspace/didChangeWatchedFiles` * notifications to any LSP client whose registered patterns match the * changed file. * * @param relPath - Path relative to the workspace root. * @param eventType - `"change"` or `"rename"` (create/delete/rename). */ onFileChange(relPath: string, eventType: string): void; openDocument(ext: string, filePath: string, content: string, view: EditorView): Promise; private requestDiagnostics; changeDocument(filePath: string): void; closeDocument(filePath: string): void; completion(ext: string, filePath: string, pos: number, doc: Text): Promise; /** * Resolves a completion item via `completionItem/resolve`. Returns the * resolved item (which may include `additionalTextEdits` for auto-imports), * or null if no server could resolve it. */ resolveCompletion(ext: string, item: CompletionItem): Promise; hover(ext: string, filePath: string, pos: number, doc: Text): Promise; private updateDiagnostics; private applyDiagnostics; dispose(): void; } export declare function cmToLspPos(doc: Text, pos: number): Position; export declare function lspToCmPos(doc: Text, pos: Position): number; //# sourceMappingURL=manager.d.ts.map