Documentation
¶
Overview ¶
Package lsp is a small Language Server Protocol client: it starts the configured servers lazily over stdio, keeps the files it has shown them in sync with disk, and collects diagnostics, definitions and references.
Index ¶
- Constants
- Variables
- func PathToURI(path string) string
- func RuneToUTF16(line string, col int) int
- func URIToPath(uri string) (string, error)
- func UTF16ToRune(line string, units int) int
- type Diagnostic
- type Event
- type FileDiagnostics
- type Location
- type Manager
- func (m *Manager) Close()
- func (m *Manager) Definition(ctx context.Context, path string, pos Position) ([]Location, error)
- func (m *Manager) Diagnostics(ctx context.Context, paths []string, wait time.Duration) []FileDiagnostics
- func (m *Manager) Names() []string
- func (m *Manager) References(ctx context.Context, path string, pos Position) ([]Location, error)
- func (m *Manager) ServerFor(path string) (string, bool)
- func (m *Manager) TakeEvents() []Event
- type Options
- type Position
- type Range
- type UnavailableError
Constants ¶
const ( StateStarted = "started" StateCrashed = "crashed" StateStopped = "stopped" )
Server states reported in events.
const ( SeverityError = 1 SeverityWarning = 2 )
Severities of a Diagnostic.
Variables ¶
var ErrNoServer = errors.New("no lsp server configured")
ErrNoServer is returned for a file no configured server handles.
Functions ¶
func RuneToUTF16 ¶
RuneToUTF16 converts a zero-based rune column in line to UTF-16 units. A column past the end is clamped to the line length.
func UTF16ToRune ¶
UTF16ToRune converts a zero-based UTF-16 column in line to runes.
Types ¶
type Diagnostic ¶
type Diagnostic struct {
Range Range `json:"range"`
Severity int `json:"severity,omitempty"`
Source string `json:"source,omitempty"`
Message string `json:"message"`
}
Diagnostic is one published diagnostic.
func (Diagnostic) IsError ¶
func (d Diagnostic) IsError() bool
IsError reports whether d is an error; a missing severity counts as one.
type FileDiagnostics ¶
type FileDiagnostics struct {
Path string
Server string
Items []Diagnostic
// Ready is false when the server published nothing in time.
Ready bool
Err error
}
FileDiagnostics is the outcome for one file.
type Location ¶
Location is a resolved definition or reference: an absolute path and a zero-based UTF-16 range.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager owns the configured servers for one run. It is safe for concurrent use.
func (*Manager) Close ¶
func (m *Manager) Close()
Close shuts every running server down (shutdown and exit, then a kill of its process group after a short grace) and records a stopped event for each. Later calls do nothing.
func (*Manager) Definition ¶
Definition returns where the symbol at pos in path is defined.
func (*Manager) Diagnostics ¶
func (m *Manager) Diagnostics(ctx context.Context, paths []string, wait time.Duration) []FileDiagnostics
Diagnostics syncs each path and waits up to wait (for all of them together) for the server's diagnostics. Paths no server handles are skipped. A file whose content the server already has returns the last published diagnostics at once.
func (*Manager) References ¶
References returns the references to the symbol at pos in path, including its declaration.
func (*Manager) TakeEvents ¶
TakeEvents returns and clears the lifecycle events recorded so far.
type Options ¶
type Options struct {
// Root is the workspace root: the server's working directory and
// root URI.
Root string
Servers []config.LSPServer
// LogDir receives one stderr log per server and run ("" discards
// server stderr). LogPrefix starts each log's file name.
LogDir string
LogPrefix string
}
Options configures a Manager.
type UnavailableError ¶
type UnavailableError struct {
}
UnavailableError reports a server that can't be used for the rest of the run.
func (*UnavailableError) Error ¶
func (e *UnavailableError) Error() string