Documentation
¶
Overview ¶
Package lsp provides Language Server Protocol integration for real-time diagnostics.
Index ¶
- type Client
- func (c *Client) ClearDiagnostic(uri protocol.DocumentURI)
- func (c *Client) Diagnostics() map[protocol.DocumentURI][]protocol.Diagnostic
- func (c *Client) HandlesFile(path string) bool
- func (c *Client) Kill()
- func (c *Client) Name() string
- func (c *Client) NotifyChange(ctx context.Context, path string) error
- func (c *Client) OpenFileOnDemand(ctx context.Context, path string) error
- func (c *Client) Shutdown(ctx context.Context)
- func (c *Client) State() ServerState
- func (c *Client) WaitForDiagnostics(ctx context.Context, timeout time.Duration)
- type Config
- type DiagnosticsInputs
- type DiagnosticsTool
- type FileInfo
- type Manager
- func (m *Manager) AllDiagnostics(ctx context.Context, path string) string
- func (m *Manager) DidOpen(ctx context.Context, path string)
- func (m *Manager) FormatDiagnostics(path string) string
- func (m *Manager) HandlesFile(server Server, path string) bool
- func (m *Manager) HasRootMarkers(server Server) bool
- func (m *Manager) NotifyChange(ctx context.Context, path string)
- func (m *Manager) ResolvePath(path string) string
- func (m *Manager) RestartAll(ctx context.Context)
- func (m *Manager) RestartServer(ctx context.Context, name string) error
- func (m *Manager) ServerCount() int
- func (m *Manager) ServerNames() []string
- func (m *Manager) Start(ctx context.Context, filePath string)
- func (m *Manager) StopAll()
- type RestartInputs
- type RestartTool
- type Server
- type ServerState
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps a powernap LSP client with diagnostic caching and file tracking.
func NewClient ¶
NewClient creates a powernap LSP client, registers the diagnostic handler, and initializes the connection. Returns an error if initialization fails.
func (*Client) ClearDiagnostic ¶
func (c *Client) ClearDiagnostic(uri protocol.DocumentURI)
ClearDiagnostic removes cached diagnostics for a single URI.
func (*Client) Diagnostics ¶
func (c *Client) Diagnostics() map[protocol.DocumentURI][]protocol.Diagnostic
Diagnostics returns a snapshot of the cached diagnostics.
func (*Client) HandlesFile ¶
HandlesFile checks whether this client handles the given file path based on configured file types and language detection.
func (*Client) NotifyChange ¶
NotifyChange reads the file from disk and sends a full-content change notification.
func (*Client) OpenFileOnDemand ¶
OpenFileOnDemand opens the file in the LSP server if not already open.
type Config ¶
type Config struct {
// Servers maps server names to their configuration.
// Example: "gopls" → {Command: "gopls", Args: ["serve"], FileTypes: ["go", "mod"]}.
Servers map[string]Server `yaml:"servers"`
}
Config holds LSP configuration passed to the Manager.
type DiagnosticsInputs ¶
type DiagnosticsInputs struct {
Path string `json:"path,omitempty" jsonschema:"description=File path to get diagnostics for. Omit for project-wide diagnostics."`
}
DiagnosticsInputs defines the parameters for the Diagnostics tool.
type DiagnosticsTool ¶
DiagnosticsTool returns LSP diagnostics for a file or the whole project.
func NewDiagnosticsTool ¶
func NewDiagnosticsTool(manager *Manager) *DiagnosticsTool
NewDiagnosticsTool creates a Diagnostics tool backed by the given manager.
func (*DiagnosticsTool) Available ¶
func (t *DiagnosticsTool) Available() bool
func (*DiagnosticsTool) Name ¶
func (t *DiagnosticsTool) Name() string
func (*DiagnosticsTool) Sandboxable ¶
func (t *DiagnosticsTool) Sandboxable() bool
Sandboxable returns false because the tool communicates with in-process LSP servers via the manager pointer, which does not exist in the sandboxed child process.
func (*DiagnosticsTool) Schema ¶
func (t *DiagnosticsTool) Schema() tool.Schema
type FileInfo ¶
type FileInfo struct {
URI protocol.DocumentURI
Version int32
}
FileInfo tracks an open file's version for incremental change notifications.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages LSP server lifecycle with lazy initialization. Servers are started on first file touch matching their file types and root markers.
func NewManager ¶
NewManager creates a manager with the given configuration. No servers are started until Start() or NotifyChange() is called.
func (*Manager) AllDiagnostics ¶
AllDiagnostics starts servers for the path, notifies changes, and returns formatted diagnostics. This is the entry point for the Diagnostics tool.
func (*Manager) DidOpen ¶
DidOpen opens the file in all LSP servers that handle it. This is the entry point for Read (no change notification, no diagnostic wait).
func (*Manager) FormatDiagnostics ¶
FormatDiagnostics returns formatted diagnostics from all clients. If path is non-empty, only diagnostics for that file are included. Resolves relative paths to absolute for URI matching. Returns empty string if there are no diagnostics.
func (*Manager) HandlesFile ¶
HandlesFile checks if a server configuration matches the given file path by extension or detected language.
func (*Manager) HasRootMarkers ¶
HasRootMarkers checks if at least one root marker is present in the working directory.
func (*Manager) NotifyChange ¶
NotifyChange opens the file on demand, sends a change notification, and waits for diagnostics on all clients handling the file. This is the primary entry point for Patch/Write tools.
func (*Manager) ResolvePath ¶
ResolvePath converts a relative path to an absolute path using the working directory. Returns the path unchanged if it's already absolute or if resolution fails.
func (*Manager) RestartAll ¶
RestartAll stops and restarts all previously configured servers.
func (*Manager) RestartServer ¶
RestartServer stops and restarts a single named server. Returns an error if the server name is not in the configuration.
func (*Manager) ServerCount ¶
ServerCount returns the number of running LSP servers.
func (*Manager) ServerNames ¶
ServerNames returns the names of all configured servers.
type RestartInputs ¶
type RestartInputs struct {
Server string `json:"server,omitempty" jsonschema:"description=Server name to restart. Omit to restart all servers."`
}
RestartInputs defines the parameters for the LspRestart tool.
type RestartTool ¶
RestartTool restarts LSP servers.
func NewRestartTool ¶
func NewRestartTool(manager *Manager) *RestartTool
NewRestartTool creates an LspRestart tool backed by the given manager.
func (*RestartTool) Available ¶
func (t *RestartTool) Available() bool
func (*RestartTool) Name ¶
func (t *RestartTool) Name() string
func (*RestartTool) Parallel ¶
func (t *RestartTool) Parallel() bool
Parallel returns false because restarting LSP servers races with Diagnostics and Read's DidOpen.
func (*RestartTool) Sandboxable ¶
func (t *RestartTool) Sandboxable() bool
Sandboxable returns false because the tool communicates with in-process LSP servers via the manager pointer, which does not exist in the sandboxed child process.
func (*RestartTool) Schema ¶
func (t *RestartTool) Schema() tool.Schema
type Server ¶
type Server struct {
// Command is the executable to run (e.g. "gopls", "typescript-language-server").
Command string `yaml:"command"`
// Args are command-line arguments (e.g. ["serve"]).
Args []string `yaml:"args"`
// FileTypes lists file extensions or language identifiers this server handles.
// Extensions can include the leading dot or not (e.g. ".go" or "go").
// Empty means the server handles all file types.
FileTypes []string `yaml:"file_types"`
// RootMarkers are filenames that identify the project root (e.g. ["go.mod"]).
// The server only starts if at least one marker is found in the working directory.
// Empty means the server applies to any directory.
RootMarkers []string `yaml:"root_markers"`
// Settings are LSP workspace settings passed to the server.
Settings map[string]any `yaml:"settings"`
// InitOptions are LSP initialization options.
InitOptions map[string]any `yaml:"init_options"`
// Timeout is the initialization timeout in seconds. Default: 30.
Timeout int `yaml:"timeout"`
// Disabled skips this server during startup. Default: false.
Disabled bool `yaml:"disabled"`
}
Server describes a single LSP server and how to match files to it.
func (Server) TimeoutOrDefault ¶
TimeoutOrDefault returns the configured timeout or 30 seconds.
type ServerState ¶
type ServerState int
ServerState represents the lifecycle state of an LSP server.
const ( StateStarting ServerState = iota StateReady StateError StateStopped )
func (ServerState) String ¶
func (s ServerState) String() string
String returns a human-readable state name.