lsp

package
v1.7.3 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

SPDX-License-Identifier: MIT Purpose: LSP (Language Server Protocol) client. JSON-RPC 2.0 over stdio with Content-Length framing per the LSP spec. Supports initialize, textDocument/didOpen, didChange, didClose, and the standard textDocument/* requests.

SPDX-License-Identifier: MIT Purpose: language registry — detects available LSP servers (gopls, pyright, tsserver) on the system PATH and provides ServerSpec for each so the Client knows how to spawn them.

Index

Constants

This section is empty.

Variables

View Source
var DefaultServers = []ServerSpec{
	{Language: "go", Binary: "gopls", FileExts: []string{".go"}},
	{Language: "python", Binary: "pyright-langserver", Args: []string{"--stdio"}, Aliases: []string{"pyright"}, FileExts: []string{".py"}},
	{Language: "python", Binary: "pylsp", FileExts: []string{".py"}},
	{Language: "typescript", Binary: "typescript-language-server", Args: []string{"--stdio"}, Aliases: []string{"tsserver", "ts-ls"}, FileExts: []string{".ts", ".tsx"}},
	{Language: "javascript", Binary: "typescript-language-server", Args: []string{"--stdio"}, Aliases: []string{"tsserver"}, FileExts: []string{".js", ".jsx"}},
	{Language: "rust", Binary: "rust-analyzer", FileExts: []string{".rs"}},
}

Functions

func LanguageForFile

func LanguageForFile(path string) string

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func Start

func Start(binary string, args []string, lang, rootURI string) (*Client, error)

func (*Client) Call

func (c *Client) Call(method string, params any, result any, timeout time.Duration) error

func (*Client) Close

func (c *Client) Close() error

func (*Client) Definition

func (c *Client) Definition(uri string, pos Position) ([]Location, error)

func (*Client) DefinitionRaw

func (c *Client) DefinitionRaw(uri string, pos Position) (string, error)

func (*Client) DidChange

func (c *Client) DidChange(uri string, version int, changes []TextDocumentContentChangeEvent) error

func (*Client) DidClose

func (c *Client) DidClose(uri string) error

func (*Client) DidOpen

func (c *Client) DidOpen(doc TextDocumentItem) error

func (*Client) Format

func (c *Client) Format(uri string) ([]TextEdit, error)

func (*Client) Hover

func (c *Client) Hover(uri string, pos Position) (*Hover, error)

func (*Client) Lang

func (c *Client) Lang() string

func (*Client) Notify

func (c *Client) Notify(method string, params any) error

func (*Client) References

func (c *Client) References(uri string, pos Position, includeDecl bool) ([]Location, error)

func (*Client) Rename

func (c *Client) Rename(uri string, pos Position, newName string) (*WorkspaceEdit, error)

func (*Client) RootURI

func (c *Client) RootURI() string

func (*Client) SetNotificationHandler

func (c *Client) SetNotificationHandler(fn func(method string, params json.RawMessage))

SetNotificationHandler registers a callback for server-to-client notifications (window/logMessage, $/progress, etc.). Notifications are received in addition to response frames — they don't replace responses.

func (*Client) Symbols

func (c *Client) Symbols(uri string) ([]DocumentSymbol, error)

type ClientCapabilities

type ClientCapabilities struct {
	TextDocument map[string]any `json:"textDocument,omitempty"`
	Workspace    map[string]any `json:"workspace,omitempty"`
}

type Diagnostic

type Diagnostic struct {
	Range    Range  `json:"range"`
	Severity *int   `json:"severity,omitempty"`
	Code     any    `json:"code,omitempty"`
	Source   string `json:"source,omitempty"`
	Message  string `json:"message"`
}

type DocumentSymbol

type DocumentSymbol struct {
	Name           string           `json:"name"`
	Detail         string           `json:"detail,omitempty"`
	Kind           int              `json:"kind"`
	Tags           []any            `json:"tags,omitempty"`
	Deprecated     *bool            `json:"deprecated,omitempty"`
	Range          Range            `json:"range"`
	SelectionRange Range            `json:"selectionRange"`
	Children       []DocumentSymbol `json:"children,omitempty"`
}

type Hover

type Hover struct {
	Contents any    `json:"contents"`
	Range    *Range `json:"range,omitempty"`
}

type InitializeParams

type InitializeParams struct {
	ProcessID    int                `json:"processId"`
	RootURI      string             `json:"rootUri"`
	Capabilities ClientCapabilities `json:"capabilities"`
	ClientInfo   map[string]string  `json:"clientInfo,omitempty"`
}

type InitializeResult

type InitializeResult struct {
	Capabilities ServerCapabilities `json:"capabilities"`
	ServerInfo   map[string]string  `json:"serverInfo,omitempty"`
}

type Location

type Location struct {
	URI   string `json:"uri"`
	Range Range  `json:"range"`
}
type LocationLink struct {
	OriginSelectionRange *Range `json:"originSelectionRange,omitempty"`
	TargetURI            string `json:"targetUri"`
	TargetRange          Range  `json:"targetRange"`
	TargetSelectionRange Range  `json:"targetSelectionRange"`
}

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

func NewManager

func NewManager() *Manager

func (*Manager) Close

func (m *Manager) Close()

func (*Manager) Get

func (m *Manager) Get(lang, rootURI string) (*Client, error)

type Position

type Position struct {
	Line      int `json:"line"`
	Character int `json:"character"`
}

type PublishDiagnosticsParams

type PublishDiagnosticsParams struct {
	URI         string       `json:"uri"`
	Diagnostics []Diagnostic `json:"diagnostics"`
}

type Range

type Range struct {
	Start Position `json:"start"`
	End   Position `json:"end"`
}

type RenameParams

type RenameParams struct {
	TextDocument TextDocumentIdentifier `json:"textDocument"`
	Position     Position               `json:"position"`
	NewName      string                 `json:"newName"`
}

type Response

type Response struct {
	JSONRPC string          `json:"jsonrpc"`
	ID      any             `json:"id,omitempty"`
	Result  json.RawMessage `json:"result,omitempty"`
	Error   *ResponseError  `json:"error,omitempty"`
	Method  string          `json:"method,omitempty"`
	Params  json.RawMessage `json:"params,omitempty"`
}

type ResponseError

type ResponseError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Data    any    `json:"data,omitempty"`
}

type ServerCapabilities

type ServerCapabilities struct {
	TextDocumentSync           any `json:"textDocumentSync,omitempty"`
	HoverProvider              any `json:"hoverProvider,omitempty"`
	DefinitionProvider         any `json:"definitionProvider,omitempty"`
	ReferencesProvider         any `json:"referencesProvider,omitempty"`
	RenameProvider             any `json:"renameProvider,omitempty"`
	DocumentFormattingProvider any `json:"documentFormattingProvider,omitempty"`
	DocumentSymbolProvider     any `json:"documentSymbolProvider,omitempty"`
	CodeActionProvider         any `json:"codeActionProvider,omitempty"`
	CompletionProvider         any `json:"completionProvider,omitempty"`
}

type ServerSpec

type ServerSpec struct {
	Language string
	Binary   string
	Args     []string
	Aliases  []string
	FileExts []string
}

func DetectAvailable

func DetectAvailable() []ServerSpec

type SymbolInformation

type SymbolInformation struct {
	Name          string   `json:"name"`
	Kind          int      `json:"kind"`
	Deprecated    *bool    `json:"deprecated,omitempty"`
	Location      Location `json:"location"`
	ContainerName string   `json:"containerName,omitempty"`
}

type TextDocumentContentChangeEvent

type TextDocumentContentChangeEvent struct {
	Range       *Range `json:"range,omitempty"`
	RangeLength *int   `json:"rangeLength,omitempty"`
	Text        string `json:"text"`
}

type TextDocumentIdentifier

type TextDocumentIdentifier struct {
	URI string `json:"uri"`
}

type TextDocumentItem

type TextDocumentItem struct {
	URI        string `json:"uri"`
	LanguageID string `json:"languageId"`
	Version    int    `json:"version"`
	Text       string `json:"text"`
}

type TextDocumentPositionParams

type TextDocumentPositionParams struct {
	TextDocument TextDocumentIdentifier `json:"textDocument"`
	Position     Position               `json:"position"`
}

type TextEdit

type TextEdit struct {
	Range   Range  `json:"range"`
	NewText string `json:"newText"`
}

type VersionedTextDocumentIdentifier

type VersionedTextDocumentIdentifier struct {
	URI     string `json:"uri"`
	Version int    `json:"version"`
}

type WorkspaceEdit

type WorkspaceEdit struct {
	Changes map[string][]TextEdit `json:"changes,omitempty"`
}

Jump to

Keyboard shortcuts

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