Documentation
¶
Index ¶
- Constants
- Variables
- func AutoDetect(existing map[string]bool) map[string]ServerConfig
- func DetectedServers(alreadyConfigured map[string]bool) []string
- type Client
- func (c *Client) Close() error
- func (c *Client) CodeActions(ctx context.Context, file string, line, col int) ([]CodeAction, error)
- func (c *Client) Definition(ctx context.Context, file string, line, col int) ([]Location, error)
- func (c *Client) Diagnostics(ctx context.Context, file string) ([]Diagnostic, error)
- func (c *Client) DidClose(ctx context.Context, file string) error
- func (c *Client) DidOpen(ctx context.Context, file, lang, text string) error
- func (c *Client) DocumentSymbols(ctx context.Context, file string) ([]Symbol, error)
- func (c *Client) Hover(ctx context.Context, file string, line, col int) (*Hover, error)
- func (c *Client) References(ctx context.Context, file string, line, col int) ([]Location, error)
- func (c *Client) Rename(ctx context.Context, file string, line, col int, newName string) (*WorkspaceEdit, error)
- type ClientCapabilities
- type CodeAction
- type CodeActionParams
- type Diagnostic
- type DocumentSymbolParams
- type Hover
- type HoverParams
- type InitializeParams
- type Location
- type Manager
- type MarkupContent
- type Position
- type Range
- type ReferenceParams
- type RenameParams
- type ServerConfig
- type Symbol
- type TextDocumentClientCapabilities
- type TextDocumentIdentifier
- type TextDocumentPositionParams
- type TextEdit
- type WorkspaceEdit
Constants ¶
const ( SeverityError = 1 SeverityWarning = 2 SeverityInformation = 3 SeverityHint = 4 )
Diagnostic severities (LSP spec).
const ( SymbolKindFile = 1 SymbolKindModule = 2 SymbolKindNamespace = 3 SymbolKindPackage = 4 SymbolKindClass = 5 SymbolKindMethod = 6 SymbolKindProperty = 7 SymbolKindField = 8 SymbolKindConstructor = 9 SymbolKindEnum = 10 SymbolKindInterface = 11 SymbolKindFunction = 12 SymbolKindVariable = 13 SymbolKindConstant = 14 SymbolKindString = 15 SymbolKindNumber = 16 SymbolKindBoolean = 17 SymbolKindArray = 18 SymbolKindObject = 19 SymbolKindKey = 20 SymbolKindNull = 21 SymbolKindEnumMember = 22 SymbolKindStruct = 23 SymbolKindEvent = 24 SymbolKindOperator = 25 SymbolKindTypeParameter = 26 )
LSP symbol kinds (subset of the LSP SymbolKind enum).
Variables ¶
var KnownServers = []struct { Lang string Command string Args []string }{ {"go", "gopls", []string{"serve"}}, {"typescript", "typescript-language-server", []string{"--stdio"}}, {"python", "pyright-langserver", []string{"--stdio"}}, {"python", "pylsp", []string{}}, {"rust", "rust-analyzer", []string{}}, {"c", "clangd", []string{}}, {"cpp", "clangd", []string{}}, {"java", "jdtls", []string{}}, {"ruby", "solargraph", []string{"stdio"}}, }
KnownServers maps a language ID to the server binary and default args. AutoDetect scans PATH for these binaries in priority order — the first found for a language wins. Explicit Config.LSP entries always override auto-detected ones.
Functions ¶
func AutoDetect ¶
func AutoDetect(existing map[string]bool) map[string]ServerConfig
AutoDetect scans PATH for known language server binaries and returns configs for every language that has a server available. When multiple servers exist for the same language (e.g. pyright-langserver and pylsp for Python), the first found in KnownServers order wins.
existing is the set of languages already explicitly configured — those are skipped so explicit config always takes priority.
func DetectedServers ¶
DetectedServers returns a human-readable list of auto-detected servers for boot messages. It scans PATH and returns lines like "go: gopls". Pass alreadyConfigured to skip languages with explicit config.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a JSON-RPC 2.0 connection to an LSP server over stdio.
func Start ¶
Start launches a language server process and performs the LSP initialize/initialized handshake.
func (*Client) CodeActions ¶
CodeActions requests available code actions for a position. line is 1-indexed.
func (*Client) Definition ¶
Definition requests go-to-definition at the given position. line is 1-indexed (converted to 0-indexed internally).
func (*Client) Diagnostics ¶
Diagnostics fetches diagnostics for a file. Not all servers support pull-based diagnostics (textDocument/diagnostic); for those we return an empty list. This is best-effort.
func (*Client) DocumentSymbols ¶
DocumentSymbols requests all symbols in a document.
func (*Client) References ¶
References requests all references to the symbol at the given position. line is 1-indexed.
type ClientCapabilities ¶
type ClientCapabilities struct {
TextDocument TextDocumentClientCapabilities `json:"textDocument"`
}
ClientCapabilities declares which features the client supports.
type CodeAction ¶
type CodeAction struct {
Title string `json:"title"`
Kind string `json:"kind,omitempty"`
Edit *WorkspaceEdit `json:"edit,omitempty"`
}
CodeAction describes a refactoring or fix-it action.
type CodeActionParams ¶
type CodeActionParams struct {
TextDocument TextDocumentIdentifier `json:"textDocument"`
Range Range `json:"range"`
Context struct {
Diagnostics []Diagnostic `json:"diagnostics,omitempty"`
Only []string `json:"only,omitempty"`
} `json:"context"`
}
CodeActionParams requests code actions for a range.
type Diagnostic ¶
type Diagnostic struct {
Range Range `json:"range"`
Severity int `json:"severity"`
Code string `json:"code,omitempty"`
Source string `json:"source,omitempty"`
Message string `json:"message"`
}
Diagnostic is a compiler/linter message for a range.
type DocumentSymbolParams ¶
type DocumentSymbolParams struct {
TextDocument TextDocumentIdentifier `json:"textDocument"`
}
DocumentSymbolParams requests symbols for a document.
type Hover ¶
type Hover struct {
Contents MarkupContent `json:"contents"`
Range *Range `json:"range,omitempty"`
}
Hover is the result of a textDocument/hover request.
type HoverParams ¶
type HoverParams = TextDocumentPositionParams
HoverParams requests hover information at a position.
type InitializeParams ¶
type InitializeParams struct {
RootURI string `json:"rootUri,omitempty"`
Capabilities ClientCapabilities `json:"capabilities"`
ProcessID int `json:"processId"`
}
InitializeParams is the LSP initialize request payload.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager owns the set of running LSP servers, one per language. It starts them on demand, caches the connections, and shuts them all down on Close.
func NewManager ¶
func NewManager(configs map[string]ServerConfig, rootDir string) *Manager
NewManager creates a Manager from the given server configs.
func (*Manager) Server ¶
Server returns a ready client for the given language, starting the server on first call. Subsequent calls return the cached client.
func (*Manager) ServerForFile ¶
ServerForFile maps a file path to its language and returns the server.
type MarkupContent ¶
type MarkupContent struct {
Kind string `json:"kind"` // "markdown" or "plaintext"
Value string `json:"value"`
}
MarkupContent is markdown or plaintext content.
type Position ¶
Position is a 0-indexed line and character position in a document. LSP uses 0-indexed lines; the chat tool converts from 1-indexed.
type ReferenceParams ¶
type ReferenceParams struct {
TextDocument TextDocumentIdentifier `json:"textDocument"`
Position Position `json:"position"`
Context struct {
IncludeDeclaration bool `json:"includeDeclaration"`
} `json:"context"`
}
ReferenceParams extends TextDocumentPositionParams with context.
type RenameParams ¶
type RenameParams struct {
TextDocument TextDocumentIdentifier `json:"textDocument"`
Position Position `json:"position"`
NewName string `json:"newName"`
}
RenameParams requests a symbol rename.
type ServerConfig ¶
ServerConfig describes how to start a language server.
type Symbol ¶
type Symbol struct {
Name string `json:"name"`
Kind int `json:"kind"`
Range Range `json:"range"`
SelectionRange Range `json:"selectionRange"`
Children []Symbol `json:"children,omitempty"`
}
Symbol is a document symbol (function, class, variable, etc.).
type TextDocumentClientCapabilities ¶
type TextDocumentClientCapabilities struct {
Definition *struct{} `json:"definition,omitempty"`
References *struct{} `json:"references,omitempty"`
DocumentSymbol *struct{} `json:"documentSymbol,omitempty"`
Hover *struct{} `json:"hover,omitempty"`
Rename *struct{} `json:"rename,omitempty"`
CodeAction *struct{} `json:"codeAction,omitempty"`
PublishDiagnostics *struct{} `json:"publishDiagnostics,omitempty"`
}
TextDocumentClientCapabilities enables per-feature capabilities.
type TextDocumentIdentifier ¶
type TextDocumentIdentifier struct {
URI string `json:"uri"`
}
TextDocumentIdentifier identifies a document by URI.
type TextDocumentPositionParams ¶
type TextDocumentPositionParams struct {
TextDocument TextDocumentIdentifier `json:"textDocument"`
Position Position `json:"position"`
}
TextDocumentPositionParams is a document + position, used by definition and references requests.
type WorkspaceEdit ¶
WorkspaceEdit is the result of a rename — a set of edits per file.