Documentation
¶
Overview ¶
Package lsp implements the Language Server Protocol over a full-duplex, cancellable JSON-RPC connection. Unknown methods and extension fields remain available through Call and Notify rather than a closed method enumeration.
Index ¶
- Constants
- Variables
- func ApplySemanticDelta(previous []uint32, edits []SemanticTokensEdit) ([]uint32, error)
- func ApplyTextEdits(content string, edits []TextEdit, encoding PositionEncoding) (string, error)
- func OffsetAt[V piecetree.Value](value V, p Position, encoding PositionEncoding) (int, error)
- func Request[P, R any](ctx context.Context, c *Conn, method string, params P) (R, error)
- type Client
- func (c *Client) CloseDocument(ctx context.Context, uri URI) error
- func (c *Client) Configure(ctx context.Context, configuration json.RawMessage) error
- func (c *Client) DidSave(ctx context.Context, uri URI) error
- func (c *Client) DidSaveText[V piecetree.Value](ctx context.Context, uri URI, value V) error
- func (c *Client) DocumentVersion(uri URI) (int, bool)
- func (c *Client) ProviderOptions(method, capability string) json.RawMessage
- func (c *Client) Shutdown(ctx context.Context) error
- func (c *Client) Supports(method, capability string) bool
- func (c *Client) SyncDocument[V piecetree.Value](ctx context.Context, uri URI, language string, value V, version int) error
- func (c *Client) WillSave(ctx context.Context, uri URI) error
- type CodeAction
- type Command
- type CompletionItem
- type Conn
- func (c *Conn) BeginCall(ctx context.Context, method string, params any) (PendingCall, error)
- func (c *Conn) Call(ctx context.Context, method string, params, result any) error
- func (c *Conn) Close()
- func (c *Conn) Done() <-chan struct{}
- func (c *Conn) Err() error
- func (c *Conn) Flush(ctx context.Context) error
- func (c *Conn) Notify(ctx context.Context, method string, params any) error
- type Diagnostic
- type Handler
- type Location
- type LocationLink
- type Message
- type Options
- type PendingCall
- type Position
- type PositionEncoding
- type PublishDiagnosticsParams
- type Range
- type Reader
- type Registration
- type ResponseError
- type SemanticToken
- type SemanticTokens
- type SemanticTokensDelta
- type SemanticTokensEdit
- type ServerCapabilities
- type TextDocumentEdit
- type TextDocumentIdentifier
- type TextDocumentPositionParams
- type TextEdit
- type URI
- type VersionedTextDocumentIdentifier
- type WorkspaceEdit
- type WorkspaceFolder
- type Writer
Constants ¶
const ( DiagnosticSeverityHint = 4 DiagnosticTagUnnecessary = 1 DiagnosticTagDeprecated = 2 )
const ( ParseError = -32700 InvalidRequest = -32600 MethodNotFound = -32601 InvalidParams = -32602 InternalError = -32603 RequestCancelled = -32800 ContentModified = -32801 )
const MaxMessage = 32 << 20
Variables ¶
var ErrClosed = errors.New("lsp: connection closed")
var SemanticTokenModifiers = []string{"declaration", "definition", "readonly", "static", "deprecated", "abstract", "async", "modification", "documentation", "defaultLibrary"}
var SemanticTokenTypes = []string{"namespace", "type", "class", "enum", "interface", "struct", "typeParameter", "parameter", "variable", "property", "enumMember", "event", "function", "method", "macro", "keyword", "modifier", "comment", "string", "number", "regexp", "operator", "decorator"}
Functions ¶
func ApplySemanticDelta ¶
func ApplySemanticDelta(previous []uint32, edits []SemanticTokensEdit) ([]uint32, error)
func ApplyTextEdits ¶
func ApplyTextEdits(content string, edits []TextEdit, encoding PositionEncoding) (string, error)
ApplyTextEdits validates the entire edit set before creating a new string. All endpoints are resolved in a single forward scan. Sorting costs O(m log m) for m edits, and scanning/copying costs O(n) for n document bytes.
Types ¶
type Client ¶
type Client struct {
Capabilities ServerCapabilities
ProcessDone <-chan struct{}
*Conn
Encoding PositionEncoding
Root URI
// contains filtered or unexported fields
}
func Connect ¶
Connect runs LSP negotiation over an owned remote stdio stream. Process creation, PATH lookup, and reaping belong to pencode-server.
func (*Client) DidSaveText ¶
func (*Client) ProviderOptions ¶
func (c *Client) ProviderOptions(method, capability string) json.RawMessage
ProviderOptions includes dynamically registered trigger characters and resolve support, using the same provider selection as Supports.
func (*Client) Shutdown ¶
Shutdown performs shutdown -> response -> exit, flushes the final notification and reaps the process. A deadline also terminates unresponsive servers.
type CodeAction ¶
type CodeAction struct {
Title string `json:"title"`
Kind string `json:"kind,omitempty"`
Edit *WorkspaceEdit `json:"edit,omitempty"`
Command *Command `json:"command,omitempty"`
Disabled *struct {
Reason string `json:"reason"`
} `json:"disabled,omitempty"`
Data json.RawMessage `json:"data,omitempty"`
}
type Command ¶
type Command struct {
Title string `json:"title"`
Command string `json:"command"`
Arguments []json.RawMessage `json:"arguments,omitempty"`
}
type CompletionItem ¶
type CompletionItem struct {
TextEdit *TextEdit `json:"textEdit,omitempty"`
Command *Command `json:"command,omitempty"`
Label string `json:"label"`
SortText string `json:"sortText,omitempty"`
FilterText string `json:"filterText,omitempty"`
Detail string `json:"detail,omitempty"`
InsertText string `json:"insertText,omitempty"`
AdditionalTextEdits []TextEdit `json:"additionalTextEdits,omitempty"`
Data json.RawMessage `json:"data,omitempty"`
Kind int `json:"kind,omitempty"`
InsertTextFormat int `json:"insertTextFormat,omitempty"`
}
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
func NewConn ¶
NewConn owns its streams. closeIO must interrupt both reads and writes. Responses are dispatched independently of handlers, so a server request can make a nested client request without deadlocking the reader.
func (*Conn) BeginCall ¶
BeginCall enqueues the request before returning. A session can therefore keep didOpen/didChange/requests ordered while waiting for responses concurrently.
type Diagnostic ¶
type Diagnostic struct {
Source string `json:"source,omitempty"`
Message string `json:"message"`
Code json.RawMessage `json:"code,omitempty"`
Tags []int `json:"tags,omitempty"`
RelatedInformation json.RawMessage `json:"relatedInformation,omitempty"`
Data json.RawMessage `json:"data,omitempty"`
Range Range `json:"range"`
Severity int `json:"severity,omitempty"`
}
type LocationLink ¶
type Message ¶
type Message struct {
Error *ResponseError `json:"error,omitempty"`
JSONRPC string `json:"jsonrpc"`
Method string `json:"method,omitempty"`
ID json.RawMessage `json:"id,omitempty"`
Params json.RawMessage `json:"params,omitempty"`
Result json.RawMessage `json:"result,omitempty"`
}
Message.ID is absent for notifications. Raw JSON preserves string and numeric server IDs, result unions, custom methods and future protocol additions.
type Options ¶
type Options struct {
// Handler receives server requests and notifications not handled internally.
// Returning MethodNotFound is required for unsupported requests.
Handler Handler
// Capabilities augments the conservative built-in client capabilities.
Capabilities map[string]any
Root string
InitializationOptions json.RawMessage
Configuration json.RawMessage
}
type PendingCall ¶
type PendingCall struct {
// contains filtered or unexported fields
}
PendingCall owns one response slot. Exactly one Wait must follow BeginCall, including when its context has been cancelled, to release the registration.
type Position ¶
func PositionAt ¶
type PositionEncoding ¶
type PositionEncoding string
Offsets and positions are checked against rune boundaries. CRLF is one line ending; characters count UTF-16 code units by default, never UTF-8 bytes.
const ( UTF8 PositionEncoding = "utf-8" UTF16 PositionEncoding = "utf-16" UTF32 PositionEncoding = "utf-32" )
type PublishDiagnosticsParams ¶
type PublishDiagnosticsParams struct {
URI URI `json:"uri"`
Version *int `json:"version,omitempty"`
Diagnostics []Diagnostic `json:"diagnostics"`
}
type Range ¶
func IncrementalChange ¶
func IncrementalChange(old, next string, encoding PositionEncoding) (Range, string)
IncrementalChange computes one minimal replacement, without allocating or splitting UTF-8 runes. It also handles changes to line endings.
type Registration ¶
type Registration struct {
ID string `json:"id"`
Method string `json:"method"`
RegisterOptions json.RawMessage `json:"registerOptions,omitempty"`
}
type ResponseError ¶
type ResponseError struct {
Message string `json:"message"`
Data json.RawMessage `json:"data,omitempty"`
Code int `json:"code"`
}
func (*ResponseError) Error ¶
func (e *ResponseError) Error() string
type SemanticToken ¶
func DecodeSemanticTokens ¶
func DecodeSemanticTokens[V piecetree.Value](dst []SemanticToken, data []uint32, value V, encoding PositionEncoding, types int) ([]SemanticToken, error)
DecodeSemanticTokens resolves relative positions in one forward document scan. The client does not advertise overlapping or multiline token support.
type SemanticTokens ¶
type SemanticTokensDelta ¶
type SemanticTokensDelta struct {
ResultID string `json:"resultId,omitempty"`
Edits []SemanticTokensEdit `json:"edits"`
}
type SemanticTokensEdit ¶
type ServerCapabilities ¶
type ServerCapabilities map[string]json.RawMessage
func (ServerCapabilities) Has ¶
func (c ServerCapabilities) Has(key string) bool
type TextDocumentEdit ¶
type TextDocumentEdit struct {
TextDocument VersionedTextDocumentIdentifier `json:"textDocument"`
Edits []TextEdit `json:"edits"`
}
type TextDocumentIdentifier ¶
type TextDocumentIdentifier struct {
URI URI `json:"uri"`
}
type TextDocumentPositionParams ¶
type TextDocumentPositionParams struct {
TextDocument TextDocumentIdentifier `json:"textDocument"`
Position Position `json:"position"`
}
type WorkspaceEdit ¶
type WorkspaceEdit struct {
Changes map[URI][]TextEdit `json:"changes,omitempty"`
DocumentChanges []json.RawMessage `json:"documentChanges,omitempty"`
ChangeAnnotations json.RawMessage `json:"changeAnnotations,omitempty"`
}