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

lsp

package
v0.1.6 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// DefaultIdle is how long a server may sit unused before it is stopped.
	DefaultIdle = 10 * time.Minute
)

Variables

View Source
var ErrMissing = errors.New("language server is not installed")

ErrMissing reports a server that is not installed.

View Source
var ErrNotReady = errors.New("language server is starting")

ErrNotReady reports a server still starting when a request gave up.

View Source
var ErrUnsupported = errors.New("language server does not support this request")

ErrUnsupported reports a request the server does not answer.

Functions

This section is empty.

Types

type Capabilities

type Capabilities struct {
	Definition bool `json:"definition"`
	References bool `json:"references"`
}

Capabilities are the navigation methods negotiated with a running server.

type File

type File struct {
	Path     string
	Size     int64
	Modified time.Time
}

File is a project file and its change stamp, for change notifications.

type Install

type Install struct {
	Label         string   `json:"label"`
	Command       string   `json:"command"`
	Prerequisites []string `json:"prerequisites,omitempty"`
	Docs          string   `json:"docs,omitempty"`
}

Install is host-specific guidance, never an automatically executed command. Command is empty for downloads that require following the linked documentation.

type Location

type Location struct {
	Path string
	Position
	End Position
}

Location is a position in a file, by absolute path.

type Manager

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

Manager runs language servers on demand: one per server and project root, started by the first request and stopped after Idle.

func NewManager

func NewManager(servers []Server, options Options) *Manager

NewManager creates a Manager for servers.

func (*Manager) Available

func (m *Manager) Available(root, family string) bool

Available reports whether a family's server is installed and not in its failure backoff, so requests may wait for it.

func (*Manager) Close

func (m *Manager) Close()

Close stops every server.

func (*Manager) Definition

func (m *Manager) Definition(ctx context.Context, request Request) ([]Location, error)

Definition asks the family's server where the symbol at a position is defined. It waits for a starting server until ctx ends, then returns ErrNotReady.

func (*Manager) Idle

func (m *Manager) Idle() time.Duration

Idle is how long servers run unused before stopping.

func (*Manager) References

func (m *Manager) References(ctx context.Context, request Request) ([]Location, error)

References asks the family's server for every use of the symbol at a position, including its declaration.

func (*Manager) Refresh

func (m *Manager) Refresh()

Refresh forgets discovered binaries and failures, so newly installed servers are found and failed ones retried.

func (*Manager) ServerFor

func (m *Manager) ServerFor(family string) (Server, bool)

ServerFor finds the server for a document family.

func (*Manager) Servers

func (m *Manager) Servers() []Server

Servers lists the registered servers.

func (*Manager) Start

func (m *Manager) Start(ctx context.Context, root, family string) error

Start starts a family's server for a root if needed and waits until it is ready or ctx ends, returning ErrNotReady then.

func (*Manager) Status

func (m *Manager) Status(root, family string) (Status, bool)

Status reports a family's server for a project root without starting it.

type Options

type Options struct {
	// Idle stops servers unused this long; zero means DefaultIdle.
	Idle time.Duration
	// LookPath finds a server binary; nil searches PATH and install dirs.
	LookPath func(name string) (string, bool)
}

Options configure a Manager.

type Position

type Position struct {
	Line   int
	Column int
}

Position is a 1-based line and a 0-based UTF-16 column, as servef counts.

type Request

type Request struct {
	// Root is the project root; one server runs per root.
	Root   string
	Family string
	// Document is the queried file and Text its contents.
	Document File
	Text     []byte
	At       Position
	// Files are the project's files of the server's families, so the server
	// learns about changes on disk.
	Files []File
}

Request is one navigation query against a language server.

type ResolvedServer

type ResolvedServer struct {
	Path string
	Name string
	Args []string
}

ResolvedServer identifies the selected executable without starting it.

type Server

type Server struct {
	// WorkspaceFiles are base-name globs for configuration change notifications.
	WorkspaceFiles []string
	Aliases        []string
	Name           string
	Args           []string
	Language       string
	Families       map[string]string
	Install        []Install
	Docs           string
	// NativeTypeScript selects TypeScript 7's native LSP before the classic adapter.
	NativeTypeScript bool
	// NodePackage identifies npm launchers on hosts that cannot execute shebangs.
	NodePackage string
}

Server describes a deliberately supported language-server process.

func Builtins

func Builtins() []Server

Builtins lists the supported language servers with guidance for this host.

func (Server) Resolve

func (s Server) Resolve(root string, lookup func(string) (string, bool)) (ResolvedServer, bool)

Resolve checks project-local tools before host tools. Discovery reads files and PATH only; status requests never run a shell, installer, or language server.

type State

type State string

State is a server's lifecycle state for a project.

const (
	// StateMissing means the server binary was not found.
	StateMissing State = "missing"
	// StateStopped means the server is installed but not running.
	StateStopped  State = "stopped"
	StateStarting State = "starting"
	StateReady    State = "ready"
	// StateFailed means the last start failed or the server exited.
	StateFailed State = "failed"
)

type Status

type Status struct {
	Server Server
	State  State
	// Message explains a failure.
	Message string
	// Memory is the running server's resident memory in bytes, when known.
	Memory       uint64
	Capabilities *Capabilities
}

Status describes a family's language server for a project.

Directories

Path Synopsis
Package lsptest is a fake language server for tests.
Package lsptest is a fake language server for tests.

Jump to

Keyboard shortcuts

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