lsp

package
v0.11.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: Apache-2.0, MIT Imports: 18 Imported by: 0

Documentation

Overview

Package lsp implements a minimal Language Server Protocol client over stdio. LSP uses JSON-RPC 2.0 with Content-Length framed messages.

Index

Constants

View Source
const InitializeTimeout = 5 * time.Second

InitializeTimeout bounds readiness independently of the session lifetime.

Variables

This section is empty.

Functions

func DefaultConfig

func DefaultConfig() config.LSPConfig

DefaultConfig returns a config that probes PATH for common language servers. Only servers whose binary exists are returned.

func URIToPath

func URIToPath(uri string) string

URIToPath converts a file:// URI back to a local filesystem path.

Types

type Client

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

Client is one language-server stdio connection.

func NewClient

func NewClient(language, command string, args []string, maxMessageBytes int) *Client

NewClient constructs (but does not start) a client.

func (*Client) Close

func (c *Client) Close() error

Close attempts the LSP shutdown/exit protocol within a fixed grace period, then cancels the owned process group and waits for process/reader reaping.

func (*Client) Connected

func (c *Client) Connected() bool

Connected returns true once the LSP initialize handshake has completed.

func (*Client) Definition

func (c *Client) Definition(ctx context.Context, file string, line, col int) ([]Location, error)

Definition returns the definition site(s) for the symbol at file:line:col.

func (*Client) DocumentSymbols

func (c *Client) DocumentSymbols(ctx context.Context, file string) ([]SymbolInformation, error)

DocumentSymbols returns the outline for a single file.

func (*Client) Hover

func (c *Client) Hover(ctx context.Context, file string, line, col int) (Hover, error)

Hover returns the hover doc for the symbol at file:line:col as plain text.

func (*Client) Language

func (c *Client) Language() string

Language returns the language name this client serves.

func (*Client) LastError

func (c *Client) LastError() error

LastError returns the last connection error.

func (*Client) References

func (c *Client) References(ctx context.Context, file string, line, col int) ([]Location, error)

References returns usage sites of the symbol at file:line:col.

func (*Client) Start

func (c *Client) Start(ctx context.Context, rootDir string) error

Start owns the server until ctx is canceled or Close is called. Concurrent starts share one initialize attempt; Close is terminal and waits for reaping.

func (*Client) WorkspaceSymbols

func (c *Client) WorkspaceSymbols(ctx context.Context, query string) ([]SymbolInformation, error)

WorkspaceSymbols searches across the workspace for matching symbols.

type Hover

type Hover struct {
	Contents string `json:"-"`
	Range    *Range `json:"range,omitempty"`
}

Hover is a hover response. Markdown content is in `Contents` as a string.

type Location

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

Location pins a Range inside a URI-addressed file.

type Manager

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

Manager holds one Client per language and routes calls by file extension.

func NewManager

func NewManager(cfg config.LSPConfig, rootDir string) *Manager

NewManager builds a manager. Use defaultLSPConfig() for sensible defaults.

func (*Manager) ClientForFile

func (m *Manager) ClientForFile(path string) *Client

ClientForFile picks the right language client for a given path. Returns nil if no server handles that extension.

func (*Manager) ConnectedCount

func (m *Manager) ConnectedCount() int

ConnectedCount returns how many language servers are live.

func (*Manager) Languages

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

Languages returns the names of every connected language server.

func (*Manager) Start

func (m *Manager) Start(ctx context.Context) error

Start launches configured servers once and waits for bounded initialization. ctx owns their session lifetime, not just readiness. Any failed server is reported; callers assembling an all-or-nothing session should call Stop.

func (*Manager) Stop

func (m *Manager) Stop()

Stop is terminal. It cancels pending startup and joins all owned subprocesses and readers without holding the routing lock. Repeated/concurrent calls wait for the same Client.Close operations rather than racing process handles.

type Position

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

Position is an LSP zero-based line/character position.

type Range

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

Range is an LSP range.

type SymbolInformation

type SymbolInformation struct {
	Name     string   `json:"name"`
	Kind     int      `json:"kind"`
	Location Location `json:"location"`
}

SymbolInformation is the legacy LSP workspace/document symbol shape — the subset we actually consume.

Jump to

Keyboard shortcuts

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