lsp

package
v0.0.0-...-19f589e Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: MIT Imports: 31 Imported by: 0

Documentation

Overview

Package lsp provides session-owned language servers and normalized code queries.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter

type Adapter interface {
	Resolve(context.Context, ResolveRequest) (LaunchSpec, error)
}

Adapter resolves setup only. Semantic operations are implemented by the client. Resolve may read files, but must not start processes or modify the workspace. Implementations must support concurrent calls and honor cancellation.

type Config

type Config struct {
	Dir                 string         `json:"-"`
	Servers             []ServerConfig `json:"servers"`
	StartTimeoutMS      int            `json:"start_timeout_ms,omitempty"`
	RequestTimeoutMS    int            `json:"request_timeout_ms,omitempty"`
	DiagnosticTimeoutMS int            `json:"diagnostic_timeout_ms,omitempty"`
	MaxServers          int            `json:"max_servers,omitempty"`
	MaxFileBytes        int            `json:"max_file_bytes,omitempty"`
	MaxMessageBytes     int            `json:"max_message_bytes,omitempty"`
	MaxWorkspaceFiles   int            `json:"max_workspace_files,omitempty"`
	MaxWorkspaceBytes   int            `json:"max_workspace_bytes,omitempty"`
	MaxOpenDocuments    int            `json:"max_open_documents,omitempty"`
	CacheBytes          int            `json:"cache_bytes,omitempty"`
}

Config is host policy. Dir is supplied by the harness, not by model arguments.

func BashConfig

func BashConfig() Config

BashConfig handles shell scripts and common Bash startup files. ShellCheck is optional, but must be installed for its lint diagnostics. No scripts are run.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig enables the built-in server presets. Binaries must be installed separately; constructing the configuration neither discovers nor launches them. JavaScript and TypeScript share one server configuration and process per root.

func GoConfig

func GoConfig() Config

func Load

func Load(path string) (Config, error)

Load rejects unknown host fields, while server-owned JSON remains opaque.

func PythonConfig

func PythonConfig() Config

PythonConfig uses Pyright. Interpreter and import-path settings can be supplied through Settings (python.pythonPath, python.analysis) or pyright project files.

func RustConfig

func RustConfig() Config

RustConfig supports Cargo projects and rust-project.json workspaces. Set explicit Roots to share one instance across members of a Cargo workspace.

func TypeScriptConfig

func TypeScriptConfig() Config

TypeScriptConfig handles both JavaScript and TypeScript, including JSX/TSX and CommonJS/ES module suffixes. Do not configure two overlapping instances for JavaScript and TypeScript files in the same project.

func (Config) Clone

func (c Config) Clone() Config

type Dependencies

type Dependencies struct{ Adapters map[string]Adapter }

type DiagnosticCheck

type DiagnosticCheck struct {
	Path      string `json:"path"`
	Server    string `json:"server"`
	Freshness string `json:"freshness"`
	Count     int    `json:"count"`
}

type DiagnosticQuery

type DiagnosticQuery struct {
	Paths []string
	PageQuery
	// Wait, when positive, replaces the configured diagnostic timeout for this
	// query: how long to wait for the servers' analysis of the paths.
	Wait time.Duration `json:"-"`
	// Resync sends every requested open file to its server as a new version,
	// even when its text is unchanged, so the server publishes diagnostics
	// for it again. After a change elsewhere, a server that republishes only
	// what changed would otherwise leave the file's diagnostics unconfirmed.
	Resync bool `json:"-"`
}

type Error

type Error struct {
	Kind    string
	Message string
}

func (*Error) Error

func (e *Error) Error() string

type InspectQuery

type InspectQuery struct {
	Target        Target
	IncludeSource bool
}

type Inspection

type Inspection struct {
	Location      Item     `json:"location"`
	Documentation string   `json:"documentation"`
	Truncated     bool     `json:"truncated"`
	Metadata      Metadata `json:"metadata"`
}

type Item

type Item struct {
	Ref         string `json:"ref,omitempty"`
	Name        string `json:"name,omitempty"`
	Kind        string `json:"kind,omitempty"`
	Container   string `json:"container,omitempty"`
	Path        string `json:"path"`
	URI         string `json:"uri,omitempty"`
	Selection   *Range `json:"selection,omitempty"`
	Declaration *Range `json:"declaration,omitempty"`
	SHA256      string `json:"sha256,omitempty"`
	Excerpt     string `json:"excerpt,omitempty"`
	Depth       int    `json:"depth,omitempty"`
	Severity    string `json:"severity,omitempty"`
	Code        string `json:"code,omitempty"`
	Message     string `json:"message,omitempty"`
	Source      string `json:"source,omitempty"`
	Freshness   string `json:"freshness,omitempty"`
}

type LaunchSpec

type LaunchSpec struct {
	Root                  string
	Dir                   string
	Command               []string
	Env                   []string
	InitializationOptions json.RawMessage
	Settings              json.RawMessage
}

type Manager

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

Manager serializes query/synchronization transactions. Protocol callbacks use separate client locks, so a server can ask for configuration during a query. The manager is shared by agents, but never by independently edited worktrees.

func New

func New(config Config, deps Dependencies) (*Manager, error)

func (*Manager) Changed

func (m *Manager) Changed(path string)

Changed is a nonblocking hint; file hooks must call it after releasing their mutation lock. Empty path means a shell/external writer may have changed anything.

func (*Manager) Close

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

func (*Manager) Config

func (m *Manager) Config() Config

func (*Manager) Covers

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

Covers reports whether a configured server handles path, an absolute path inside the manager's directory.

func (*Manager) Diagnostics

func (m *Manager) Diagnostics(ctx context.Context, q DiagnosticQuery) (Page, error)

func (*Manager) Handles

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

Handles reports whether a configured server handles path's language, wherever the file is.

func (*Manager) Inspect

func (m *Manager) Inspect(ctx context.Context, q InspectQuery) (Inspection, error)

func (*Manager) Navigate

func (m *Manager) Navigate(ctx context.Context, q NavigateQuery) (Page, error)

func (*Manager) Outline

func (m *Manager) Outline(ctx context.Context, q OutlineQuery) (Page, error)

func (*Manager) References

func (m *Manager) References(ctx context.Context, q ReferenceQuery) (Page, error)

func (*Manager) Status

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

func (*Manager) Symbols

func (m *Manager) Symbols(ctx context.Context, q SymbolQuery) (Page, error)

type Metadata

type Metadata struct {
	Sources   []Source          `json:"sources"`
	Freshness string            `json:"freshness"`
	Coverage  string            `json:"coverage"`
	Partial   bool              `json:"partial"`
	Issues    []string          `json:"issues,omitempty"`
	Checks    []DiagnosticCheck `json:"checks,omitempty"`
}
type NavigateQuery struct {
	Target   Target
	Relation string
	PageQuery
}

type OutlineQuery

type OutlineQuery struct {
	Path  string
	Depth int
	PageQuery
}

type Page

type Page struct {
	Items      []Item   `json:"items"`
	NextCursor string   `json:"next_cursor,omitempty"`
	Truncated  bool     `json:"truncated"`
	Metadata   Metadata `json:"metadata"`
}

type PageQuery

type PageQuery struct {
	Limit  int
	Cursor string
}

type Position

type Position struct {
	Line   int `json:"line"`
	Column int `json:"column"`
}

Positions exposed by Strap are one-based Unicode code point offsets, not tabs' display width or the server's negotiated code units. Range ends are exclusive.

type Range

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

type ReferenceQuery

type ReferenceQuery struct {
	Target             Target
	IncludeDeclaration bool
	PageQuery
}

type ResolveRequest

type ResolveRequest struct {
	SessionDir, Path string
	Server           ServerConfig
}

type ServerConfig

type ServerConfig struct {
	ID                    string            `json:"id"`
	Adapter               string            `json:"adapter,omitempty"`
	Command               []string          `json:"command"`
	Languages             map[string]string `json:"languages"`       // File suffix -> LSP language ID.
	Roots                 []string          `json:"roots,omitempty"` // Relative to Config.Dir.
	RootMarkers           []string          `json:"root_markers,omitempty"`
	FallbackToSession     bool              `json:"fallback_to_session,omitempty"` // Use Dir when no root marker is found.
	Env                   map[string]string `json:"env,omitempty"`
	InitializationOptions json.RawMessage   `json:"initialization_options,omitempty"`
	Settings              json.RawMessage   `json:"settings,omitempty"`
}

type ServerStatus

type ServerStatus struct {
	ID         string   `json:"id"`
	Root       string   `json:"root,omitempty"`
	State      string   `json:"state"`
	Version    string   `json:"version,omitempty"`
	Generation uint64   `json:"generation,omitempty"`
	Operations []string `json:"operations,omitempty"`
	Error      string   `json:"error,omitempty"`
}

type Source

type Source struct {
	Server        string `json:"server"`
	Root          string `json:"root"`
	Generation    uint64 `json:"generation"`
	Configuration string `json:"configuration"`
}

type Status

type Status struct {
	Servers []ServerStatus `json:"servers"`
}

type SymbolQuery

type SymbolQuery struct {
	Query, Path string
	PageQuery
}

type Target

type Target struct {
	Ref, Path    string
	Line, Column int
	// Symbol selects an exact identifier on Line; Context optionally restricts
	// it to a verbatim single-line fragment. Column is a library-only
	// alternative for callers which already have an exact position.
	Symbol  string
	Context *string
}

Jump to

Keyboard shortcuts

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