Documentation
¶
Overview ¶
Package lsp provides a Language Server Protocol client for hawk. It manages LSP server subprocesses with refcounted connection pooling, idle reaping, and typed crash recovery.
Index ¶
- Variables
- func ResetConfig()
- type Client
- type Diagnostic
- type DiagnosticSeverity
- type LSPClient
- func (c *LSPClient) Close() error
- func (c *LSPClient) Diagnostics(ctx context.Context, uri string) ([]Diagnostic, error)
- func (c *LSPClient) DocumentSymbol(ctx context.Context, uri string) ([]SymbolInformation, error)
- func (c *LSPClient) FindReferences(ctx context.Context, uri string, line, char int) ([]Location, error)
- func (c *LSPClient) GotoDefinition(ctx context.Context, uri string, line, char int) ([]Location, error)
- func (c *LSPClient) Language() string
- func (c *LSPClient) PrepareRename(ctx context.Context, uri string, line, char int) (*Range, error)
- func (c *LSPClient) Rename(ctx context.Context, uri string, line, char int, newName string) (*WorkspaceEdit, error)
- type LSPConfig
- type LSPError
- type LSPManager
- type Location
- type ManagedClient
- type Position
- type Range
- type RenameCapabilities
- type Request
- type Response
- type ResponseError
- type ServerConfig
- type ServerManager
- type SymbolInformation
- type TextEdit
- type WorkspaceEdit
Constants ¶
This section is empty.
Variables ¶
var ( ErrManagerClosed = &LSPError{Code: "MANAGER_CLOSED", Message: "LSP manager is closed"} ErrLanguageNotConfigured = &LSPError{Code: "LANG_NOT_CONFIGURED", Message: "no LSP server configured for language"} )
Errors
var ReadOnlyRetryTools = map[string]bool{ "diagnostics": true, "goto_definition": true, "find_references": true, "symbols": true, "prepare_rename": true, "status": true, }
ReadOnlyRetryTools contains tool names that are safe to retry on crash.
Functions ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents an LSP client connection.
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 represents an LSP diagnostic.
type DiagnosticSeverity ¶
type DiagnosticSeverity int
DiagnosticSeverity represents LSP diagnostic severity levels.
const ( SeverityError DiagnosticSeverity = 1 SeverityWarning DiagnosticSeverity = 2 SeverityInformation DiagnosticSeverity = 3 SeverityHint DiagnosticSeverity = 4 )
type LSPClient ¶
type LSPClient struct {
// contains filtered or unexported fields
}
LSPClient communicates with a single language server subprocess.
func NewLSPClient ¶
NewLSPClient starts a language server subprocess and initializes the LSP protocol.
func (*LSPClient) Diagnostics ¶
Diagnostics requests diagnostics for a file.
func (*LSPClient) DocumentSymbol ¶
DocumentSymbol returns all symbols in a document.
func (*LSPClient) FindReferences ¶
func (c *LSPClient) FindReferences(ctx context.Context, uri string, line, char int) ([]Location, error)
FindReferences finds all references to a symbol at a position.
func (*LSPClient) GotoDefinition ¶
func (c *LSPClient) GotoDefinition(ctx context.Context, uri string, line, char int) ([]Location, error)
GotoDefinition finds the definition of a symbol at a position.
func (*LSPClient) PrepareRename ¶
PrepareRename checks if a symbol at a position can be renamed.
type LSPConfig ¶
type LSPConfig struct {
Servers map[string]ServerConfig `json:"lsp"`
}
LSPConfig holds all configured language servers.
func LoadConfig ¶
LoadConfig merges project-level (.agents/lsp.json) and global user-state LSP configuration. Project-level overrides global.
func (*LSPConfig) LanguageForExtension ¶
LanguageForExtension returns the language name for a file extension, or empty string if no LSP server is configured for that extension.
func (*LSPConfig) ServerForFile ¶
func (c *LSPConfig) ServerForFile(filePath string) (string, ServerConfig, bool)
ServerForFile returns the language and server config for a file path.
type LSPManager ¶
type LSPManager struct {
// contains filtered or unexported fields
}
LSPManager manages a pool of language server connections.
func NewManager ¶
func NewManager(cfg *LSPConfig) *LSPManager
NewManager creates an LSPManager with the given config.
func NewManagerFromProject ¶
func NewManagerFromProject(projectDir string) *LSPManager
NewManagerFromProject creates an LSPManager loading config from project directory.
func (*LSPManager) Close ¶
func (m *LSPManager) Close() error
Close shuts down all language server connections.
func (*LSPManager) Config ¶
func (m *LSPManager) Config() *LSPConfig
Config returns the LSP configuration.
func (*LSPManager) Execute ¶
func (m *LSPManager) Execute(ctx context.Context, lang string, readOnly bool, fn func(client *LSPClient) error) error
Execute runs fn with an LSPClient, handling acquire/release and crash recovery. readOnly indicates if the operation is idempotent (safe to retry once on crash).
func (*LSPManager) Status ¶
func (m *LSPManager) Status() map[string]string
Status returns the state of all configured language servers.
type ManagedClient ¶
type ManagedClient struct {
// contains filtered or unexported fields
}
ManagedClient wraps an LSPClient with refcounting and idle tracking.
type RenameCapabilities ¶
type RenameCapabilities struct {
PrepareSupport bool `json:"prepareSupport,omitempty"`
}
RenameCapabilities describes rename support.
type Request ¶
type Request struct {
JSONRPC string `json:"jsonrpc"`
ID int `json:"id"`
Method string `json:"method"`
Params interface{} `json:"params,omitempty"`
}
Request is an LSP request.
type Response ¶
type Response struct {
JSONRPC string `json:"jsonrpc"`
ID int `json:"id,omitempty"`
Method string `json:"method,omitempty"`
Result json.RawMessage `json:"result,omitempty"`
Error *ResponseError `json:"error,omitempty"`
}
Response is an LSP response.
type ResponseError ¶
ResponseError is an LSP error.
type ServerConfig ¶
type ServerConfig struct {
Command string `json:"command"`
Args []string `json:"args,omitempty"`
Extensions []string `json:"extensions"`
}
ServerConfig defines how to launch a language server for a given language.
type ServerManager ¶
type ServerManager struct {
// contains filtered or unexported fields
}
ServerManager manages LSP server connections.
func NewServerManager ¶
func NewServerManager() *ServerManager
NewServerManager creates a new LSP server manager.
func (*ServerManager) IsRunning ¶
func (m *ServerManager) IsRunning(name string) bool
IsRunning checks if a server is running.
func (*ServerManager) List ¶
func (m *ServerManager) List() []string
List returns all running servers.
func (*ServerManager) Start ¶
func (m *ServerManager) Start(name, command string, args ...string) error
Start starts an LSP server.
func (*ServerManager) Stop ¶
func (m *ServerManager) Stop(name string) error
Stop stops an LSP server gracefully.
type SymbolInformation ¶
type SymbolInformation struct {
Name string `json:"name"`
Kind int `json:"kind"`
Location Location `json:"location"`
ContainerName string `json:"containerName,omitempty"`
}
SymbolInformation represents an LSP symbol.
type WorkspaceEdit ¶
WorkspaceEdit represents an LSP workspace edit.