Documentation
¶
Overview ¶
SPDX-License-Identifier: MIT Purpose: LSP (Language Server Protocol) client. JSON-RPC 2.0 over stdio with Content-Length framing per the LSP spec. Supports initialize, textDocument/didOpen, didChange, didClose, and the standard textDocument/* requests.
SPDX-License-Identifier: MIT Purpose: language registry — detects available LSP servers (gopls, pyright, tsserver) on the system PATH and provides ServerSpec for each so the Client knows how to spawn them.
Index ¶
- Variables
- func LanguageForFile(path string) string
- type Client
- func (c *Client) Call(method string, params any, result any, timeout time.Duration) error
- func (c *Client) Close() error
- func (c *Client) Definition(uri string, pos Position) ([]Location, error)
- func (c *Client) DefinitionRaw(uri string, pos Position) (string, error)
- func (c *Client) DidChange(uri string, version int, changes []TextDocumentContentChangeEvent) error
- func (c *Client) DidClose(uri string) error
- func (c *Client) DidOpen(doc TextDocumentItem) error
- func (c *Client) Format(uri string) ([]TextEdit, error)
- func (c *Client) Hover(uri string, pos Position) (*Hover, error)
- func (c *Client) Lang() string
- func (c *Client) Notify(method string, params any) error
- func (c *Client) References(uri string, pos Position, includeDecl bool) ([]Location, error)
- func (c *Client) Rename(uri string, pos Position, newName string) (*WorkspaceEdit, error)
- func (c *Client) RootURI() string
- func (c *Client) SetNotificationHandler(fn func(method string, params json.RawMessage))
- func (c *Client) Symbols(uri string) ([]DocumentSymbol, error)
- type ClientCapabilities
- type Diagnostic
- type DocumentSymbol
- type Hover
- type InitializeParams
- type InitializeResult
- type Location
- type LocationLink
- type Manager
- type Position
- type PublishDiagnosticsParams
- type Range
- type RenameParams
- type Response
- type ResponseError
- type ServerCapabilities
- type ServerSpec
- type SymbolInformation
- type TextDocumentContentChangeEvent
- type TextDocumentIdentifier
- type TextDocumentItem
- type TextDocumentPositionParams
- type TextEdit
- type VersionedTextDocumentIdentifier
- type WorkspaceEdit
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultServers = []ServerSpec{ {Language: "go", Binary: "gopls", FileExts: []string{".go"}}, {Language: "python", Binary: "pyright-langserver", Args: []string{"--stdio"}, Aliases: []string{"pyright"}, FileExts: []string{".py"}}, {Language: "python", Binary: "pylsp", FileExts: []string{".py"}}, {Language: "typescript", Binary: "typescript-language-server", Args: []string{"--stdio"}, Aliases: []string{"tsserver", "ts-ls"}, FileExts: []string{".ts", ".tsx"}}, {Language: "javascript", Binary: "typescript-language-server", Args: []string{"--stdio"}, Aliases: []string{"tsserver"}, FileExts: []string{".js", ".jsx"}}, {Language: "rust", Binary: "rust-analyzer", FileExts: []string{".rs"}}, }
Functions ¶
func LanguageForFile ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) Definition ¶
func (*Client) DefinitionRaw ¶
func (*Client) DidChange ¶
func (c *Client) DidChange(uri string, version int, changes []TextDocumentContentChangeEvent) error
func (*Client) DidOpen ¶
func (c *Client) DidOpen(doc TextDocumentItem) error
func (*Client) References ¶
func (*Client) SetNotificationHandler ¶
func (c *Client) SetNotificationHandler(fn func(method string, params json.RawMessage))
SetNotificationHandler registers a callback for server-to-client notifications (window/logMessage, $/progress, etc.). Notifications are received in addition to response frames — they don't replace responses.
type ClientCapabilities ¶
type Diagnostic ¶
type DocumentSymbol ¶
type DocumentSymbol struct {
Name string `json:"name"`
Detail string `json:"detail,omitempty"`
Kind int `json:"kind"`
Tags []any `json:"tags,omitempty"`
Deprecated *bool `json:"deprecated,omitempty"`
Range Range `json:"range"`
SelectionRange Range `json:"selectionRange"`
Children []DocumentSymbol `json:"children,omitempty"`
}
type InitializeParams ¶
type InitializeParams struct {
ProcessID int `json:"processId"`
RootURI string `json:"rootUri"`
Capabilities ClientCapabilities `json:"capabilities"`
ClientInfo map[string]string `json:"clientInfo,omitempty"`
}
type InitializeResult ¶
type InitializeResult struct {
Capabilities ServerCapabilities `json:"capabilities"`
ServerInfo map[string]string `json:"serverInfo,omitempty"`
}
type LocationLink ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
func NewManager ¶
func NewManager() *Manager
type PublishDiagnosticsParams ¶
type PublishDiagnosticsParams struct {
URI string `json:"uri"`
Diagnostics []Diagnostic `json:"diagnostics"`
}
type RenameParams ¶
type RenameParams struct {
TextDocument TextDocumentIdentifier `json:"textDocument"`
Position Position `json:"position"`
NewName string `json:"newName"`
}
type Response ¶
type Response struct {
JSONRPC string `json:"jsonrpc"`
ID any `json:"id,omitempty"`
Result json.RawMessage `json:"result,omitempty"`
Error *ResponseError `json:"error,omitempty"`
Method string `json:"method,omitempty"`
Params json.RawMessage `json:"params,omitempty"`
}
type ResponseError ¶
type ServerCapabilities ¶
type ServerCapabilities struct {
TextDocumentSync any `json:"textDocumentSync,omitempty"`
HoverProvider any `json:"hoverProvider,omitempty"`
DefinitionProvider any `json:"definitionProvider,omitempty"`
ReferencesProvider any `json:"referencesProvider,omitempty"`
RenameProvider any `json:"renameProvider,omitempty"`
DocumentFormattingProvider any `json:"documentFormattingProvider,omitempty"`
DocumentSymbolProvider any `json:"documentSymbolProvider,omitempty"`
CodeActionProvider any `json:"codeActionProvider,omitempty"`
CompletionProvider any `json:"completionProvider,omitempty"`
}
type ServerSpec ¶
type ServerSpec struct {
Language string
Binary string
Args []string
Aliases []string
FileExts []string
}
func DetectAvailable ¶
func DetectAvailable() []ServerSpec
type SymbolInformation ¶
type TextDocumentIdentifier ¶
type TextDocumentIdentifier struct {
URI string `json:"uri"`
}
type TextDocumentItem ¶
type TextDocumentPositionParams ¶
type TextDocumentPositionParams struct {
TextDocument TextDocumentIdentifier `json:"textDocument"`
Position Position `json:"position"`
}
type WorkspaceEdit ¶
Click to show internal directories.
Click to hide internal directories.