Documentation
¶
Overview ¶
Package lsp integrates Language Server Protocol (LSP) support into BroCode.
A language server (gopls for Go, typescript-language-server for TS, etc.) is spawned over stdio and queried for definition, references, hover and diagnostics — real code intelligence instead of grep-only exploration. The server is launched lazily on first use and kept alive for the session; if no server is available for the requested language the tools fail with a clear message telling the model to fall back to grep/glob/read_file.
Index ¶
- Constants
- func RegisterTools(r *tool.Registry, m *Manager)
- type AutoFixTool
- type Client
- type DefinitionTool
- type DiagnosticsTool
- type FixTool
- type HoverTool
- type Manager
- func (m *Manager) ActiveServers() []string
- func (m *Manager) AutoFixAll(ctx context.Context, root string) (string, error)
- func (m *Manager) AvailableServers() []string
- func (m *Manager) Close()
- func (m *Manager) CodeAction(ctx context.Context, path string) (string, error)
- func (m *Manager) Definition(ctx context.Context, path string, line, col int) (string, error)
- func (m *Manager) DeterministicFixAll(ctx context.Context, root string) (string, error)
- func (m *Manager) Diagnostics(ctx context.Context, path string) (string, error)
- func (m *Manager) FixAllFile(ctx context.Context, path string) (int, string, error)
- func (m *Manager) Hover(ctx context.Context, path string, line, col int) (string, error)
- func (m *Manager) InstallHints() map[string]string
- func (m *Manager) Outline(ctx context.Context, path string) (string, error)
- func (m *Manager) References(ctx context.Context, path string, line, col int) (string, error)
- func (m *Manager) Rename(ctx context.Context, path string, line, col int, newName string) (string, error)
- func (m *Manager) ScanDiagnostics(ctx context.Context, root string) (string, error)
- func (m *Manager) Symbols(ctx context.Context, path, query string) (string, error)
- func (m *Manager) WarmUp(root string)
- type OutlineTool
- type ReferencesTool
- type RenameTool
- type ScanTool
- type ServerSpec
- type SymbolsTool
Constants ¶
const DefaultIdleTimeout = 10 * time.Minute
DefaultIdleTimeout is how long a language server stays alive after its last use before it is shut down to free memory. 10 minutes covers a normal task burst while keeping idle processes bounded.
Variables ¶
This section is empty.
Functions ¶
func RegisterTools ¶
RegisterTools registers the LSP intelligence tools into the registry. The tools share one Manager (one language server process per language) and fail with a clear message when no server is available so the model falls back to grep/glob/read_file.
Types ¶
type AutoFixTool ¶
type AutoFixTool struct {
// contains filtered or unexported fields
}
AutoFixTool — apply all auto-fixable quick-fixes across the project in one shot.
func (*AutoFixTool) Description ¶
func (t *AutoFixTool) Description() string
func (*AutoFixTool) Name ¶
func (t *AutoFixTool) Name() string
func (*AutoFixTool) Parameters ¶
func (t *AutoFixTool) Parameters() map[string]any
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a live connection to one language server.
type DefinitionTool ¶
type DefinitionTool struct {
// contains filtered or unexported fields
}
DefinitionTool — jump to where a symbol is defined.
func (*DefinitionTool) Description ¶
func (t *DefinitionTool) Description() string
func (*DefinitionTool) Name ¶
func (t *DefinitionTool) Name() string
func (*DefinitionTool) Parameters ¶
func (t *DefinitionTool) Parameters() map[string]any
type DiagnosticsTool ¶
type DiagnosticsTool struct {
// contains filtered or unexported fields
}
DiagnosticsTool — compiler/linter errors for a file.
func (*DiagnosticsTool) Description ¶
func (t *DiagnosticsTool) Description() string
func (*DiagnosticsTool) Name ¶
func (t *DiagnosticsTool) Name() string
func (*DiagnosticsTool) Parameters ¶
func (t *DiagnosticsTool) Parameters() map[string]any
type FixTool ¶
type FixTool struct {
// contains filtered or unexported fields
}
FixTool — apply the language server's auto-fixable code actions to a file.
func (*FixTool) Description ¶
func (*FixTool) Parameters ¶
type HoverTool ¶
type HoverTool struct {
// contains filtered or unexported fields
}
HoverTool — documentation and type info for a symbol.
func (*HoverTool) Description ¶
func (*HoverTool) Parameters ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager owns zero or more language server connections (one per language). Servers are spawned lazily on first use and reaped when idle, so a long session does not accumulate live language-server processes (the "unbounded memory growth" problem other agents have).
func NewManager ¶
func NewManager() *Manager
NewManager creates an empty LSP manager with an idle reaper.
func (*Manager) ActiveServers ¶
ActiveServers returns the languages whose server process is currently running (spawned by a previous lsp_* tool call this session).
func (*Manager) AutoFixAll ¶
AutoFixAll applies all auto-fixable quick-fixes across every file that has diagnostics, in a single call (one language-server session, one settle). This is the "batch clear" counterpart to lsp_fix: instead of calling lsp_fix per file, the engine fixes the whole project in one shot. Returns a per-file summary of what was applied.
func (*Manager) AvailableServers ¶
AvailableServers returns the language names whose server binary is on PATH — these are the languages LSP tools can actually use right now.
func (*Manager) Close ¶
func (m *Manager) Close()
Close shuts down all running language servers and stops the idle reaper.
func (*Manager) CodeAction ¶
CodeAction applies the first auto-applicable code action the server offers for the file's current diagnostics — e.g. auto-import, organize imports, or a quick-fix rewrite — preferring the server's "preferred" action. The resulting edits are written to disk and recorded for the turn's diff, undo snapshots and verification. Returns a summary of what was applied, or the available action titles when none carried an auto-applyable edit.
func (*Manager) Definition ¶
Definition returns the source location(s) of the symbol under the cursor.
func (*Manager) DeterministicFixAll ¶
DeterministicFixAll applies gopls source.fixAll across every supported file in the project in one call — the deterministic bulk clearing pass for mechanical warnings. It returns a per-file summary; the LLM only handles whatever remains (genuinely semantic issues) afterward.
func (*Manager) Diagnostics ¶
Diagnostics returns the current diagnostics (errors/warnings) for a file.
func (*Manager) FixAllFile ¶
FixAllFile clears every mechanically-fixable diagnostic in ONE file by asking gopls for quick-fixes and applying them one at a time, re-syncing the server and re-reading diagnostics after each. Crucially, every applied fix is build-gated: if applying it makes `go build` of the package fail, the edit is reverted and that diagnostic is skipped. This keeps the project always compiling while absorbing the bulk of the warnings (imports, Fprintf/Sprintf rewrites, CutPrefix, max/min, range loops, slices.Backward, etc.) — no LLM in the loop. Determinism + the build gate mean it can never leave broken code; anything that would break the build is left for a human/LLM. Returns the number of fixes applied and a summary.
func (*Manager) InstallHints ¶
InstallHints returns, for each supported language whose server binary is missing, the official command to install it (empty map = all installed). The platform-dependent clangd hint is resolved here so callers (UI, tools) never need runtime.GOOS themselves.
func (*Manager) Outline ¶
Outline returns the hierarchical symbol tree of a file (functions, types, methods, fields) via documentSymbol — a semantic map of a file's shape.
func (*Manager) References ¶
References returns all references to the symbol under the cursor.
func (*Manager) Rename ¶
func (m *Manager) Rename(ctx context.Context, path string, line, col int, newName string) (string, error)
Rename renames the symbol under the cursor across the whole project using the server's semantic rename, applying the resulting edits to disk. The verification ladder catches anything the rename missed. Returns a per-file summary of what changed.
func (*Manager) ScanDiagnostics ¶
ScanDiagnostics proactively scans a project for compiler/linter diagnostics: errors, warnings and deprecated usages across source files — a full health check without running a build. It opens at most scanMaxFiles supported files (dependency/build dirs skipped), gives the servers one short settle window, then aggregates everything they publish. Files whose language server is not installed are skipped silently. Returns a compact report, or a clean line when no issues were found.
func (*Manager) Symbols ¶
Symbols searches the whole workspace for symbols matching a name using workspace/symbol — semantic lookup that does not need a cursor position (unlike definition/references). path anchors the language server to use.
func (*Manager) WarmUp ¶
WarmUp spawns language servers for supported files under root in the background, so the first lsp_* call of the session is instant instead of paying spawn + initialize + (cache-warm) index on first use — the persistent per-session gap. Servers the user never touches are shut down by the idle reaper after idleTimeout, so unused warm-up costs nothing in the long run. Never blocks; errors are ignored (lazy spawn still happens on first call).
type OutlineTool ¶
type OutlineTool struct {
// contains filtered or unexported fields
}
OutlineTool — hierarchical symbol tree of a file.
func (*OutlineTool) Description ¶
func (t *OutlineTool) Description() string
func (*OutlineTool) Name ¶
func (t *OutlineTool) Name() string
func (*OutlineTool) Parameters ¶
func (t *OutlineTool) Parameters() map[string]any
type ReferencesTool ¶
type ReferencesTool struct {
// contains filtered or unexported fields
}
ReferencesTool — find every place a symbol is used.
func (*ReferencesTool) Description ¶
func (t *ReferencesTool) Description() string
func (*ReferencesTool) Name ¶
func (t *ReferencesTool) Name() string
func (*ReferencesTool) Parameters ¶
func (t *ReferencesTool) Parameters() map[string]any
type RenameTool ¶
type RenameTool struct {
// contains filtered or unexported fields
}
RenameTool — semantic rename across the project.
func (*RenameTool) Description ¶
func (t *RenameTool) Description() string
func (*RenameTool) Name ¶
func (t *RenameTool) Name() string
func (*RenameTool) Parameters ¶
func (t *RenameTool) Parameters() map[string]any
type ScanTool ¶
type ScanTool struct {
// contains filtered or unexported fields
}
ScanTool — project-wide health check: errors, warnings, deprecated APIs.
func (*ScanTool) Description ¶
func (*ScanTool) Parameters ¶
type ServerSpec ¶
type ServerSpec struct {
Language string // display name, e.g. "go"
Command string // binary, e.g. "gopls"
Args []string
}
ServerSpec describes how to spawn a language server for a language.
type SymbolsTool ¶
type SymbolsTool struct {
// contains filtered or unexported fields
}
SymbolsTool — find symbols by name, no cursor needed.
func (*SymbolsTool) Description ¶
func (t *SymbolsTool) Description() string
func (*SymbolsTool) Name ¶
func (t *SymbolsTool) Name() string
func (*SymbolsTool) Parameters ¶
func (t *SymbolsTool) Parameters() map[string]any