lsp

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 6, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package lsp is a minimal Language Server Protocol client: it spawns a language server per language on demand, syncs queried documents from disk, and adapts a few read-only capabilities (definition, references, hover, diagnostics) to the tool.Tool interface. Servers are not bundled — they resolve on PATH and a clear install hint is returned when one is missing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultSpecs

func DefaultSpecs() map[string]ServerSpec

DefaultSpecs maps a language key to its conventional server. Commands are tried on PATH; nothing here ships with fairpeer. Extensions drive file routing, so a user can override any entry or add a new language entirely from config.

func Tools

func Tools(m *Manager) []tool.Tool

Tools adapts the manager's read-only queries to the tool.Tool interface. They report ReadOnly=true, so a batch of them rides the agent's parallel dispatch and shares one server per language.

Types

type Diagnostic

type Diagnostic struct {
	Range    Range  `json:"range"`
	Severity int    `json:"severity"`
	Message  string `json:"message"`
	Source   string `json:"source"`
}

Diagnostic is one published problem for a document.

type Location

type Location struct {
	URI   string `json:"uri"`
	Range Range  `json:"range"`
}

Location is a file URI plus a range, the shape definition/references return.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager owns the lazily-spawned language servers for a session. Servers start on first query for their language and are reused; the session-scoped context (cancelled by Close) bounds their lifetime, not a single turn.

func NewManager

func NewManager(wsRoot string, specs map[string]ServerSpec) *Manager

func (*Manager) Close

func (m *Manager) Close()

func (*Manager) Definition

func (m *Manager) Definition(ctx context.Context, file string, line int, symbol string) (string, error)

func (*Manager) Diagnostics

func (m *Manager) Diagnostics(ctx context.Context, file string) (string, error)

func (*Manager) Hover

func (m *Manager) Hover(ctx context.Context, file string, line int, symbol string) (string, error)

func (*Manager) Implementation

func (m *Manager) Implementation(ctx context.Context, file string, line int, symbol string) (string, error)

Implementation finds the concrete implementations of an interface method (or interface type). Uses the same file+line+symbol pattern as Definition.

func (*Manager) References

func (m *Manager) References(ctx context.Context, file string, line int, symbol string) (string, error)

func (*Manager) WorkspaceSymbol

func (m *Manager) WorkspaceSymbol(ctx context.Context, query string) (string, error)

WorkspaceSymbol searches for symbols across the whole workspace by name (partial match). Unlike definition/references it doesn't need a file+line — just a query string. Returns matching symbols with their location and kind.

type Position

type Position struct {
	Line      int `json:"line"`
	Character int `json:"character"`
}

Position is a zero-based LSP position. Character is counted in the encoding the server negotiated at initialize (utf-16 by default, utf-8 when both sides agree).

type Range

type Range struct {
	Start Position `json:"start"`
	End   Position `json:"end"`
}

Range is a half-open span between two positions.

type ServerSpec

type ServerSpec struct {
	Command     string
	Args        []string
	Env         map[string]string
	LanguageID  string
	Extensions  []string
	InstallHint string
}

ServerSpec declares how to launch one language server. Command resolves on PATH (the binary is never bundled); InstallHint is surfaced when it is missing. Extensions are the file suffixes (".go", ".rs") this server handles — they drive file → language routing, so a config-only entry can add a new language without any code change.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL