Documentation
¶
Overview ¶
Package lsp provides a JSON-RPC 2.0 client for Language Server Protocol servers (gopls, typescript-language-server, rust-analyzer, etc.).
Wire format: Content-Length framing over stdio.
Index ¶
- func LanguageID(ext string) string
- type Client
- func (c *Client) Close() error
- func (c *Client) Diagnostics(uri string) []Diagnostic
- func (c *Client) Notify(method string, params json.RawMessage) error
- func (c *Client) Request(ctx context.Context, method string, params json.RawMessage) (json.RawMessage, error)
- func (c *Client) StoreDiagnostics(uri string, diags []Diagnostic)
- type Diagnostic
- type DiagnosticSeverity
- type DidCloseTextDocumentParams
- type DidOpenTextDocumentParams
- type Hover
- type InitializeParams
- type InitializeResult
- type Location
- type Manager
- type MarkupContent
- type Position
- type PublishDiagnosticsParams
- type Range
- type ReferenceContext
- type ReferenceParams
- type TextDocumentIdentifier
- type TextDocumentItem
- type TextDocumentPositionParams
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LanguageID ¶
LanguageID returns the LSP languageId string for a file extension.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps a language server subprocess and speaks JSON-RPC 2.0 over its stdin/stdout using the Content-Length framing defined by the LSP spec.
func NewClient ¶
NewClient spawns the language server at cmd+args, performs the LSP initialize/initialized handshake, and returns a ready Client.
func NewClientFromPipes ¶
func NewClientFromPipes(ctx context.Context, stdin io.WriteCloser, stdout io.ReadCloser) (*Client, error)
NewClientFromPipes creates a Client using caller-supplied stdin/stdout pipes. This is useful for testing with an in-process mock server. It performs the same initialize/initialized handshake as NewClient.
func (*Client) Diagnostics ¶
func (c *Client) Diagnostics(uri string) []Diagnostic
Diagnostics returns the most recently cached diagnostics for uri.
func (*Client) Notify ¶
func (c *Client) Notify(method string, params json.RawMessage) error
Notify sends a JSON-RPC notification (no ID, no response expected).
func (*Client) Request ¶
func (c *Client) Request(ctx context.Context, method string, params json.RawMessage) (json.RawMessage, error)
Request sends a JSON-RPC request and blocks until the server responds.
func (*Client) StoreDiagnostics ¶
func (c *Client) StoreDiagnostics(uri string, diags []Diagnostic)
StoreDiagnostics manually sets the diagnostics cache for a URI. This is primarily useful in tests to simulate server push notifications.
type Diagnostic ¶
type Diagnostic struct {
Range Range `json:"range"`
Severity DiagnosticSeverity `json:"severity"`
Message string `json:"message"`
Source string `json:"source,omitempty"`
}
Diagnostic is a single diagnostic message from the server.
type DiagnosticSeverity ¶
type DiagnosticSeverity int
DiagnosticSeverity mirrors LSP DiagnosticSeverity.
const ( SeverityError DiagnosticSeverity = 1 SeverityWarning DiagnosticSeverity = 2 SeverityInformation DiagnosticSeverity = 3 SeverityHint DiagnosticSeverity = 4 )
func (DiagnosticSeverity) String ¶
func (s DiagnosticSeverity) String() string
type DidCloseTextDocumentParams ¶
type DidCloseTextDocumentParams struct {
TextDocument TextDocumentIdentifier `json:"textDocument"`
}
DidCloseTextDocumentParams is the payload for textDocument/didClose.
type DidOpenTextDocumentParams ¶
type DidOpenTextDocumentParams struct {
TextDocument TextDocumentItem `json:"textDocument"`
}
DidOpenTextDocumentParams is the payload for textDocument/didOpen.
type Hover ¶
type Hover struct {
Contents MarkupContent `json:"contents"`
Range *Range `json:"range,omitempty"`
}
Hover is the result of a textDocument/hover request.
type InitializeParams ¶
type InitializeParams struct {
ProcessID *int `json:"processId"`
RootURI string `json:"rootUri"`
Capabilities map[string]any `json:"capabilities"`
}
InitializeParams is the payload for the initialize request.
type InitializeResult ¶
InitializeResult is the response to initialize.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager owns one *Client per language and starts servers on demand.
type MarkupContent ¶
type MarkupContent struct {
Kind string `json:"kind"` // "plaintext" | "markdown"
Value string `json:"value"`
}
MarkupContent holds a marked-up string (plaintext or markdown).
type PublishDiagnosticsParams ¶
type PublishDiagnosticsParams struct {
URI string `json:"uri"`
Diagnostics []Diagnostic `json:"diagnostics"`
}
PublishDiagnosticsParams is sent as a server notification.
type ReferenceContext ¶
type ReferenceContext struct {
IncludeDeclaration bool `json:"includeDeclaration"`
}
ReferenceContext is included in references requests.
type ReferenceParams ¶
type ReferenceParams struct {
TextDocument TextDocumentIdentifier `json:"textDocument"`
Position Position `json:"position"`
Context ReferenceContext `json:"context"`
}
ReferenceParams extends TextDocumentPositionParams with context.
type TextDocumentIdentifier ¶
type TextDocumentIdentifier struct {
URI string `json:"uri"`
}
TextDocumentIdentifier identifies a text document by URI.
type TextDocumentItem ¶
type TextDocumentItem struct {
URI string `json:"uri"`
LanguageID string `json:"languageId"`
Version int `json:"version"`
Text string `json:"text"`
}
TextDocumentItem carries the full content of a document on open.
type TextDocumentPositionParams ¶
type TextDocumentPositionParams struct {
TextDocument TextDocumentIdentifier `json:"textDocument"`
Position Position `json:"position"`
}
TextDocumentPositionParams is the common position params for many requests.