lsp

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Overview

Package lsp provides a manager for Language Server Protocol (LSP) clients.

Index

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

func HandleRegisterCapability(_ context.Context, _ string, params json.RawMessage) (any, error)

HandleRegisterCapability handles capability registration requests

func HandleServerMessage

func HandleServerMessage(_ context.Context, method string, params json.RawMessage)

HandleServerMessage handles server messages

func HandleWorkspaceConfiguration

func HandleWorkspaceConfiguration(_ context.Context, _ string, params json.RawMessage) (any, error)

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

func (c *Client) Close(ctx context.Context) error

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

func (c *Client) CloseAllFiles(ctx context.Context)

CloseAllFiles closes all currently open files.

func (*Client) FileTypes

func (c *Client) FileTypes() []string

FileTypes returns the file types this LSP client handles

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

func (c *Client) GetName() string

GetName returns the name of the LSP client

func (*Client) GetServerState

func (c *Client) GetServerState() ServerState

GetServerState returns the current state of the LSP server

func (*Client) HandlesFile

func (c *Client) HandlesFile(path string) bool

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

func (c *Client) IsFileOpen(filepath string) bool

IsFileOpen checks if a file is currently open.

func (*Client) Kill

func (c *Client) Kill()

Kill kills the client without doing anything else.

func (*Client) NotifyChange

func (c *Client) NotifyChange(ctx context.Context, filepath string) error

NotifyChange notifies the server about a file change.

func (*Client) NotifyWorkspaceChange

func (c *Client) NotifyWorkspaceChange(ctx context.Context) error

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

func (c *Client) OpenFile(ctx context.Context, filepath string) error

OpenFile opens a file in the LSP server.

func (*Client) OpenFileOnDemand

func (c *Client) OpenFileOnDemand(ctx context.Context, filepath string) error

OpenFileOnDemand opens a file only if it's not already open.

func (*Client) RefreshOpenFiles

func (c *Client) RefreshOpenFiles(ctx context.Context)

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

func (c *Client) RegisterServerRequestHandler(method string, handler transport.Handler)

RegisterServerRequestHandler handles server requests.

func (*Client) Restart

func (c *Client) Restart() error

Restart closes the current LSP client and creates a new one with the same configuration.

func (*Client) SetDiagnosticsCallback

func (c *Client) SetDiagnosticsCallback(callback func(name string, count int))

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

func (c *Client) WaitForDiagnostics(ctx context.Context, timeout time.Duration)

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.

func (*Client) WaitForServerReady

func (c *Client) WaitForServerReady(ctx context.Context) error

WaitForServerReady waits for the server to be ready

type DiagnosticCounts

type DiagnosticCounts struct {
	Error       int
	Warning     int
	Information int
	Hint        int
}

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

func (s *Manager) Clients() *csync.Map[string, *Client]

Clients returns the map of LSP clients.

func (*Manager) KillAll

func (s *Manager) KillAll(context.Context)

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

func (s *Manager) SetCallback(cb func(name string, client *Client))

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

func (s *Manager) Start(ctx context.Context, path string)

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

func (s *Manager) StopAll(ctx context.Context)

StopAll stops all running LSP clients and clears the client map.

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
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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