lsp

package
v0.6.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 3, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DiagnosticSeverityError       = 1
	DiagnosticSeverityWarning     = 2
	DiagnosticSeverityInformation = 3
	DiagnosticSeverityHint        = 4
)

Variables

This section is empty.

Functions

func DiagnosticSeverityName

func DiagnosticSeverityName(severity int) string

DiagnosticSeverityName returns the human-readable name for a diagnostic severity.

func FileURI

func FileURI(path string) string

FileURI converts a file path to a file:// URI.

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 CallHierarchyItem struct {
	Name           string          `json:"name"`
	Kind           int             `json:"kind"`
	Detail         string          `json:"detail,omitempty"`
	URI            string          `json:"uri"`
	Range          Range           `json:"range"`
	SelectionRange Range           `json:"selectionRange"`
	Data           json.RawMessage `json:"data,omitempty"`
}

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 Diagnostic struct {
	Range    Range  `json:"range"`
	Severity int    `json:"severity,omitempty"`
	Code     any    `json:"code,omitempty"`
	Source   string `json:"source,omitempty"`
	Message  string `json:"message"`
}

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 DocumentSymbol struct {
	Name           string           `json:"name"`
	Detail         string           `json:"detail,omitempty"`
	Kind           int              `json:"kind"`
	Range          Range            `json:"range"`
	SelectionRange Range            `json:"selectionRange"`
	Children       []DocumentSymbol `json:"children,omitempty"`
}

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 Location

type Location struct {
	URI   string `json:"uri"`
	Range Range  `json:"range"`
}

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager caches LSP sessions so servers are reused across tool invocations.

func NewManager

func NewManager(workingDir string) *Manager

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) Close

func (m *Manager) Close()

Close shuts down all cached sessions.

func (*Manager) CollectAllDiagnostics

func (m *Manager) CollectAllDiagnostics(ctx context.Context) map[string][]Diagnostic

CollectAllDiagnostics returns raw diagnostics grouped by file path.

func (*Manager) DetectServers

func (m *Manager) DetectServers() []Server

DetectServers finds all available LSP servers for the workspace.

func (*Manager) FindServer

func (m *Manager) FindServer(filePath string) *Server

FindServer finds an appropriate LSP server for the given file.

func (*Manager) GetSession

func (m *Manager) GetSession(ctx context.Context, filePath string) (*Session, error)

GetSession returns a cached session or creates a new one for the given file.

func (*Manager) GetSessionByServer

func (m *Manager) GetSessionByServer(ctx context.Context, server Server) (*Session, error)

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

func (m *Manager) WorkingDir() string

WorkingDir returns the working directory for this manager.

func (*Manager) WorkspaceDiagnostics

func (m *Manager) WorkspaceDiagnostics(ctx context.Context) (string, error)

WorkspaceDiagnostics collects diagnostics across all workspace files.

func (*Manager) WorkspaceSymbols

func (m *Manager) WorkspaceSymbols(ctx context.Context, query string) (string, error)

WorkspaceSymbols searches for symbols across the workspace.

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 Position

type Position struct {
	Line      int `json:"line"`
	Character int `json:"character"`
}

type PublishDiagnosticsParams

type PublishDiagnosticsParams struct {
	URI         string       `json:"uri"`
	Diagnostics []Diagnostic `json:"diagnostics"`
}

type Range

type Range struct {
	Start Position `json:"start"`
	End   Position `json:"end"`
}

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

func (s *Session) CallAndAwait(ctx context.Context, method string, params any, result any) error

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

func (s *Session) ClearPushDiagnostics(uri string)

ClearPushDiagnostics removes cached push diagnostics for a URI, so that fresh diagnostics will be collected after the next change.

func (*Session) Close

func (s *Session) Close()

Close shuts down the LSP server connection.

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

func (s *Session) Definition(ctx context.Context, uri string, line, column int) (string, error)

Definition returns the definition location(s) for the symbol at the given position.

func (*Session) Diagnostics

func (s *Session) Diagnostics(ctx context.Context, uri string, filePath string) (string, error)

Diagnostics returns formatted diagnostics for a single file.

func (*Session) DocumentSymbols

func (s *Session) DocumentSymbols(ctx context.Context, uri string, filePath string) (string, error)

DocumentSymbols returns the symbols in a document.

func (*Session) Hover

func (s *Session) Hover(ctx context.Context, uri string, line, column int) (string, error)

Hover returns hover information for the symbol at the given position.

func (*Session) Implementation

func (s *Session) Implementation(ctx context.Context, uri string, line, column int) (string, error)

Implementation returns the implementation location(s) for the symbol at the given position.

func (*Session) IsAlive

func (s *Session) IsAlive() bool

IsAlive returns true if the underlying LSP server process is still running.

func (*Session) OpenDocument

func (s *Session) OpenDocument(ctx context.Context, filePath string) (string, error)

OpenDocument opens a document in the LSP server, syncing content if already open.

func (*Session) OpenedDocURIs

func (s *Session) OpenedDocURIs() []string

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

func (s *Session) References(ctx context.Context, uri string, line, column int) (string, error)

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 SymbolInformation struct {
	Name     string   `json:"name"`
	Kind     int      `json:"kind"`
	Location Location `json:"location"`
}

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 TextDocumentItem struct {
	URI        string `json:"uri"`
	LanguageID string `json:"languageId"`
	Version    int    `json:"version"`
	Text       string `json:"text"`
}

type TextDocumentPositionParams

type TextDocumentPositionParams struct {
	TextDocument TextDocumentIdentifier `json:"textDocument"`
	Position     Position               `json:"position"`
}

type TextDocumentSyncClientCapabilities

type TextDocumentSyncClientCapabilities struct {
	DidSave bool `json:"didSave,omitempty"`
}

type VersionedTextDocumentIdentifier

type VersionedTextDocumentIdentifier struct {
	URI     string `json:"uri"`
	Version int    `json:"version"`
}

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"`
}

Directories

Path Synopsis
Package jsonrpc2 is a minimal implementation of the JSON RPC 2 spec.
Package jsonrpc2 is a minimal implementation of the JSON RPC 2 spec.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL