Documentation
¶
Overview ¶
Package lsp provides a manager for Language Server Protocol (LSP) clients.
Index ¶
- func HandleApplyEdit(encoding powernap.OffsetEncoding) func(_ context.Context, _ string, params json.RawMessage) (any, error)
- func HandleDiagnostics(client *Client, params json.RawMessage)
- func HandleRegisterCapability(_ context.Context, _ string, params json.RawMessage) (any, error)
- func HandleServerMessage(_ context.Context, method string, params json.RawMessage)
- func HandleWorkspaceConfiguration(_ context.Context, _ string, params json.RawMessage) (any, error)
- func RegisterFileWatchHandler(handler FileWatchRegistrationHandler)
- type Client
- func (c *Client) Close(ctx context.Context) error
- func (c *Client) CloseAllFiles(ctx context.Context)
- func (c *Client) FileTypes() []string
- func (c *Client) FindReferences(ctx context.Context, filepath string, line, character int, ...) ([]protocol.Location, error)
- func (c *Client) GetDiagnosticCounts() DiagnosticCounts
- func (c *Client) GetDiagnostics() map[protocol.DocumentURI][]protocol.Diagnostic
- func (c *Client) GetFileDiagnostics(uri protocol.DocumentURI) []protocol.Diagnostic
- func (c *Client) GetName() string
- func (c *Client) GetServerState() ServerState
- func (c *Client) HandlesFile(path string) bool
- func (c *Client) Initialize(ctx context.Context, workspaceDir string) (*protocol.InitializeResult, error)
- func (c *Client) IsFileOpen(filepath string) bool
- func (c *Client) Kill()
- func (c *Client) NotifyChange(ctx context.Context, filepath string) error
- func (c *Client) NotifyWorkspaceChange(ctx context.Context) error
- func (c *Client) OpenFile(ctx context.Context, filepath string) error
- func (c *Client) OpenFileOnDemand(ctx context.Context, filepath string) error
- func (c *Client) RefreshOpenFiles(ctx context.Context)
- func (c *Client) RegisterNotificationHandler(method string, handler transport.NotificationHandler)
- func (c *Client) RegisterServerRequestHandler(method string, handler transport.Handler)
- func (c *Client) Restart() error
- func (c *Client) SetDiagnosticsCallback(callback func(name string, count int))
- func (c *Client) SetServerState(state ServerState)
- func (c *Client) WaitForDiagnostics(ctx context.Context, timeout time.Duration)
- func (c *Client) WaitForServerReady(ctx context.Context) error
- type DiagnosticCounts
- type FileWatchRegistrationHandler
- type Manager
- func (s *Manager) Clients() *csync.Map[string, *Client]
- func (s *Manager) KillAll(context.Context)
- func (s *Manager) SetCallback(cb func(name string, client *Client))
- func (s *Manager) Start(ctx context.Context, path string)
- func (s *Manager) StopAll(ctx context.Context)
- func (s *Manager) TrackConfigured()
- type OpenFileInfo
- type ServerState
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HandleApplyEdit ¶
func HandleApplyEdit(encoding powernap.OffsetEncoding) func(_ context.Context, _ string, params json.RawMessage) (any, error)
HandleApplyEdit handles workspace edit requests
func HandleDiagnostics ¶
func HandleDiagnostics(client *Client, params json.RawMessage)
HandleDiagnostics handles diagnostic notifications from the LSP server
func HandleRegisterCapability ¶
HandleRegisterCapability handles capability registration requests
func HandleServerMessage ¶
func HandleServerMessage(_ context.Context, method string, params json.RawMessage)
HandleServerMessage handles server messages
func HandleWorkspaceConfiguration ¶
HandleWorkspaceConfiguration handles workspace configuration requests
func RegisterFileWatchHandler ¶
func RegisterFileWatchHandler(handler FileWatchRegistrationHandler)
RegisterFileWatchHandler sets the handler for file watch registrations
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func New ¶
func New( ctx context.Context, name string, cfg config.LSPConfig, resolver config.VariableResolver, cwd string, debug bool, ) (*Client, error)
New creates a new LSP client using the powernap implementation.
func (*Client) Close ¶
Close closes all open files in the client, then shuts down gracefully. If shutdown takes longer than closeTimeout, it falls back to Kill().
func (*Client) CloseAllFiles ¶
CloseAllFiles closes all currently open files.
func (*Client) FindReferences ¶
func (c *Client) FindReferences(ctx context.Context, filepath string, line, character int, includeDeclaration bool) ([]protocol.Location, error)
FindReferences finds all references to the symbol at the given position.
func (*Client) GetDiagnosticCounts ¶
func (c *Client) GetDiagnosticCounts() DiagnosticCounts
GetDiagnosticCounts returns cached diagnostic counts by severity. Uses the VersionedMap version to avoid recomputing on every call.
func (*Client) GetDiagnostics ¶
func (c *Client) GetDiagnostics() map[protocol.DocumentURI][]protocol.Diagnostic
GetDiagnostics returns all diagnostics for all files.
func (*Client) GetFileDiagnostics ¶
func (c *Client) GetFileDiagnostics(uri protocol.DocumentURI) []protocol.Diagnostic
GetFileDiagnostics returns diagnostics for a specific file.
func (*Client) GetServerState ¶
func (c *Client) GetServerState() ServerState
GetServerState returns the current state of the LSP server
func (*Client) HandlesFile ¶
HandlesFile checks if this LSP client handles the given file based on its extension and whether it's within the working directory.
func (*Client) Initialize ¶
func (c *Client) Initialize(ctx context.Context, workspaceDir string) (*protocol.InitializeResult, error)
Initialize initializes the LSP client and returns the server capabilities.
func (*Client) IsFileOpen ¶
IsFileOpen checks if a file is currently open.
func (*Client) NotifyChange ¶
NotifyChange notifies the server about a file change.
func (*Client) NotifyWorkspaceChange ¶
NotifyWorkspaceChange sends a workspace-level file change notification to trigger re-analysis of all files. This is useful when the overall project state may have changed (e.g., after a project-wide refactoring) and diagnostics for files not currently being edited may be stale.
func (*Client) OpenFileOnDemand ¶
OpenFileOnDemand opens a file only if it's not already open.
func (*Client) RefreshOpenFiles ¶
RefreshOpenFiles re-notifies the LSP server about all currently open files, which triggers re-analysis and fresh diagnostics for the entire project.
func (*Client) RegisterNotificationHandler ¶
func (c *Client) RegisterNotificationHandler(method string, handler transport.NotificationHandler)
RegisterNotificationHandler registers a notification handler.
func (*Client) RegisterServerRequestHandler ¶
RegisterServerRequestHandler handles server requests.
func (*Client) Restart ¶
Restart closes the current LSP client and creates a new one with the same configuration.
func (*Client) SetDiagnosticsCallback ¶
SetDiagnosticsCallback sets the callback function for diagnostic changes
func (*Client) SetServerState ¶
func (c *Client) SetServerState(state ServerState)
SetServerState sets the current state of the LSP server
func (*Client) WaitForDiagnostics ¶
WaitForDiagnostics waits until diagnostics stop changing for a settling period, indicating the LSP server has finished processing. If no diagnostics change within firstChangeDuration, it returns early since the server likely isn't going to republish.
type DiagnosticCounts ¶
DiagnosticCounts holds the count of diagnostics by severity.
type FileWatchRegistrationHandler ¶
type FileWatchRegistrationHandler func(id string, watchers []protocol.FileSystemWatcher)
FileWatchRegistrationHandler is a function that will be called when file watch registrations are received
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager handles lazy initialization of LSP clients based on file types.
func NewManager ¶
func NewManager(cfg *config.ConfigStore) *Manager
NewManager creates a new LSP manager service.
func (*Manager) KillAll ¶
KillAll force-kills all the LSP clients.
This is generally faster than Manager.StopAll because it doesn't wait for the server to exit gracefully, but it can lead to data loss if the server is in the middle of writing something. Generally it doesn't matter when shutting down Seshat, though.
func (*Manager) SetCallback ¶
SetCallback sets a callback that is invoked when a new LSP client is successfully started. This allows the coordinator to add LSP tools.
func (*Manager) Start ¶
Start starts an LSP server that can handle the given file path. If an appropriate LSP is already running, this is a no-op.
func (*Manager) TrackConfigured ¶
func (s *Manager) TrackConfigured()
TrackConfigured will callback the user-configured LSPs, but will not create any clients.
type OpenFileInfo ¶
type OpenFileInfo struct {
Version int32
URI protocol.DocumentURI
}
OpenFileInfo contains information about an open file
type ServerState ¶
type ServerState int
ServerState represents the state of an LSP server
const ( StateUnstarted ServerState = iota StateStarting StateReady StateError StateStopped StateDisabled )