lsp

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 26 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package lsp runs language servers (gopls, typescript-language-server, pyright or pylsp, rust-analyzer) for the agent: the errors an edit leaves, in the edited files and in the files that use them, and the `lsp` tool's code navigation.

Index

Constants

View Source
const ToolName = "lsp"

ToolName is the code navigation tool.

Variables

This section is empty.

Functions

func Languages

func Languages() []string

Languages lists the built-in languages by name.

func NewTool

func NewTool(m *Manager) tools.Executor

NewTool is the `lsp` tool over m's servers.

Types

type Config

type Config struct {
	Disabled bool                `json:"disabled,omitempty"`
	Servers  map[string][]string `json:"servers,omitempty"`
}

Config is setup.json's `diagnostics.lsp`: Disabled turns every language server off; Servers replaces the command of a language (an argv such as ["pylsp"]), and an empty one turns that language off.

func (Config) Validate

func (c Config) Validate() error

Validate reports languages that are not built in and blank commands.

type Diagnostic

type Diagnostic struct {
	Range    Range           `json:"range"`
	Severity int             `json:"severity,omitempty"`
	Code     json.RawMessage `json:"code,omitempty"`
	Source   string          `json:"source,omitempty"`
	Message  string          `json:"message"`
}

type FileErrors

type FileErrors struct {
	Path   string
	Errors []Diagnostic
}

FileErrors are the errors of one file.

type Location

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

type Manager

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

Manager starts one server per language and project root on first use and stops it when idle and on Close.

func NewManager

func NewManager(logDir string, env func() []string, config func() Config) *Manager

NewManager returns a manager whose servers log stderr into logDir and run with env (nil for the daemon's environment) and the settings of config.

func (*Manager) Available

func (m *Manager) Available(dir string) bool

Available reports whether a server would serve a project in dir, so the `lsp` tool is offered there.

func (*Manager) Close

func (m *Manager) Close()

Close stops every server; the daemon calls it on shutdown.

func (*Manager) Diagnose

func (m *Manager) Diagnose(ctx context.Context, files []string) Report

Diagnose sends the edited files to their servers and waits for their diagnostics. A file whose server is missing, not ready within documentWait or silent about it is left out of Checked, so another check can take it. The errors in other files are all a server knows when it can tell that it diagnosed everything the edit affects (gopls), else those it published while it checked the edited files.

type Position

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

Position is zero-based; Character counts UTF-16 code units.

type Range

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

type Report

type Report struct {
	Checked []string
	Errors  map[string][]Diagnostic
	Others  []FileErrors
}

Report is what the language servers said after an edit: the edited files they checked and the errors in them, and the other files their servers know errors in, most recently published first.

func (Report) Lines

func (r Report) Lines() []string

Lines renders the errors of the edited files, at most maxErrorsPerFile each.

func (Report) OtherLines

func (r Report) OtherLines() []string

OtherLines renders the errors of at most maxOtherFiles other files under a heading; nil when there are none.

Jump to

Keyboard shortcuts

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