{"modulePath":"github.com/memcode-ai/memcode","version":"v0.56.16","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package lsp\n\nPackage lsp is memcode's resident Language Server Protocol client — the \"give the agent eyes\" layer. It speaks JSON-RPC 2.0 over a language server's stdio (gopls, typescript-language-server, pyright), holding the server RESIDENT for the session so diagnostics are incremental (milliseconds, not a full re-typecheck) and semantic queries (definition / references / hover) are available. This is the capability no amount of grep + build gives, and the only static type-error source for TS/Python.\n\nModel (following Claude Code): DETECT AND CONNECT. A server is used only when its binary is on PATH; nothing is bundled or auto-installed. The valuable operations for an agent are diagnostics, definition, and references — completion is deliberately not implemented.\n\n## Functions\n\n```go\nfunc PathToURI(path string) string\n```\nPathToURI converts an absolute filesystem path to a file:// URI.\n\n```go\nfunc ServerBins() map[string]string\n```\nServerBins reports the registry's language → server binary (for doctor's missing-server check). javascript shares typescript's binary; callers that want one row per binary can dedupe on the value.\n\n```go\nfunc URIToPath(uri string) string\n```\nURIToPath converts a file:// URI back to a filesystem path (best-effort).\n\n## Types\n\n```go\ntype Client struct {\n\t// contains filtered or unexported fields\n}\n```\nClient is a JSON-RPC 2.0 client over one language server's stdio. It is created by the manager per language and reused across a session. Safe for concurrent Requests; the write side is mutex-guarded and responses are demuxed by id.\n\n```go\nfunc (c *Client) Close()\n```\nClose shuts the server down: a polite shutdown/exit, then kill if it lingers, and always reaps the process. Bounded: it never waits more than a few seconds.\n\n```go\nfunc (c *Client) Definition(ctx context.Context, uri string, pos Position) ([]Location, error)\n```\nDefinition returns where the symbol at pos is defined. Handles the server returning a single Location or an array (both are valid per the spec).\n\n```go\nfunc (c *Client) Diagnostics(uri string) []Diagnostic\n```\nDiagnostics returns the latest diagnostics the server pushed for uri. Callers that just opened/changed a file should give the server a moment to publish (see WaitDiagnostics).\n\n```go\nfunc (c *Client) DidChange(uri string, version int, text string) error\n```\nDidChange tells the server a document's full content changed (full-sync) — sent after an edit so its diagnostics reflect the new text. version must increase per document.\n\n```go\nfunc (c *Client) DidOpen(uri, languageID, text string) error\n```\nDidOpen tells the server about a document's content — required before it will produce diagnostics or answer position queries for that file.\n\n```go\nfunc (c *Client) DocumentSymbol(ctx context.Context, uri string) ([]DocumentSymbol, error)\n```\nDocumentSymbol returns the file's symbol tree. Handles both the hierarchical DocumentSymbol\\[] result (gopls/tsserver/pyright) and the flat SymbolInformation\\[] fallback.\n\n```go\nfunc (c *Client) Hover(ctx context.Context, uri string, pos Position) (string, error)\n```\nHover returns the type/signature/doc for the symbol at pos, flattened to text.\n\n```go\nfunc (c *Client) Initialize(ctx context.Context, root string) error\n```\nInitialize runs the LSP handshake with the workspace root, then sends \\`initialized\\`. The declared client capabilities are the minimal set our operations use.\n\n```go\nfunc (c *Client) References(ctx context.Context, uri string, pos Position) ([]Location, error)\n```\nReferences returns every use of the symbol at pos (including its declaration).\n\n```go\nfunc (c *Client) WaitDiagnostics(ctx context.Context, uri string, timeout time.Duration) []Diagnostic\n```\nWaitDiagnostics polls for diagnostics on uri up to timeout — diagnostics arrive as an async push after didOpen, so a caller that needs them right after opening waits briefly. Returns whatever is present at the deadline (empty means \"clean\" once the server settled).\n\n```go\ntype Diagnostic struct {\n\tRange    Range  `json:\"range\"`\n\tSeverity int    `json:\"severity\"` // 1 error, 2 warning, 3 info, 4 hint\n\tCode     any    `json:\"code\"`\n\tSource   string `json:\"source\"`\n\tMessage  string `json:\"message\"`\n}\n```\nDiagnostic is one problem the server reports for a document.\n\n```go\nfunc (d Diagnostic) SeverityLabel() string\n```\nSeverityLabel renders the numeric severity as text.\n\n```go\ntype DocumentSymbol struct {\n\tName           string           `json:\"name\"`\n\tKind           int              `json:\"kind\"`\n\tRange          Range            `json:\"range\"`\n\tSelectionRange Range            `json:\"selectionRange\"`\n\tChildren       []DocumentSymbol `json:\"children,omitempty\"`\n}\n```\nDocumentSymbol is a named symbol in a file (LSP documentSymbol). Range is the full span (declaration + body); SelectionRange is the name token. Children nest (a method inside a type). Used to attribute a reference to the function/method that contains it.\n\n```go\ntype EnclosingSymbol struct {\n\tName    string\n\tKind    int\n\tPath    string // absolute file path (as queried)\n\tDefLine int    // 1-based line of the symbol name (its selectionRange start)\n\tDefCol  int    // 1-based column\n}\n```\nEnclosingSymbol is the named symbol whose body contains a position — used to attribute a reference to the function/method that contains it, for call-graph / impact analysis.\n\n```go\ntype FileSymbol struct {\n\tName    string\n\tKind    int // LSP SymbolKind\n\tLine    int // 1-based full-range start\n\tEndLine int // 1-based full-range end\n\tSelLine int // 1-based name-token line\n\tDepth   int // 0 = top level, 1 = member (a class's method), …\n}\n```\nFileSymbol is one declaration from a file's LSP symbol tree, flattened for consumers that want a per-file symbol list (the repo map) rather than the enclosing-position query EnclosingSymbol answers.\n\n```go\ntype Location struct {\n\tURI   string `json:\"uri\"`\n\tRange Range  `json:\"range\"`\n}\n```\nLocation is a range within a document (uri) — the shape definition/references return.\n\n```go\ntype Manager struct {\n\t// contains filtered or unexported fields\n}\n```\nManager owns one resident language server per language for a workspace, started lazily and reused for the session. It is the session-facing surface (Diagnostics/Definition/ References/Hover by file path). Nil-safe: a zero Manager degrades to \"no LSP\".\n\n```go\nfunc NewManager(root string) *Manager\n```\nNewManager returns a Manager rooted at the workspace. Servers are started on first use.\n\n```go\nfunc (m *Manager) Close()\n```\nClose shuts every resident server down (call on session end).\n\n```go\nfunc (m *Manager) Definition(ctx context.Context, path string, line, col int) ([]Location, bool, error)\n```\nDefinition/References/Hover resolve the symbol at a 1-based line/col (the human/editor convention) — converted to LSP's 0-based position here.\n\n```go\nfunc (m *Manager) DiagnoseAfterEdit(ctx context.Context, path string) (diags []Diagnostic, ok bool, err error)\n```\nDiagnoseAfterEdit re-syncs a file that was just edited on disk (didChange with the new content, or didOpen if the server hasn't seen it yet), then waits for the server's fresh diagnostics. This is the \"sees the error immediately, fixes it the same turn\" loop. ok=false when no resident server serves the file.\n\n```go\nfunc (m *Manager) Diagnostics(ctx context.Context, path string) (diags []Diagnostic, ok bool, err error)\n```\nDiagnostics returns the resident server's diagnostics for a file (opening it first and waiting briefly for the async push). ok=false means no server is available for it.\n\n```go\nfunc (m *Manager) EnclosingSymbol(ctx context.Context, path string, line, col int) (EnclosingSymbol, bool, error)\n```\nEnclosingSymbol resolves the most-specific symbol containing a 1-based line/col. ok=false when no resident server serves the file or nothing encloses the position.\n\n```go\nfunc (m *Manager) FileSymbols(ctx context.Context, path string) ([]FileSymbol, bool, error)\n```\nFileSymbols returns the file's declarations via textDocument/documentSymbol, flattened two levels deep (top-level + members — grandchildren are locals and fields, noise for a repo overview). ok=false when no resident server serves the file's language.\n\n```go\nfunc (m *Manager) FormatLocations(locs []Location) string\n```\nFormatLocations renders locations as repo-relative file:line references for the model.\n\n```go\nfunc (m *Manager) Hover(ctx context.Context, path string, line, col int) (string, bool, error)\n```\nHover returns the type/signature/doc at a 1-based line/col.\n\n```go\nfunc (m *Manager) InstallHint(path string) string\n```\nInstallHint returns the binary a user must install to enable LSP for path's language.\n\n```go\nfunc (m *Manager) References(ctx context.Context, path string, line, col int) ([]Location, bool, error)\n```\n\n```go\nfunc (m *Manager) Supported(path string) (lang string, ok bool)\n```\nSupported reports whether a resident server COULD serve this path (its language is known and its binary is on PATH). Used to decide whether to prefer LSP over a one-shot checker, and to give an actionable \"install X\" message otherwise.\n\n```go\ntype Position struct {\n\tLine      int `json:\"line\"`\n\tCharacter int `json:\"character\"`\n}\n```\nPosition is a zero-based line/character in a document (the LSP convention).\n\n```go\ntype Range struct {\n\tStart Position `json:\"start\"`\n\tEnd   Position `json:\"end\"`\n}\n```\nRange is a span in a document.\n\n","path":"github.com/memcode-ai/memcode/internal/lsp","name":"lsp","synopsis":"Package lsp is memcode's resident Language Server Protocol client — the \"give the agent eyes\" layer.","isRedistributable":true}
