Help us shape the future of Go! Take the 2026 Go Developer Survey

lsp

package
v0.10.3 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package lsp is a small Language Server Protocol client: it starts the configured servers lazily over stdio, keeps the files it has shown them in sync with disk, and collects diagnostics, definitions and references.

Index

Constants

View Source
const (
	StateStarted     = "started"
	StateUnavailable = "unavailable"
	StateCrashed     = "crashed"
	StateStopped     = "stopped"
)

Server states reported in events.

View Source
const (
	SeverityError   = 1
	SeverityWarning = 2
)

Severities of a Diagnostic.

Variables

View Source
var ErrNoServer = errors.New("no lsp server configured")

ErrNoServer is returned for a file no configured server handles.

Functions

func PathToURI

func PathToURI(path string) string

PathToURI returns the file URI for an absolute path.

func RuneToUTF16

func RuneToUTF16(line string, col int) int

RuneToUTF16 converts a zero-based rune column in line to UTF-16 units. A column past the end is clamped to the line length.

func URIToPath

func URIToPath(uri string) (string, error)

URIToPath returns the absolute path of a file URI.

func UTF16ToRune

func UTF16ToRune(line string, units int) int

UTF16ToRune converts a zero-based UTF-16 column in line to runes.

Types

type Diagnostic

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

Diagnostic is one published diagnostic.

func (Diagnostic) IsError

func (d Diagnostic) IsError() bool

IsError reports whether d is an error; a missing severity counts as one.

type Event

type Event struct {
	Server string
	State  string
	Reason string
}

Event is a server lifecycle change (the lsp.server run event).

type FileDiagnostics

type FileDiagnostics struct {
	Path   string
	Server string
	Items  []Diagnostic
	// Ready is false when the server published nothing in time.
	Ready bool
	Err   error
}

FileDiagnostics is the outcome for one file.

type Location

type Location struct {
	Path  string
	Range Range
}

Location is a resolved definition or reference: an absolute path and a zero-based UTF-16 range.

type Manager

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

Manager owns the configured servers for one run. It is safe for concurrent use.

func New

func New(o Options) *Manager

New returns a Manager; no server starts until a file it handles is used.

func (*Manager) Close

func (m *Manager) Close()

Close shuts every running server down (shutdown and exit, then a kill of its process group after a short grace) and records a stopped event for each. Later calls do nothing.

func (*Manager) Definition

func (m *Manager) Definition(ctx context.Context, path string, pos Position) ([]Location, error)

Definition returns where the symbol at pos in path is defined.

func (*Manager) Diagnostics

func (m *Manager) Diagnostics(ctx context.Context, paths []string, wait time.Duration) []FileDiagnostics

Diagnostics syncs each path and waits up to wait (for all of them together) for the server's diagnostics. Paths no server handles are skipped. A file whose content the server already has returns the last published diagnostics at once.

func (*Manager) Names

func (m *Manager) Names() []string

Names returns the configured server names in config order.

func (*Manager) References

func (m *Manager) References(ctx context.Context, path string, pos Position) ([]Location, error)

References returns the references to the symbol at pos in path, including its declaration.

func (*Manager) ServerFor

func (m *Manager) ServerFor(path string) (string, bool)

ServerFor returns the name of the server handling path, if any.

func (*Manager) TakeEvents

func (m *Manager) TakeEvents() []Event

TakeEvents returns and clears the lifecycle events recorded so far.

type Options

type Options struct {
	// Root is the workspace root: the server's working directory and
	// root URI.
	Root    string
	Servers []config.LSPServer
	// LogDir receives one stderr log per server and run ("" discards
	// server stderr). LogPrefix starts each log's file name.
	LogDir    string
	LogPrefix string
}

Options configures a Manager.

type Position

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

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

type Range

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

Range is an LSP range.

type UnavailableError

type UnavailableError struct {
	Server string
	Reason string
}

UnavailableError reports a server that can't be used for the rest of the run.

func (*UnavailableError) Error

func (e *UnavailableError) Error() string

Directories

Path Synopsis
Package lsptest is a fake language server for tests: the test binary re-executes itself, so tests need no real language server.
Package lsptest is a fake language server for tests: the test binary re-executes itself, so tests need no real language server.

Jump to

Keyboard shortcuts

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