Documentation
¶
Overview ¶
Package lsp provides a client implementation for the Language Server Protocol (LSP).
Index ¶
- Constants
- func CreateFullDocumentChange(content string) []protocol.TextDocumentContentChangeEvent
- func DetectLanguage(path string) protocol.LanguageKind
- func FilePathToURI(path string) stringdeprecated
- func URIToFilePath(uri string) string
- type Client
- func (c *Client) Exit() error
- func (c *Client) FindReferences(ctx context.Context, filepath string, line, character int, ...) ([]protocol.Location, error)
- func (c *Client) GetCapabilities() protocol.ServerCapabilities
- func (c *Client) Initialize(ctx context.Context, enableSnippets bool) error
- func (c *Client) IsInitialized() bool
- func (c *Client) IsRunning() bool
- func (c *Client) Kill()
- func (c *Client) NotifyDidChangeTextDocument(ctx context.Context, uri string, version int, ...) error
- func (c *Client) NotifyDidChangeWatchedFiles(ctx context.Context, changes []protocol.FileEvent) error
- func (c *Client) NotifyDidCloseTextDocument(ctx context.Context, uri string) error
- func (c *Client) NotifyDidOpenTextDocument(ctx context.Context, uri string, languageID string, version int, text string) error
- func (c *Client) NotifyWorkspaceDidChangeConfiguration(ctx context.Context, settings any) error
- func (c *Client) RegisterHandler(method string, handler transport.Handler)
- func (c *Client) RegisterNotificationHandler(method string, handler transport.NotificationHandler)
- func (c *Client) RequestCompletion(ctx context.Context, uri string, position protocol.Position) (*protocol.CompletionList, error)
- func (c *Client) RequestHover(ctx context.Context, uri string, position protocol.Position) (*protocol.Hover, error)
- func (c *Client) Shutdown(ctx context.Context) error
- type ClientConfig
- type Document
- type Message
- type OffsetEncoding
- type ResponseError
- type TextDocumentSyncManager
- func (m *TextDocumentSyncManager) Change(uri string, changes []protocol.TextDocumentContentChangeEvent) error
- func (m *TextDocumentSyncManager) Close(uri string) error
- func (m *TextDocumentSyncManager) GetDocument(uri string) (*Document, bool)
- func (m *TextDocumentSyncManager) Open(uri, languageID, content string) error
- func (m *TextDocumentSyncManager) OpenFile(filePath, content string) error
- func (m *TextDocumentSyncManager) Save(uri string, includeText bool) error
Constants ¶
const ( MethodInitialize = "initialize" MethodInitialized = "initialized" MethodShutdown = "shutdown" MethodExit = "exit" MethodTextDocumentDidOpen = "textDocument/didOpen" MethodTextDocumentDidChange = "textDocument/didChange" MethodTextDocumentDidSave = "textDocument/didSave" MethodTextDocumentDidClose = "textDocument/didClose" MethodTextDocumentCompletion = "textDocument/completion" MethodTextDocumentHover = "textDocument/hover" MethodTextDocumentDefinition = "textDocument/definition" MethodTextDocumentReferences = "textDocument/references" MethodTextDocumentDiagnostic = "textDocument/publishDiagnostics" MethodWorkspaceConfiguration = "workspace/configuration" MethodWorkspaceDidChangeConfiguration = "workspace/didChangeConfiguration" MethodWorkspaceDidChangeWorkspaceFolders = "workspace/didChangeWorkspaceFolders" MethodWorkspaceDidChangeWatchedFiles = "workspace/didChangeWatchedFiles" )
LSP method constants.
Variables ¶
This section is empty.
Functions ¶
func CreateFullDocumentChange ¶
func CreateFullDocumentChange(content string) []protocol.TextDocumentContentChangeEvent
CreateFullDocumentChange creates a change event for full document sync.
func DetectLanguage ¶
func DetectLanguage(path string) protocol.LanguageKind
DetectLanguage detects the language of a given file path.
func FilePathToURI
deprecated
FilePathToURI converts a file path to a file URI.
Deprecated: use protocol.URIFromPath.
func URIToFilePath ¶
URIToFilePath converts a file URI to a file path.
Types ¶
type Client ¶
Client represents an LSP client connection to a language server.
func NewClient ¶
func NewClient(config ClientConfig) (*Client, error)
NewClient creates a new LSP client with the given configuration.
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) GetCapabilities ¶
func (c *Client) GetCapabilities() protocol.ServerCapabilities
GetCapabilities returns the server capabilities.
func (*Client) Initialize ¶
Initialize sends the initialize request to the language server.
func (*Client) IsInitialized ¶
IsInitialized returns whether the client has been initialized.
func (*Client) NotifyDidChangeTextDocument ¶
func (c *Client) NotifyDidChangeTextDocument(ctx context.Context, uri string, version int, changes []protocol.TextDocumentContentChangeEvent) error
NotifyDidChangeTextDocument notifies the server that a document was changed.
func (*Client) NotifyDidChangeWatchedFiles ¶
func (c *Client) NotifyDidChangeWatchedFiles(ctx context.Context, changes []protocol.FileEvent) error
NotifyDidChangeWatchedFiles notifies the server that watched files have changed.
func (*Client) NotifyDidCloseTextDocument ¶
NotifyDidCloseTextDocument notifies the server that a document was closeed.
func (*Client) NotifyDidOpenTextDocument ¶
func (c *Client) NotifyDidOpenTextDocument(ctx context.Context, uri string, languageID string, version int, text string) error
NotifyDidOpenTextDocument notifies the server that a document was opened.
func (*Client) NotifyWorkspaceDidChangeConfiguration ¶
NotifyWorkspaceDidChangeConfiguration notifies the server that the workspace configuration has changed.
func (*Client) RegisterHandler ¶
RegisterHandler registers a handler for server-initiated requests.
func (*Client) RegisterNotificationHandler ¶
func (c *Client) RegisterNotificationHandler(method string, handler transport.NotificationHandler)
RegisterNotificationHandler registers a handler for server-initiated notifications.
func (*Client) RequestCompletion ¶
func (c *Client) RequestCompletion(ctx context.Context, uri string, position protocol.Position) (*protocol.CompletionList, error)
RequestCompletion requests completion items at the given position.
type ClientConfig ¶
type ClientConfig struct {
Command string
Args []string
RootURI string
WorkspaceFolders []protocol.WorkspaceFolder
InitOptions map[string]any
Settings map[string]any
Environment map[string]string
Timeout time.Duration
}
ClientConfig represents the configuration for creating a new LSP client.
type Message ¶
type Message struct {
JSONRPC string `json:"jsonrpc"`
ID int32 `json:"id,omitempty"`
Method string `json:"method,omitempty"`
Params json.RawMessage `json:"params,omitempty"`
Result json.RawMessage `json:"result,omitempty"`
Error *ResponseError `json:"error,omitempty"`
}
Message represents a JSON-RPC 2.0 message.
func NewNotification ¶
NewNotification creates a new JSON-RPC 2.0 notification message.
type OffsetEncoding ¶
type OffsetEncoding int
OffsetEncoding represents the character encoding used for text document offsets.
const ( // UTF8 encoding - bytes. UTF8 OffsetEncoding = iota // UTF16 encoding - default for LSP. UTF16 // UTF32 encoding - codepoints. UTF32 )
type ResponseError ¶
ResponseError represents a JSON-RPC 2.0 error.
type TextDocumentSyncManager ¶
type TextDocumentSyncManager struct {
// contains filtered or unexported fields
}
TextDocumentSyncManager manages text document synchronization with the language server.
func NewTextDocumentSyncManager ¶
func NewTextDocumentSyncManager(client *Client) *TextDocumentSyncManager
NewTextDocumentSyncManager creates a new text document sync manager.
func (*TextDocumentSyncManager) Change ¶
func (m *TextDocumentSyncManager) Change(uri string, changes []protocol.TextDocumentContentChangeEvent) error
Change applies changes to an open document.
func (*TextDocumentSyncManager) Close ¶
func (m *TextDocumentSyncManager) Close(uri string) error
Close closes a text document.
func (*TextDocumentSyncManager) GetDocument ¶
func (m *TextDocumentSyncManager) GetDocument(uri string) (*Document, bool)
GetDocument returns the document for the given URI.
func (*TextDocumentSyncManager) Open ¶
func (m *TextDocumentSyncManager) Open(uri, languageID, content string) error
Open opens a new text document.
func (*TextDocumentSyncManager) OpenFile ¶
func (m *TextDocumentSyncManager) OpenFile(filePath, content string) error
OpenFile opens a new text document from a file path.