// Shared types: LSP layer (ported from pi-lsp) and the unified runner layer // (RunnerDefinition/RunnerResult, distilled from pi-lens's dispatch types). // --- LSP layer --- export interface ServerCommand { command: string; args: string[]; } export interface StatusContext { ui: { setStatus: (key: string, value: string | undefined) => void }; } export interface LspPosition { line: number; character: number; } export interface LspRange { start: LspPosition; end: LspPosition; } export interface LspDiagnostic { range: LspRange; severity?: number; code?: string | number; codeDescription?: { href?: string }; source?: string; message: string; } export interface LspTextEdit { range: LspRange; newText: string; } export interface WorkspaceEdit { changes?: Record; documentChanges?: Array<{ textDocument?: { uri?: string; version?: number | null }; edits?: LspTextEdit[]; }>; } export interface CodeAction { title: string; kind?: string; edit?: WorkspaceEdit; data?: unknown; } export interface DiagnosticEntry { path: string; uri: string; diagnostics: LspDiagnostic[]; /** Set when this file's diagnostics failed; diagnostics is then unused. */ error?: string; } export interface JsonRpcMessage { jsonrpc?: "2.0"; id?: number | string | null; method?: string; params?: unknown; result?: unknown; error?: { code: number; message: string; data?: unknown }; } export interface ConfiguredLspServer { command: string[]; extensions: string[]; /** Overrides the generic "Install to enable it" hint. */ missingCommandHint?: string; env?: Record; initialization?: Record; skipDirectories?: string[]; /** Extra spawn environment computed from the workspace root (see LspServerAdapter). */ spawnEnv?: (cwd: string) => Record | undefined; /** Attempt a best-effort package-manager install when the server is missing. */ autoInstall?: boolean; /** * Per-server timeout override (ms) for LSP requests, replacing the global * default. Cold-start servers that index the whole project on the first * pull (tsserver over a full tree) need a larger budget than lanes that * answer per-file. */ timeoutMs?: number; /** Ordered install candidates tried when the server command is missing. */ installRecipes?: InstallRecipe[]; /** Full custom installer (e.g. download-and-extract servers without a package-manager channel). */ customInstaller?: CustomInstaller; // Quiet period in ms after the latest push-diagnostics publication. diagnosticsSettleMs?: number; // Maximum wait for a push-only server that publishes nothing for a clean document. pushDiagnosticsGraceMs?: number; // Maximum wait for a newer push publication after an empty pull result. pullDiagnosticsGraceMs?: number; } export interface LspConfig { timeout?: number; servers: InternalLspServer[]; } export interface InternalLspServer extends ConfiguredLspServer { name: string; isDefault?: boolean; } export interface LspServerAdapter { name: string; isDefault: boolean; defaultCommand: ServerCommand; missingCommandHint: string; extensions: string[]; /** Per-server timeout override for LSP requests (see ConfiguredLspServer). */ timeoutMs?: number; env?: Record; /** Attempt a best-effort package-manager install when the server is missing. */ autoInstall?: boolean; /** Ordered install candidates tried when the server command is missing. */ installRecipes?: InstallRecipe[]; /** Full custom installer (e.g. download-and-extract servers without a package-manager channel). */ customInstaller?: CustomInstaller; initialization?: Record; skipDirectories: Set; diagnosticsSettleMs?: number; pushDiagnosticsGraceMs?: number; pullDiagnosticsGraceMs?: number; isSupportedFile: (filePath: string) => boolean; languageIdFor: (filePath: string) => string; /** * Extra environment variables for this server's spawn, computed from the * workspace root (e.g. jdtls's per-workspace -data directory). Environment * values bypass shell parsing, so they are safe for paths containing * cmd.exe metacharacters that a wrapper script could not carry itself. */ spawnEnv?: (cwd: string) => Record | undefined; } /** * One best-effort install candidate for a missing LSP server, mirroring the * CLI runner's InstallCandidate shape. verifyArgs (default ["--version"]) is * used for the post-install probe of the LSP command itself. An empty array * skips the probe — for servers that treat any argument as a connection flag * and would hang or exit non-zero (e.g. intelephense), resolvability alone * must be accepted. */ export interface InstallRecipe { label: string; command: string; args: string[]; verifyArgs?: string[]; } /** A server-specific installer run when the command is missing on PATH. */ export type CustomInstaller = ( cwd: string, signal: AbortSignal | undefined, ) => Promise; export interface CustomInstallOutcome { installed: boolean; detail: string; } export interface DiagnosticSummary { files: number; diagnostics: number; } // --- Runner layer (pi-lens-inspired, minimal) --- export type Severity = "error" | "warning" | "info" | "hint"; /** A single finding, normalized across LSP servers and CLI runners. */ export interface Diagnostic { filePath: string; line: number; column: number; endLine: number; endColumn: number; severity: Severity; message: string; tool: string; rule?: string; fixable: boolean; } /** Closed taxonomy of runner failures, borrowed from pi-lens's honesty rules: * a finding-bearing run is a completed check, not a broken runner. */ export type RunnerFailureKind = "timeout" | "exception" | "parser_error"; /** Bounded reason for an expected skip. */ export type RunnerSkipReason = "no-files-matched" | "unavailable"; export interface RunnerResult { tool: string; status: "succeeded" | "failed" | "skipped"; diagnostics: Diagnostic[]; files: string[]; durationMs: number; /** Machine-readable reason when status === "failed". */ failureKind?: RunnerFailureKind; failureMessage?: string; skipReason?: RunnerSkipReason; /** Set when this run auto-installed the missing CLI tool. */ autoInstalled?: boolean; /** Detail about a failed auto-install attempt (attached to the skip). */ installDetail?: string; } export interface RunnerContext { root: string; /** Files already filtered to this runner's extensions. */ files: string[]; signal: AbortSignal | undefined; /** Effective wall-clock timeout for one run: runner override or global default. */ timeoutMs: number; /** Whether this runner may auto-install its CLI when missing on PATH. */ autoInstall: boolean; /** Report one status-bar line for this lane (` installing` / ` check`). * The runner spells the text; the caller owns the status key and clears it. */ reportStatus?: (text: string) => void; } export interface RunnerDefinition { id: string; extensions: string[]; priority: number; /** The CLI binary name (first command token) for availability pre-checks. */ command?: string; /** Per-run timeout override in ms. */ timeoutMs?: number; /** Attempt a best-effort package-manager install when the CLI is missing. */ autoInstall?: boolean; run(ctx: RunnerContext): Promise; }