lsp

package
v0.8.11 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: Apache-2.0 Imports: 17 Imported by: 1 module, 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 talks to language servers for the agent's code intelligence (spec_parity_027 PAR-TOOL-03): definitions, references, hover, symbols and diagnostics, from servers started lazily per language.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnknownDocument means no open document has the ID (closed, or its
	// lease ran out).
	ErrUnknownDocument = errors.New("no such document: open it again")
	// ErrStale means a request was about another version of the document
	// than the one the server has.
	ErrStale = errors.New("the document has changed since")
)

Errors of the editor's requests.

View Source
var ErrNoServer = errors.New("no language server for this kind of file")

ErrNoServer means no language server is configured for the file.

Functions

func InstallHint added in v0.5.0

func InstallHint(language string) string

InstallHint is what to run to install language's default server ("" when there's none to suggest).

func SnippetPath added in v0.5.0

func SnippetPath(root, key, ext string) string

SnippetPath is where a code block's file is said to be: a folder of its own (so it's a package of its own) under the workspace's root, so it sees the workspace's module; never written to disk. Not under a folder whose name starts with "." or "_": gopls gives files there no diagnostics.

Types

type Completion added in v0.5.0

type Completion struct {
	Label, Kind, Detail, Documentation string
	InsertText                         string
	Edit                               *TextEdit
	Snippet                            bool
	AdditionalEdits                    []TextEdit
	SortText, FilterText               string
}

Completion is one completion item.

type CompletionList added in v0.5.0

type CompletionList struct {
	Items      []Completion
	Incomplete bool
}

CompletionList is what Complete returns.

type Diagnostic

type Diagnostic struct {
	Line     int    `json:"line"`
	Column   int    `json:"column"`
	Severity string `json:"severity"`
	Message  string `json:"message"`
	Source   string `json:"source,omitempty"`
}

Diagnostic is a problem a server reports.

type Document added in v0.5.0

type Document struct {
	ID       string
	Client   string
	Path     string // absolute
	Language string
	Version  int64
	// contains filtered or unexported fields
}

Document is an editor document.

type DocumentDiagnostic added in v0.5.0

type DocumentDiagnostic struct {
	Start, End                      Position
	Severity, Message, Source, Code string
}

DocumentDiagnostic is one problem in an editor document.

type DocumentDiagnostics added in v0.5.0

type DocumentDiagnostics struct {
	Document    string
	Version     int64
	Diagnostics []DocumentDiagnostic
}

DocumentDiagnostics are a document's diagnostics for a version.

type DocumentInfo added in v0.5.0

type DocumentInfo struct {
	ID       string // "" when its language has no server
	Language string
	State    State
	Detail   string // why it's missing or failed
	Install  string // what to install, when missing
}

DocumentInfo is what opening a document says.

type Launcher

type Launcher func(ctx context.Context, argv []string) (Process, error)

Launcher starts a server's command in the workspace (the engine's runs it guarded, in the OS sandbox).

type Location

type Location struct {
	Path   string `json:"path"`
	Line   int    `json:"line"`
	Column int    `json:"column"`
	Text   string `json:"text,omitempty"`
}

Location is a place in a file, for people: the path (relative to the workspace when inside it), 1-based line and column, and the line.

type Manager

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

Manager starts language servers as files need them, one per language, and keeps the files it asks about in sync with the disk.

func NewManager

func NewManager(root string, servers []Server, launch Launcher) *Manager

NewManager is a manager for the workspace root.

func (*Manager) ChangeDocument added in v0.5.0

func (m *Manager) ChangeDocument(ctx context.Context, id string, version int64, text string) error

ChangeDocument replaces a document's text with version's.

func (*Manager) Close

func (m *Manager) Close()

Close shuts the servers down, and ends the starts under way, waiting for them.

func (*Manager) CloseDocument added in v0.5.0

func (m *Manager) CloseDocument(id string) error

CloseDocument closes a document.

func (*Manager) Complete added in v0.5.0

func (m *Manager) Complete(ctx context.Context, id string, version int64, line, col int, trigger string) (CompletionList, error)

Complete asks for completions at (line, col) of a document at version; trigger is the character typed that asked ("" when invoked).

func (*Manager) Definition

func (m *Manager) Definition(ctx context.Context, path string, line, col int) ([]Location, error)

Definition is where the symbol at (line, col) of path is defined.

func (*Manager) Diagnostics

func (m *Manager) Diagnostics(ctx context.Context, path string, wait time.Duration) ([]Diagnostic, error)

Diagnostics are the problems the server reports for path as it is on disk, waiting up to wait for them.

func (*Manager) DocumentDefinition added in v0.5.0

func (m *Manager) DocumentDefinition(ctx context.Context, id string, version int64, line, col int) ([]Location, error)

DocumentDefinition is where the symbol at (line, col) is defined.

func (*Manager) DocumentHover added in v0.5.0

func (m *Manager) DocumentHover(ctx context.Context, id string, version int64, line, col int) (string, error)

DocumentHover is what the server says about the symbol at (line, col).

func (*Manager) DocumentReferences added in v0.5.0

func (m *Manager) DocumentReferences(ctx context.Context, id string, version int64, line, col int) ([]Location, error)

DocumentReferences are where the symbol at (line, col) is used.

func (*Manager) For

func (m *Manager) For(ctx context.Context, path string) (*server, error)

For finds the server for path, starting it if need be. A start runs on its own (startTimeout, or until Close), not on ctx: callers wait for it, each giving up with its own ctx, and other languages go on meanwhile.

func (*Manager) Hover

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

Hover is what the server says about the symbol at (line, col).

func (*Manager) KeepDocuments added in v0.5.0

func (m *Manager) KeepDocuments(client string) []string

KeepDocuments marks client seen, returning its documents still open.

func (*Manager) OpenDocument added in v0.5.0

func (m *Manager) OpenDocument(client, path, text string, version int64) DocumentInfo

OpenDocument opens path (absolute) for client's editor with its text, starting the server in the background when it isn't running.

func (*Manager) OpenSnippet added in v0.5.0

func (m *Manager) OpenSnippet(client, path, text string, version int64) DocumentInfo

OpenSnippet opens a code block as the file path (SnippetPath), which isn't on disk: a Go fragment is made a whole file for the server, and positions are the block's own.

func (*Manager) References

func (m *Manager) References(ctx context.Context, path string, line, col int) ([]Location, error)

References are where the symbol at (line, col) of path is used.

func (*Manager) Restart added in v0.5.0

func (m *Manager) Restart(language string) error

Restart stops language's server; the next request starts it again, and the editor's documents are opened in it again.

func (*Manager) Running

func (m *Manager) Running(path string) bool

Running reports whether a server runs for files like path (edits then report diagnostics without starting one).

func (*Manager) SnippetPath added in v0.5.2

func (m *Manager) SnippetPath(key, ext string) string

SnippetPath is where the code block key's file is said to be: under the workspace's root (the function SnippetPath); but a Go block in a workspace no go.mod or go.work covers is in a folder of the manager's own outside it, made for it, since gopls lists a file outside a module from its folder, which must exist (and nothing is written to the workspace).

func (*Manager) Status added in v0.5.0

func (m *Manager) Status() []ServerStatus

Status lists the configured servers and how each is.

func (*Manager) Symbols

func (m *Manager) Symbols(ctx context.Context, path, query string) ([]Symbol, error)

Symbols are the workspace's symbols matching query, from the server for files like path.

func (*Manager) WatchDiagnostics added in v0.5.0

func (m *Manager) WatchDiagnostics(ctx context.Context, client string, send func(DocumentDiagnostics) error) error

WatchDiagnostics sends client's documents' diagnostics to send, each document's latest first and then as they change, until ctx ends or send fails. Diagnostics about an older text than the server has are skipped: newer ones follow.

type NotInstalledError added in v0.5.0

type NotInstalledError struct{ Command string }

NotInstalledError is a server whose command isn't installed.

func (*NotInstalledError) Error added in v0.5.0

func (e *NotInstalledError) Error() string

Error says which command is missing.

type Position added in v0.5.0

type Position struct{ Line, Column int }

Position is a 1-based line and column, in characters.

type Process

type Process interface {
	Stdin() io.WriteCloser
	Stdout() io.ReadCloser
	Stop()
}

Process is a started language server: its stdin and stdout, and how to stop it.

type Server

type Server struct {
	Language   string
	Command    []string
	Extensions []string // with the dot: .go
}

Server is how to run a language's server, and which files it's for.

type ServerStatus added in v0.5.0

type ServerStatus struct {
	Language   string
	Command    []string
	Extensions []string
	State      State
	Since      time.Time
	Err        string
	Install    string
}

ServerStatus is a language's server, for the status list.

type State added in v0.5.0

type State string

State is how a document's server is.

const (
	StateReady    State = "ready"
	StateStarting State = "starting"
	StateMissing  State = "missing"
	StateFailed   State = "failed"
	StateIdle     State = "idle" // not started yet
	StateNone     State = "none" // no server for the language
	// StateUntrusted is the workspace's: its project isn't trusted, so the
	// editor's servers don't start (the engine decides).
	StateUntrusted State = "untrusted"
)

The states of a server.

type Symbol

type Symbol struct {
	Name      string   `json:"name"`
	Kind      string   `json:"kind"`
	Container string   `json:"container,omitempty"`
	Location  Location `json:"location"`
}

Symbol is a workspace symbol.

type TextEdit added in v0.5.0

type TextEdit struct {
	Start, End Position
	Text       string
}

TextEdit is a range of a document replaced by text.

Directories

Path Synopsis
Package lsptest is a fake language server for tests: the test binary runs it when started with BLITZ_FAKE_LSP=1 (call MaybeServe first in TestMain), and Launcher starts that.
Package lsptest is a fake language server for tests: the test binary runs it when started with BLITZ_FAKE_LSP=1 (call MaybeServe first in TestMain), and Launcher starts that.

Jump to

Keyboard shortcuts

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