/** * Go language adapter. * * Wraps `gopls` spawned as a subprocess, speaking LSP over stdio. * Implements the `LanguageAdapter` interface from src/types.ts per * ADR-03 (adapters are plugins) and ADR-14 (gopls-specific mapping * decisions and runtime prerequisites). * * Every path crossing into or out of LSP goes through normalizePath() * (ADR-01). Symbol IDs use repo-relative forward-slash paths with * case-normalized drive letters. * * Runtime prerequisites worth knowing (both documented in ADR-14): * - The `go` binary must be on the process's PATH. Gopls spawns * `go` as a subprocess for module loading; without it every LSP * request returns "no views." The adapter runs a `go version` * preflight in initialize() and fails fast with an actionable * error if the binary is missing. * - The `workspace/configuration` handler must return a * length-matched array (pyright tolerates null; gopls does not). * Implemented in the constructor. */ import { type Diagnostic, type LanguageAdapter, type LanguageCode, type Reference, type Symbol as AtlasSymbol, type SymbolId, type SymbolKind, type TypeInfo } from "../types.js"; interface LspPosition { line: number; character: number; } interface LspRange { start: LspPosition; end: LspPosition; } interface LspDocumentSymbol { name: string; detail?: string; kind: number; range: LspRange; selectionRange: LspRange; children?: LspDocumentSymbol[]; } /** * Map gopls's LSP SymbolKind numbers to our reduced SymbolKind vocabulary. * ADR-14 §"Symbol-kind mapping" specifies: * - 5 Class (type definition OR type alias) → "class" * - 6 Method (interface methods + struct methods) → "method" * - 8 Field (struct fields, embedded fields, embedded-interface entries) * → "other" (we don't surface raw fields as top-level symbols) * - 11 Interface → "interface" * - 12 Function → "function" * - 13 Variable (package-level var) → "variable" * - 14 Constant (plain const + iota members) → "variable" * (per ADR-14 finding §6, iota members are flat top-level constants — * kept as "variable" in our reduced vocabulary since SymbolKind has * no "constant" value) * - 23 Struct → "class" * - anything else → "other" */ export declare function mapGoSymbolKind(lspKind: number): SymbolKind; export interface GoAdapterOptions { /** * Override the gopls binary path. Defaults to * `process.env.CONTEXTATLAS_GOPLS_BIN` when set, falling back to * `"gopls"` (resolved via PATH at spawn time). Tests use this to * point at a specific gopls installation independent of the shell's * PATH. */ cliPath?: string; /** Upper bound on a single LSP request. Defaults to 30s. */ requestTimeoutMs?: number; /** * Skip the `go version` preflight. Reserved for tests that stub the * LSP transport — production code should leave this at its default * `false` so the adapter fails fast when `go` is missing from PATH. */ skipGoPreflight?: boolean; /** * Override the `go` binary used by the preflight. Defaults to `"go"` * (resolved via PATH). Test-only; production users should put `go` * on PATH per ADR-14. */ goBin?: string; } export declare const GO_EXTENSIONS: readonly string[]; export declare class GoAdapter implements LanguageAdapter { readonly language: LanguageCode; readonly extensions: readonly string[]; private readonly client; private readonly options; private rootPath; private readonly openFiles; private readonly diagnosticsByUri; private readonly diagnosticsListeners; constructor(options?: GoAdapterOptions); initialize(rootPath: string): Promise; shutdown(): Promise; listSymbols(filePath: string): Promise; getSymbolDetails(id: SymbolId): Promise; findReferences(id: SymbolId): Promise; getDiagnostics(filePath: string): Promise; private ensureOpen; getDocstring(id: SymbolId): Promise; getTypeInfo(id: SymbolId): Promise; private symbolId; private referenceId; private resolveFile; } /** * Extract the doc-comment prose section from gopls hover output. * * gopls hover returns a three-section markdown structure (verified * empirically across 7 cobra symbols spanning surface-shape diversity * during Substep 10.1 spike — packages, types, vars, functions, methods, * deprecation markers, build-tag-aware vars): * * ``` * ```go * * ``` * --- * * --- * * ``` * * Section 2 (between the two `\n---\n` separators) is the doc-comment * prose — the load-bearing extraction target. Returns null when: * - Fewer than 2 sections exist (no `---` separator → likely no docstring) * - Section 2 is empty/whitespace-only (signature-only hover) * * Type/struct hover signature blocks are LONG (~200 LOC for cobra's * `type Command struct`) but the `\n---\n` split is content-agnostic * and remains reliable. See Step 10 docstring-probe-findings spike * notes in the v0.3 commit ladder for substantive findings. */ export declare function parseDocstringFromGoplsHover(hoverValue: string): string | null; /** * Parse a Go SymbolId (`sym:go::`) into its components. * Returns null for IDs that don't match the expected shape — callers * treat that as "no such symbol" rather than throwing. * * Go symbol names can contain `()`, `*`, `[`, `]`, and `.` from the * receiver encoding (`(*Rectangle).Area`, `(*Stack[T]).Push`, * `Shape.Area`) but never colons, so a greedy regex anchored on the * second `:` divides path from name cleanly. */ export declare function parseSymbolId(id: SymbolId): { path: string; name: string; } | null; /** * Locate the position of a symbol identified by `name` within the * documentSymbol tree. Handles three naming shapes uniformly: * - top-level plain names ("Shape", "NewRectangle") * - receiver-encoded struct-method names ("(*Rectangle).Area", * "(*Stack[T]).Push") — these are top-level symbols in gopls's * output, so a direct top-level match works * - flattened interface-method names ("Shape.Area") — not * top-level; split on the first dot and look up as parent.child * within the interface's children array */ export declare function findTargetPosition(symbols: LspDocumentSymbol[], name: string): LspPosition | null; /** * Walk a documentSymbol tree and return the innermost symbol whose * range contains the given position. Used by getTypeInfo to resolve * each `implementation` result location back to the declaring * symbol's name for the `implements` / `usedByTypes` partition. */ export declare function findEnclosingSymbol(symbols: LspDocumentSymbol[], pos: LspPosition): LspDocumentSymbol | null; /** * Run ` version` and resolve when it exits 0. Throws with an * actionable message when the subprocess can't be spawned or exits * non-zero — per ADR-14, this is the fail-fast path that surfaces a * missing `go` binary before gopls's "no views" cascade kicks in. */ export declare function runGoVersionPreflight(goBin: string): Promise; export {}; //# sourceMappingURL=go.d.ts.map