Documentation
¶
Overview ¶
Package lsp talks to language servers for the agent's code intelligence (spec_parity_027 PAR-TOOL-03): definitions, references, hover, symbols and diagnostics, from servers started lazily per language.
Index ¶
- Variables
- func InstallHint(language string) string
- func SnippetPath(root, key, ext string) string
- type Completion
- type CompletionList
- type Diagnostic
- type Document
- type DocumentDiagnostic
- type DocumentDiagnostics
- type DocumentInfo
- type Launcher
- type Location
- type Manager
- func (m *Manager) ChangeDocument(ctx context.Context, id string, version int64, text string) error
- func (m *Manager) Close()
- func (m *Manager) CloseDocument(id string) error
- func (m *Manager) Complete(ctx context.Context, id string, version int64, line, col int, trigger string) (CompletionList, error)
- func (m *Manager) Definition(ctx context.Context, path string, line, col int) ([]Location, error)
- func (m *Manager) Diagnostics(ctx context.Context, path string, wait time.Duration) ([]Diagnostic, error)
- func (m *Manager) DocumentDefinition(ctx context.Context, id string, version int64, line, col int) ([]Location, error)
- func (m *Manager) DocumentHover(ctx context.Context, id string, version int64, line, col int) (string, error)
- func (m *Manager) DocumentReferences(ctx context.Context, id string, version int64, line, col int) ([]Location, error)
- func (m *Manager) For(ctx context.Context, path string) (*server, error)
- func (m *Manager) Hover(ctx context.Context, path string, line, col int) (string, error)
- func (m *Manager) KeepDocuments(client string) []string
- func (m *Manager) OpenDocument(client, path, text string, version int64) DocumentInfo
- func (m *Manager) OpenSnippet(client, path, text string, version int64) DocumentInfo
- func (m *Manager) References(ctx context.Context, path string, line, col int) ([]Location, error)
- func (m *Manager) Restart(language string) error
- func (m *Manager) Running(path string) bool
- func (m *Manager) SnippetPath(key, ext string) string
- func (m *Manager) Status() []ServerStatus
- func (m *Manager) Symbols(ctx context.Context, path, query string) ([]Symbol, error)
- func (m *Manager) WatchDiagnostics(ctx context.Context, client string, send func(DocumentDiagnostics) error) error
- type NotInstalledError
- type Position
- type Process
- type Server
- type ServerStatus
- type State
- type Symbol
- type TextEdit
Constants ¶
This section is empty.
Variables ¶
var ( // ErrUnknownDocument means no open document has the ID (closed, or its // lease ran out). ErrUnknownDocument = errors.New("no such document: open it again") // ErrStale means a request was about another version of the document // than the one the server has. ErrStale = errors.New("the document has changed since") )
Errors of the editor's requests.
var ErrNoServer = errors.New("no language server for this kind of file")
ErrNoServer means no language server is configured for the file.
Functions ¶
func InstallHint ¶ added in v0.5.0
InstallHint is what to run to install language's default server ("" when there's none to suggest).
func SnippetPath ¶ added in v0.5.0
SnippetPath is where a code block's file is said to be: a folder of its own (so it's a package of its own) under the workspace's root, so it sees the workspace's module; never written to disk. Not under a folder whose name starts with "." or "_": gopls gives files there no diagnostics.
Types ¶
type Completion ¶ added in v0.5.0
type Completion struct {
Label, Kind, Detail, Documentation string
InsertText string
Edit *TextEdit
Snippet bool
AdditionalEdits []TextEdit
SortText, FilterText string
}
Completion is one completion item.
type CompletionList ¶ added in v0.5.0
type CompletionList struct {
Items []Completion
Incomplete bool
}
CompletionList is what Complete returns.
type Diagnostic ¶
type Diagnostic struct {
Line int `json:"line"`
Column int `json:"column"`
Severity string `json:"severity"`
Message string `json:"message"`
Source string `json:"source,omitempty"`
}
Diagnostic is a problem a server reports.
type Document ¶ added in v0.5.0
type Document struct {
ID string
Client string
Path string // absolute
Language string
Version int64
// contains filtered or unexported fields
}
Document is an editor document.
type DocumentDiagnostic ¶ added in v0.5.0
DocumentDiagnostic is one problem in an editor document.
type DocumentDiagnostics ¶ added in v0.5.0
type DocumentDiagnostics struct {
Document string
Version int64
Diagnostics []DocumentDiagnostic
}
DocumentDiagnostics are a document's diagnostics for a version.
type DocumentInfo ¶ added in v0.5.0
type DocumentInfo struct {
ID string // "" when its language has no server
Language string
State State
Detail string // why it's missing or failed
Install string // what to install, when missing
}
DocumentInfo is what opening a document says.
type Launcher ¶
Launcher starts a server's command in the workspace (the engine's runs it guarded, in the OS sandbox).
type Location ¶
type Location struct {
Path string `json:"path"`
Line int `json:"line"`
Column int `json:"column"`
Text string `json:"text,omitempty"`
}
Location is a place in a file, for people: the path (relative to the workspace when inside it), 1-based line and column, and the line.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager starts language servers as files need them, one per language, and keeps the files it asks about in sync with the disk.
func NewManager ¶
NewManager is a manager for the workspace root.
func (*Manager) ChangeDocument ¶ added in v0.5.0
ChangeDocument replaces a document's text with version's.
func (*Manager) Close ¶
func (m *Manager) Close()
Close shuts the servers down, and ends the starts under way, waiting for them.
func (*Manager) CloseDocument ¶ added in v0.5.0
CloseDocument closes a document.
func (*Manager) Complete ¶ added in v0.5.0
func (m *Manager) Complete(ctx context.Context, id string, version int64, line, col int, trigger string) (CompletionList, error)
Complete asks for completions at (line, col) of a document at version; trigger is the character typed that asked ("" when invoked).
func (*Manager) Definition ¶
Definition is where the symbol at (line, col) of path is defined.
func (*Manager) Diagnostics ¶
func (m *Manager) Diagnostics(ctx context.Context, path string, wait time.Duration) ([]Diagnostic, error)
Diagnostics are the problems the server reports for path as it is on disk, waiting up to wait for them.
func (*Manager) DocumentDefinition ¶ added in v0.5.0
func (m *Manager) DocumentDefinition(ctx context.Context, id string, version int64, line, col int) ([]Location, error)
DocumentDefinition is where the symbol at (line, col) is defined.
func (*Manager) DocumentHover ¶ added in v0.5.0
func (m *Manager) DocumentHover(ctx context.Context, id string, version int64, line, col int) (string, error)
DocumentHover is what the server says about the symbol at (line, col).
func (*Manager) DocumentReferences ¶ added in v0.5.0
func (m *Manager) DocumentReferences(ctx context.Context, id string, version int64, line, col int) ([]Location, error)
DocumentReferences are where the symbol at (line, col) is used.
func (*Manager) For ¶
For finds the server for path, starting it if need be. A start runs on its own (startTimeout, or until Close), not on ctx: callers wait for it, each giving up with its own ctx, and other languages go on meanwhile.
func (*Manager) KeepDocuments ¶ added in v0.5.0
KeepDocuments marks client seen, returning its documents still open.
func (*Manager) OpenDocument ¶ added in v0.5.0
func (m *Manager) OpenDocument(client, path, text string, version int64) DocumentInfo
OpenDocument opens path (absolute) for client's editor with its text, starting the server in the background when it isn't running.
func (*Manager) OpenSnippet ¶ added in v0.5.0
func (m *Manager) OpenSnippet(client, path, text string, version int64) DocumentInfo
OpenSnippet opens a code block as the file path (SnippetPath), which isn't on disk: a Go fragment is made a whole file for the server, and positions are the block's own.
func (*Manager) References ¶
References are where the symbol at (line, col) of path is used.
func (*Manager) Restart ¶ added in v0.5.0
Restart stops language's server; the next request starts it again, and the editor's documents are opened in it again.
func (*Manager) Running ¶
Running reports whether a server runs for files like path (edits then report diagnostics without starting one).
func (*Manager) SnippetPath ¶ added in v0.5.2
SnippetPath is where the code block key's file is said to be: under the workspace's root (the function SnippetPath); but a Go block in a workspace no go.mod or go.work covers is in a folder of the manager's own outside it, made for it, since gopls lists a file outside a module from its folder, which must exist (and nothing is written to the workspace).
func (*Manager) Status ¶ added in v0.5.0
func (m *Manager) Status() []ServerStatus
Status lists the configured servers and how each is.
func (*Manager) Symbols ¶
Symbols are the workspace's symbols matching query, from the server for files like path.
func (*Manager) WatchDiagnostics ¶ added in v0.5.0
func (m *Manager) WatchDiagnostics(ctx context.Context, client string, send func(DocumentDiagnostics) error) error
WatchDiagnostics sends client's documents' diagnostics to send, each document's latest first and then as they change, until ctx ends or send fails. Diagnostics about an older text than the server has are skipped: newer ones follow.
type NotInstalledError ¶ added in v0.5.0
type NotInstalledError struct{ Command string }
NotInstalledError is a server whose command isn't installed.
func (*NotInstalledError) Error ¶ added in v0.5.0
func (e *NotInstalledError) Error() string
Error says which command is missing.
type Position ¶ added in v0.5.0
type Position struct{ Line, Column int }
Position is a 1-based line and column, in characters.
type Process ¶
type Process interface {
Stdin() io.WriteCloser
Stdout() io.ReadCloser
Stop()
}
Process is a started language server: its stdin and stdout, and how to stop it.
type ServerStatus ¶ added in v0.5.0
type ServerStatus struct {
Language string
Command []string
Extensions []string
State State
Since time.Time
Err string
Install string
}
ServerStatus is a language's server, for the status list.
type State ¶ added in v0.5.0
type State string
State is how a document's server is.
const ( StateReady State = "ready" StateStarting State = "starting" StateMissing State = "missing" StateFailed State = "failed" StateIdle State = "idle" // not started yet StateNone State = "none" // no server for the language // StateUntrusted is the workspace's: its project isn't trusted, so the // editor's servers don't start (the engine decides). StateUntrusted State = "untrusted" )
The states of a server.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package lsptest is a fake language server for tests: the test binary runs it when started with BLITZ_FAKE_LSP=1 (call MaybeServe first in TestMain), and Launcher starts that.
|
Package lsptest is a fake language server for tests: the test binary runs it when started with BLITZ_FAKE_LSP=1 (call MaybeServe first in TestMain), and Launcher starts that. |