Documentation
¶
Overview ¶
Package lsp provides framework-free language-server lifecycle leaves.
Index ¶
- Constants
- Variables
- func FileURIToPath(value string) (string, error)
- func OffsetForPosition(content []byte, position protocol.Position, ...) (int, error)
- func PathToFileURI(path string) (string, error)
- func PositionForOffset(content []byte, offset int, encoding protocol.PositionEncodingKind) (protocol.Position, error)
- func SelectWorkspaceRoot(workspaceDir, path string, markers []string) (string, error)
- type Client
- func (client *Client) Call(ctx context.Context, method string, params, result any) (success bool)
- func (client *Client) Diagnostics(path string) []Diagnostic
- func (client *Client) DidChange(ctx context.Context, path string, text []byte) bool
- func (client *Client) DidClose(ctx context.Context, path string) bool
- func (client *Client) DidOpen(ctx context.Context, path, languageID string, text []byte) bool
- func (client *Client) Notify(ctx context.Context, method string, params any) (success bool)
- func (client *Client) PositionEncoding() protocol.PositionEncodingKind
- func (client *Client) Root() string
- func (client *Client) Server() Server
- type Decoration
- type Diagnostic
- type Enforcer
- func (enforcer *Enforcer) Await(ctx context.Context, sessionID, invocationID string) (Decoration, bool)
- func (enforcer *Enforcer) Close() error
- func (enforcer *Enforcer) Drop(sessionID, invocationID string)
- func (enforcer *Enforcer) ObserveTouch(ctx context.Context, touch workspace.Touch)
- func (enforcer *Enforcer) Status() string
- type EnforcerOptions
- type LookPathFunc
- type Manager
- type ManagerOptions
- type MessageHandler
- type RPCTransport
- type Registry
- type Server
- type StartFunc
- type Transport
Constants ¶
const ( DefaultInitializeTimeout = 10 * time.Second DefaultRequestTimeout = 5 * time.Second DefaultFailureLimit = 3 )
const DefaultDiagnosticsPerFile = 20
const (
DefaultMaxMessageBytes = int64(4 << 20)
)
Variables ¶
var ( ErrManagerClosed = errors.New("LSP manager is closed") ErrUnknownServer = errors.New("unknown LSP server") )
var ( // ErrInvalidURI indicates a non-file or malformed document URI. ErrInvalidURI = errors.New("invalid LSP file URI") // ErrInvalidPosition indicates a byte offset or LSP position that does not // identify a Unicode boundary in the supplied document. ErrInvalidPosition = errors.New("invalid LSP position") )
var ( ErrMessageTooLarge = errors.New("LSP message exceeds limit") ErrMalformedTransport = errors.New("malformed LSP transport") )
Functions ¶
func FileURIToPath ¶
FileURIToPath converts a file URI to a native path. Drive-letter URIs remain recognizable on non-Windows hosts so portable fixture data can be decoded.
func OffsetForPosition ¶
func OffsetForPosition(content []byte, position protocol.Position, encoding protocol.PositionEncodingKind) (int, error)
OffsetForPosition converts an LSP position to a byte offset.
func PathToFileURI ¶
PathToFileURI converts an absolute native or Windows path to a file URI.
func PositionForOffset ¶
func PositionForOffset(content []byte, offset int, encoding protocol.PositionEncodingKind) (protocol.Position, error)
PositionForOffset converts a byte offset to the requested LSP encoding.
func SelectWorkspaceRoot ¶
SelectWorkspaceRoot checks markers in precedence order and returns the nearest ancestor containing the first marker found anywhere beneath the workspace boundary. If none match, it returns workspaceDir.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is one initialized server/root lifecycle.
func (*Client) Call ¶
Call performs a bounded request. Runtime failure returns false after warning instead of leaking a server outage into the host operation.
func (*Client) Diagnostics ¶
func (client *Client) Diagnostics(path string) []Diagnostic
Diagnostics returns a defensive deterministic snapshot for path.
func (*Client) PositionEncoding ¶
func (client *Client) PositionEncoding() protocol.PositionEncodingKind
PositionEncoding returns the encoding negotiated during initialize.
type Decoration ¶
type Decoration struct {
Diagnostics []Diagnostic
Text string
}
Decoration is the deterministic LSP addition for one successful mutation.
type Diagnostic ¶
type Diagnostic struct {
Path string `json:"path"`
Start protocol.Position `json:"start"`
End protocol.Position `json:"end"`
Severity protocol.DiagnosticSeverity `json:"severity"`
Code string `json:"code,omitempty"`
Source string `json:"source,omitempty"`
Message string `json:"message"`
}
Diagnostic is Plasmid's deterministic, JSON-safe diagnostic projection.
func NormalizeDiagnostics ¶
func NormalizeDiagnostics(rootDir, documentURI string, values []protocol.Diagnostic, maximum int) ([]Diagnostic, error)
NormalizeDiagnostics confines, sorts, deduplicates, and bounds diagnostics for one document URI.
type Enforcer ¶
type Enforcer struct {
// contains filtered or unexported fields
}
Enforcer synchronizes successful write/edit touches and correlates their diagnostics with the exact tool invocation that caused the document version.
func NewEnforcer ¶
func NewEnforcer(options EnforcerOptions) (*Enforcer, error)
NewEnforcer subscribes to the shared touch bus without starting a server.
func (*Enforcer) Await ¶
func (enforcer *Enforcer) Await(ctx context.Context, sessionID, invocationID string) (Decoration, bool)
Await consumes one invocation receipt and waits within the configured settle bound.
func (*Enforcer) Drop ¶
Drop releases any receipt that cannot reach a successful after-tool callback.
func (*Enforcer) ObserveTouch ¶
ObserveTouch implements workspace.TouchObserver.
type EnforcerOptions ¶
type EnforcerOptions struct {
WorkspaceDir string
Touches *workspace.TouchBus
Registry Registry
Manager enforcementManager
SettleTimeout time.Duration
Output outputlimit.Policy
Warnings warning.Warner
Maximum int
}
EnforcerOptions binds the framework-free LSP lifecycle to workspace touches.
type LookPathFunc ¶
LookPathFunc is the executable-detection seam. Production uses exec.LookPath; tests can prove that detection never installs anything.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager owns lazy language-server processes independently of any Harness.
func NewManager ¶
func NewManager(parent context.Context, registry Registry, options ManagerOptions) (*Manager, error)
NewManager creates a lifecycle owner. No executable lookup or process start occurs until Start is called.
func (*Manager) ActiveServers ¶
ActiveServers returns deterministic server IDs for live clients.
type ManagerOptions ¶
type ManagerOptions struct {
Warnings warning.Warner
LookPath LookPathFunc
Start StartFunc
InitializeTimeout time.Duration
RequestTimeout time.Duration
FailureLimit int
MaxMessageBytes int64
DiagnosticsPerFile int
}
ManagerOptions controls bounded LSP lifecycle behavior.
type MessageHandler ¶
MessageHandler receives server-to-client calls. Its result is used only for requests; notification results are discarded.
type RPCTransport ¶
type RPCTransport struct {
// contains filtered or unexported fields
}
RPCTransport is a bounded sourcegraph/jsonrpc2 connection.
func NewRPCTransport ¶
func NewRPCTransport(ctx context.Context, connection io.ReadWriteCloser, maximum int64, handler MessageHandler) (*RPCTransport, error)
NewRPCTransport constructs a bounded Content-Length framed connection. The context owns the connection lifetime.
func (*RPCTransport) Call ¶
Call sends one bounded LSP request and decodes its result with the protocol package's union-aware codec.
func (*RPCTransport) Close ¶
func (transport *RPCTransport) Close() error
Close closes the connection.
func (*RPCTransport) Done ¶
func (transport *RPCTransport) Done() <-chan struct{}
Done closes when the underlying JSON-RPC stream disconnects.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry is an immutable, deterministic language-server registry.
func DefaultRegistry ¶
func DefaultRegistry() Registry
DefaultRegistry returns the built-in registry.
func MergeRegistry ¶
MergeRegistry overlays entries on the built-ins by server ID. Invalid entries are skipped and reported without invalidating unrelated servers.
type Server ¶
type Server struct {
ID string
Command string
Args []string
Extensions []string
RootMarkers []string
Disabled bool
}
Server describes one language-server executable and the files it owns.