Documentation
¶
Overview ¶
Package lsp provides an LSP client for code intelligence. It communicates with language servers via JSON-RPC 2.0 over stdin/stdout.
Index ¶
- Variables
- func FindSymbolColumn(file string, line int, symbol string) (int, error)
- func FormatHover(hover *HoverResult) string
- func FormatLocations(locs []Location, cwd string, contextLines int) string
- func FormatSymbols(symbols []DocumentSymbol, cwd string) string
- func LanguageForFile(file string) string
- func PathToURI(path string) string
- func URIToPath(uri string) string
- type CapabilitySupport
- type Client
- func (c *Client) Definition(ctx context.Context, file string, line, col int) ([]Location, error)
- func (c *Client) DidClose(file string) error
- func (c *Client) DidOpen(ctx context.Context, file, languageID, content string) error
- func (c *Client) DocumentSymbols(ctx context.Context, file string) ([]DocumentSymbol, error)
- func (c *Client) Hover(ctx context.Context, file string, line, col int) (*HoverResult, error)
- func (c *Client) Initialize(ctx context.Context, rootPath string) error
- func (c *Client) References(ctx context.Context, file string, line, col int) ([]Location, error)
- func (c *Client) Shutdown(ctx context.Context) error
- type ClientCapabilities
- type DidCloseTextDocumentParams
- type DidOpenTextDocumentParams
- type DocumentSymbol
- type DocumentSymbolParams
- type DocumentSymbolSupport
- type HoverResult
- type InitializeParams
- type InitializeResult
- type Location
- type LocationLink
- type Manager
- type MarkupContent
- type Position
- type Querier
- type Range
- type RefLocation
- type ReferenceContext
- type ReferenceParams
- type ServerCapabilities
- type ServerConfig
- type SymbolInformation
- type SymbolKind
- type TextDocumentClientCapabilities
- type TextDocumentIdentifier
- type TextDocumentItem
- type TextDocumentPositionParams
Constants ¶
This section is empty.
Variables ¶
var ErrServerDied = errors.New("language server died")
ErrServerDied is returned when the language server process exits unexpectedly.
Functions ¶
func FindSymbolColumn ¶
FindSymbolColumn finds the column (0-based) of a symbol on a given line.
func FormatHover ¶
func FormatHover(hover *HoverResult) string
FormatHover formats hover information.
func FormatLocations ¶
FormatLocations formats a list of locations as readable text.
func FormatSymbols ¶
func FormatSymbols(symbols []DocumentSymbol, cwd string) string
FormatSymbols formats document symbols as a structured list.
func LanguageForFile ¶
LanguageForFile returns the language ID for the given file path.
Types ¶
type CapabilitySupport ¶
type CapabilitySupport struct {
DynamicRegistration bool `json:"dynamicRegistration"`
}
CapabilitySupport is a generic capability flag.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is an LSP client connected to a language server process.
func (*Client) Definition ¶
Definition returns definition locations for the symbol at the given position.
func (*Client) DocumentSymbols ¶
DocumentSymbols returns symbols defined in the given file.
func (*Client) Initialize ¶
Initialize performs the LSP initialize/initialized handshake.
func (*Client) References ¶
References returns all reference locations for the symbol at the given position.
type ClientCapabilities ¶
type ClientCapabilities struct {
TextDocument TextDocumentClientCapabilities `json:"textDocument,omitempty"`
}
ClientCapabilities describes client capabilities.
type DidCloseTextDocumentParams ¶
type DidCloseTextDocumentParams struct {
TextDocument TextDocumentIdentifier `json:"textDocument"`
}
DidCloseTextDocumentParams for textDocument/didClose.
type DidOpenTextDocumentParams ¶
type DidOpenTextDocumentParams struct {
TextDocument TextDocumentItem `json:"textDocument"`
}
DidOpenTextDocumentParams for textDocument/didOpen.
type DocumentSymbol ¶
type DocumentSymbol struct {
Name string `json:"name"`
Detail string `json:"detail,omitempty"`
Kind SymbolKind `json:"kind"`
Range Range `json:"range"`
SelectionRange Range `json:"selectionRange"`
Children []DocumentSymbol `json:"children,omitempty"`
}
DocumentSymbol represents a symbol in a document (hierarchical).
type DocumentSymbolParams ¶
type DocumentSymbolParams struct {
TextDocument TextDocumentIdentifier `json:"textDocument"`
}
DocumentSymbolParams for textDocument/documentSymbol.
type DocumentSymbolSupport ¶
type DocumentSymbolSupport struct {
DynamicRegistration bool `json:"dynamicRegistration"`
HierarchicalDocumentSymbolSupport bool `json:"hierarchicalDocumentSymbolSupport"`
}
DocumentSymbolSupport describes documentSymbol capabilities.
type HoverResult ¶
type HoverResult struct {
Contents MarkupContent `json:"contents"`
Range *Range `json:"range,omitempty"`
}
HoverResult is the response to textDocument/hover.
type InitializeParams ¶
type InitializeParams struct {
ProcessID int `json:"processId,omitempty"`
RootURI string `json:"rootUri"`
Capabilities ClientCapabilities `json:"capabilities"`
}
InitializeParams for the initialize request.
type InitializeResult ¶
type InitializeResult struct {
Capabilities ServerCapabilities `json:"capabilities"`
}
InitializeResult is the response to initialize.
type LocationLink ¶
type LocationLink struct {
TargetURI string `json:"targetUri"`
TargetRange Range `json:"targetRange"`
}
LocationLink is an alternative definition response format.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages language server connections, one per language.
func NewManager ¶
NewManager creates a new server manager rooted at the given directory.
func (*Manager) EnsureFileOpen ¶
EnsureFileOpen sends didOpen for the file if not already open.
type MarkupContent ¶
MarkupContent represents hover/documentation content.
type Querier ¶
type Querier struct {
// contains filtered or unexported fields
}
Querier implements in-process LSP reference lookups via a shared Manager. Spawn one Manager per repomap invocation; all symbol queries reuse it.
func NewQuerier ¶
NewQuerier returns a Querier backed by the given Manager.
type RefLocation ¶
type RefLocation struct {
File string `json:"file"`
Line int `json:"line"`
Column int `json:"column"`
}
RefLocation is a source position returned by a refs query. It mirrors the JSON shape used by the --calls pipeline.
type ReferenceContext ¶
type ReferenceContext struct {
IncludeDeclaration bool `json:"includeDeclaration"`
}
ReferenceContext controls whether the declaration is included in references.
type ReferenceParams ¶
type ReferenceParams struct {
TextDocumentPositionParams
Context ReferenceContext `json:"context"`
}
ReferenceParams extends TextDocumentPositionParams with reference context.
type ServerCapabilities ¶
type ServerCapabilities struct {
DefinitionProvider any `json:"definitionProvider,omitempty"`
ReferencesProvider any `json:"referencesProvider,omitempty"`
HoverProvider any `json:"hoverProvider,omitempty"`
DocumentSymbolProvider any `json:"documentSymbolProvider,omitempty"`
}
ServerCapabilities describes what the server supports.
type ServerConfig ¶
ServerConfig describes how to start a language server.
type SymbolInformation ¶
type SymbolInformation struct {
Name string `json:"name"`
Kind SymbolKind `json:"kind"`
Location Location `json:"location"`
}
SymbolInformation is the flat (non-hierarchical) symbol format.
type SymbolKind ¶
type SymbolKind int
SymbolKind constants.
const ( SymbolKindFile SymbolKind = 1 SymbolKindModule SymbolKind = 2 SymbolKindNamespace SymbolKind = 3 SymbolKindPackage SymbolKind = 4 SymbolKindClass SymbolKind = 5 SymbolKindMethod SymbolKind = 6 SymbolKindProperty SymbolKind = 7 SymbolKindField SymbolKind = 8 SymbolKindConstructor SymbolKind = 9 SymbolKindEnum SymbolKind = 10 SymbolKindInterface SymbolKind = 11 SymbolKindFunction SymbolKind = 12 SymbolKindVariable SymbolKind = 13 SymbolKindConstant SymbolKind = 14 SymbolKindString SymbolKind = 15 SymbolKindNumber SymbolKind = 16 SymbolKindBoolean SymbolKind = 17 SymbolKindArray SymbolKind = 18 SymbolKindObject SymbolKind = 19 SymbolKindKey SymbolKind = 20 SymbolKindNull SymbolKind = 21 SymbolKindEnumMember SymbolKind = 22 SymbolKindStruct SymbolKind = 23 SymbolKindEvent SymbolKind = 24 SymbolKindOperator SymbolKind = 25 SymbolKindTypeParameter SymbolKind = 26 )
func (SymbolKind) String ¶
func (k SymbolKind) String() string
String returns the human-readable name of the symbol kind.
type TextDocumentClientCapabilities ¶
type TextDocumentClientCapabilities struct {
Definition CapabilitySupport `json:"definition,omitempty"`
References CapabilitySupport `json:"references,omitempty"`
Hover CapabilitySupport `json:"hover,omitempty"`
DocumentSymbol DocumentSymbolSupport `json:"documentSymbol,omitempty"`
}
TextDocumentClientCapabilities describes text document capabilities.
type TextDocumentIdentifier ¶
type TextDocumentIdentifier struct {
URI string `json:"uri"`
}
TextDocumentIdentifier identifies a 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 represents a document with content.
type TextDocumentPositionParams ¶
type TextDocumentPositionParams struct {
TextDocument TextDocumentIdentifier `json:"textDocument"`
Position Position `json:"position"`
}
TextDocumentPositionParams is a common base for position-based requests.