Documentation
¶
Index ¶
- Constants
- func DiagnosticSeverityName(severity int) string
- func FileURI(path string) string
- func FormatDiagnostics(diagnostics []Diagnostic, filePath string, workingDir string) string
- func FormatNewDiagnostics(diagnostics []Diagnostic, filePath string, workingDir string) string
- type CallHierarchyClientCapabilities
- type CallHierarchyIncomingCall
- type CallHierarchyIncomingCallsParams
- type CallHierarchyItem
- type CallHierarchyOutgoingCall
- type CallHierarchyOutgoingCallsParams
- type ClientCapabilities
- type DefinitionClientCapabilities
- type Diagnostic
- type DiagnosticClientCapabilities
- type DiagnosticTracker
- type DidChangeTextDocumentParams
- type DidOpenTextDocumentParams
- type DidSaveTextDocumentParams
- type DocumentDiagnosticParams
- type DocumentSymbol
- type DocumentSymbolClientCapabilities
- type DocumentSymbolParams
- type FullDocumentDiagnosticReport
- type HoverClientCapabilities
- type HoverContents
- type HoverResponse
- type ImplementationClientCapabilities
- type InitializeParams
- type Location
- type Manager
- func (m *Manager) Close()
- func (m *Manager) CollectAllDiagnostics(ctx context.Context) map[string][]Diagnostic
- func (m *Manager) DetectServers() []Server
- func (m *Manager) FindServer(filePath string) *Server
- func (m *Manager) GetSession(ctx context.Context, filePath string) (*Session, error)
- func (m *Manager) GetSessionByServer(ctx context.Context, server Server) (*Session, error)
- func (m *Manager) MissingServers() []MissingServer
- func (m *Manager) WorkingDir() string
- func (m *Manager) WorkspaceDiagnostics(ctx context.Context) (string, error)
- func (m *Manager) WorkspaceSymbols(ctx context.Context, query string) (string, error)
- type MissingServer
- type Position
- type PublishDiagnosticsParams
- type Range
- type ReferenceContext
- type ReferenceParams
- type ReferencesClientCapabilities
- type Server
- type Session
- func (s *Session) CallAndAwait(ctx context.Context, method string, params any, result any) error
- func (s *Session) CallHierarchy(ctx context.Context, uri string, line, column int, incoming bool) (string, error)
- func (s *Session) ClearPushDiagnostics(uri string)
- func (s *Session) Close()
- func (s *Session) CollectDiagnostics(ctx context.Context, uri string) []Diagnostic
- func (s *Session) Definition(ctx context.Context, uri string, line, column int) (string, error)
- func (s *Session) Diagnostics(ctx context.Context, uri string, filePath string) (string, error)
- func (s *Session) DocumentSymbols(ctx context.Context, uri string, filePath string) (string, error)
- func (s *Session) Hover(ctx context.Context, uri string, line, column int) (string, error)
- func (s *Session) Implementation(ctx context.Context, uri string, line, column int) (string, error)
- func (s *Session) IsAlive() bool
- func (s *Session) OpenDocument(ctx context.Context, filePath string) (string, error)
- func (s *Session) OpenedDocURIs() []string
- func (s *Session) PushDiagnostics(uri string) []Diagnostic
- func (s *Session) References(ctx context.Context, uri string, line, column int) (string, error)
- func (s *Session) WaitForDiagnostics(ctx context.Context, uri string) []Diagnostic
- type SymbolInformation
- type TextDocumentClientCapabilities
- type TextDocumentContentChangeEvent
- type TextDocumentIdentifier
- type TextDocumentItem
- type TextDocumentPositionParams
- type TextDocumentSyncClientCapabilities
- type VersionedTextDocumentIdentifier
- type WorkspaceSymbol
- type WorkspaceSymbolParams
Constants ¶
const ( DiagnosticSeverityError = 1 DiagnosticSeverityWarning = 2 DiagnosticSeverityInformation = 3 DiagnosticSeverityHint = 4 )
Variables ¶
This section is empty.
Functions ¶
func DiagnosticSeverityName ¶
DiagnosticSeverityName returns the human-readable name for a diagnostic severity.
func FormatDiagnostics ¶
func FormatDiagnostics(diagnostics []Diagnostic, filePath string, workingDir string) string
FormatDiagnostics formats diagnostics into a human-readable string.
func FormatNewDiagnostics ¶
func FormatNewDiagnostics(diagnostics []Diagnostic, filePath string, workingDir string) string
FormatNewDiagnostics formats only new diagnostics, with severity symbols and volume limiting.
Types ¶
type CallHierarchyClientCapabilities ¶
type CallHierarchyClientCapabilities struct{}
type CallHierarchyIncomingCall ¶
type CallHierarchyIncomingCall struct {
From CallHierarchyItem `json:"from"`
FromRanges []Range `json:"fromRanges"`
}
type CallHierarchyIncomingCallsParams ¶
type CallHierarchyIncomingCallsParams struct {
Item CallHierarchyItem `json:"item"`
}
type CallHierarchyItem ¶
type CallHierarchyOutgoingCall ¶
type CallHierarchyOutgoingCall struct {
To CallHierarchyItem `json:"to"`
FromRanges []Range `json:"fromRanges"`
}
type CallHierarchyOutgoingCallsParams ¶
type CallHierarchyOutgoingCallsParams struct {
Item CallHierarchyItem `json:"item"`
}
type ClientCapabilities ¶
type ClientCapabilities struct {
TextDocument TextDocumentClientCapabilities `json:"textDocument"`
}
type DefinitionClientCapabilities ¶
type DefinitionClientCapabilities struct {
LinkSupport bool `json:"linkSupport,omitempty"`
}
type Diagnostic ¶
type DiagnosticClientCapabilities ¶
type DiagnosticClientCapabilities struct{}
type DiagnosticTracker ¶
type DiagnosticTracker struct {
// contains filtered or unexported fields
}
DiagnosticTracker tracks baselines and deduplicates diagnostics across turns.
func NewDiagnosticTracker ¶
func NewDiagnosticTracker() *DiagnosticTracker
NewDiagnosticTracker creates a new tracker.
func (*DiagnosticTracker) FilterNew ¶
func (t *DiagnosticTracker) FilterNew(uri string, diags []Diagnostic) []Diagnostic
FilterNew returns only diagnostics that are new — not in the baseline and not previously delivered. It also applies volume limiting and severity sorting.
func (*DiagnosticTracker) MarkDelivered ¶
func (t *DiagnosticTracker) MarkDelivered(uri string, diags []Diagnostic)
MarkDelivered records that these diagnostics have been shown to the model.
func (*DiagnosticTracker) SetBaseline ¶
func (t *DiagnosticTracker) SetBaseline(uri string, diags []Diagnostic)
SetBaseline records the current diagnostics as a baseline before a file is edited. Only new diagnostics (not in the baseline) will be shown after the edit.
type DidChangeTextDocumentParams ¶
type DidChangeTextDocumentParams struct {
TextDocument VersionedTextDocumentIdentifier `json:"textDocument"`
ContentChanges []TextDocumentContentChangeEvent `json:"contentChanges"`
}
type DidOpenTextDocumentParams ¶
type DidOpenTextDocumentParams struct {
TextDocument TextDocumentItem `json:"textDocument"`
}
type DidSaveTextDocumentParams ¶
type DidSaveTextDocumentParams struct {
TextDocument TextDocumentIdentifier `json:"textDocument"`
}
type DocumentDiagnosticParams ¶
type DocumentDiagnosticParams struct {
TextDocument TextDocumentIdentifier `json:"textDocument"`
}
type DocumentSymbol ¶
type DocumentSymbolClientCapabilities ¶
type DocumentSymbolClientCapabilities struct{}
type DocumentSymbolParams ¶
type DocumentSymbolParams struct {
TextDocument TextDocumentIdentifier `json:"textDocument"`
}
type FullDocumentDiagnosticReport ¶
type FullDocumentDiagnosticReport struct {
Kind string `json:"kind"`
Items []Diagnostic `json:"items"`
}
type HoverClientCapabilities ¶
type HoverClientCapabilities struct {
ContentFormat []string `json:"contentFormat,omitempty"`
}
type HoverContents ¶
type HoverContents struct {
Value string
}
HoverContents handles the multiple formats that LSP servers may return: MarkupContent { kind, value }, a plain string, or MarkedString { language, value }.
func (*HoverContents) UnmarshalJSON ¶
func (h *HoverContents) UnmarshalJSON(data []byte) error
type HoverResponse ¶
type HoverResponse struct {
Contents HoverContents `json:"contents"`
Range *Range `json:"range,omitempty"`
}
type ImplementationClientCapabilities ¶
type ImplementationClientCapabilities struct{}
type InitializeParams ¶
type InitializeParams struct {
ProcessID int `json:"processId"`
RootURI string `json:"rootUri"`
Capabilities ClientCapabilities `json:"capabilities"`
}
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager caches LSP sessions so servers are reused across tool invocations.
func NewManager ¶
NewManager creates a new LSP session manager. Callers should only instantiate one when LSP is actually wanted for the workspace; outside project mode they should keep the field nil.
func (*Manager) CollectAllDiagnostics ¶
func (m *Manager) CollectAllDiagnostics(ctx context.Context) map[string][]Diagnostic
CollectAllDiagnostics returns raw diagnostics grouped by file path.
func (*Manager) DetectServers ¶
DetectServers finds all available LSP servers for the workspace.
func (*Manager) FindServer ¶
FindServer finds an appropriate LSP server for the given file.
func (*Manager) GetSession ¶
GetSession returns a cached session or creates a new one for the given file.
func (*Manager) GetSessionByServer ¶
GetSessionByServer returns a cached session or creates a new one for a specific server. If the server has crashed, it attempts to restart it and re-open previously opened documents.
func (*Manager) MissingServers ¶
func (m *Manager) MissingServers() []MissingServer
MissingServers returns project types detected in the workspace that have no available LSP server binary.
func (*Manager) WorkingDir ¶
WorkingDir returns the working directory for this manager.
func (*Manager) WorkspaceDiagnostics ¶
WorkspaceDiagnostics collects diagnostics across all workspace files.
type MissingServer ¶
type MissingServer struct {
ProjectName string // e.g. "go", "typescript"
Servers []string // candidate commands that were not found
}
MissingServer describes a detected project type with no available LSP server.
type PublishDiagnosticsParams ¶
type PublishDiagnosticsParams struct {
URI string `json:"uri"`
Diagnostics []Diagnostic `json:"diagnostics"`
}
type ReferenceContext ¶
type ReferenceContext struct {
IncludeDeclaration bool `json:"includeDeclaration"`
}
type ReferenceParams ¶
type ReferenceParams struct {
TextDocument TextDocumentIdentifier `json:"textDocument"`
Position Position `json:"position"`
Context ReferenceContext `json:"context"`
}
type ReferencesClientCapabilities ¶
type ReferencesClientCapabilities struct{}
type Server ¶
type Server struct {
Name string // Display name (e.g., "gopls")
Command string // Binary name (e.g., "gopls")
Args []string // Arguments (e.g., ["serve"])
Languages []string // File extensions without dot (e.g., ["go"])
LanguageID string // LSP language identifier (e.g., "go")
}
Server describes an LSP server binary and how to invoke it.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session represents a connected LSP server session.
func (*Session) CallAndAwait ¶
CallAndAwait invokes an LSP method and waits for the result. It retries transient errors (e.g. rust-analyzer's "content modified") with exponential backoff.
func (*Session) CallHierarchy ¶
func (s *Session) CallHierarchy(ctx context.Context, uri string, line, column int, incoming bool) (string, error)
CallHierarchy returns incoming or outgoing calls for the symbol at the given position.
func (*Session) ClearPushDiagnostics ¶
ClearPushDiagnostics removes cached push diagnostics for a URI, so that fresh diagnostics will be collected after the next change.
func (*Session) CollectDiagnostics ¶
func (s *Session) CollectDiagnostics(ctx context.Context, uri string) []Diagnostic
CollectDiagnostics retrieves diagnostics for a single document URI. It first checks push-based diagnostics (from publishDiagnostics notifications), then falls back to pull-based diagnostics (textDocument/diagnostic request).
func (*Session) Definition ¶
Definition returns the definition location(s) for the symbol at the given position.
func (*Session) Diagnostics ¶
Diagnostics returns formatted diagnostics for a single file.
func (*Session) DocumentSymbols ¶
DocumentSymbols returns the symbols in a document.
func (*Session) Implementation ¶
Implementation returns the implementation location(s) for the symbol at the given position.
func (*Session) IsAlive ¶
IsAlive returns true if the underlying LSP server process is still running.
func (*Session) OpenDocument ¶
OpenDocument opens a document in the LSP server, syncing content if already open.
func (*Session) OpenedDocURIs ¶
OpenedDocURIs returns the URIs of all documents that were opened in this session.
func (*Session) PushDiagnostics ¶
func (s *Session) PushDiagnostics(uri string) []Diagnostic
PushDiagnostics returns any diagnostics received via publishDiagnostics for the URI.
func (*Session) References ¶
References returns all references to the symbol at the given position.
func (*Session) WaitForDiagnostics ¶
func (s *Session) WaitForDiagnostics(ctx context.Context, uri string) []Diagnostic
WaitForDiagnostics waits for diagnostics until results appear or the context expires. It checks both push-based (publishDiagnostics notifications) and pull-based sources.
type SymbolInformation ¶
type TextDocumentClientCapabilities ¶
type TextDocumentClientCapabilities struct {
Synchronization TextDocumentSyncClientCapabilities `json:"synchronization"`
Hover HoverClientCapabilities `json:"hover"`
Definition DefinitionClientCapabilities `json:"definition"`
References ReferencesClientCapabilities `json:"references"`
Implementation ImplementationClientCapabilities `json:"implementation"`
DocumentSymbol DocumentSymbolClientCapabilities `json:"documentSymbol"`
Diagnostic DiagnosticClientCapabilities `json:"diagnostic"`
CallHierarchy CallHierarchyClientCapabilities `json:"callHierarchy"`
}
type TextDocumentContentChangeEvent ¶
type TextDocumentContentChangeEvent struct {
Text string `json:"text"`
}
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 TextDocumentSyncClientCapabilities ¶
type TextDocumentSyncClientCapabilities struct {
DidSave bool `json:"didSave,omitempty"`
}
type WorkspaceSymbol ¶
type WorkspaceSymbol struct {
Name string `json:"name"`
Kind int `json:"kind"`
Location struct {
URI string `json:"uri"`
Range *Range `json:"range,omitempty"`
} `json:"location"`
}
WorkspaceSymbol is the newer response type for workspace/symbol (since 3.17). Unlike SymbolInformation, its location range may be omitted.
type WorkspaceSymbolParams ¶
type WorkspaceSymbolParams struct {
Query string `json:"query"`
}