package lsp¶
Functions¶
func CompleteForText¶
func CompleteForText(
path string,
text string,
pos protocol.Position,
projects *ProjectCache,
) (protocol.CompletionList, *protocol.ResponseError)
CompleteForText resolves a completion request.
func DefinitionForText¶
func DefinitionForText(
path string,
text string,
pos protocol.Position,
projects *ProjectCache,
) ([]protocol.Location, *protocol.ResponseError)
DefinitionForText resolves a go-to-definition request.
func DiagnosticsForError¶
DiagnosticsForError converts UB parser and syntax errors to LSP diagnostics.
func DiagnosticsForText¶
DiagnosticsForText parses and validates UB source text into LSP diagnostics.
func DiagnosticsForTextWithProjects¶
func DiagnosticsForTextWithProjects(
path string,
text string,
projects *ProjectCache,
) []protocol.Diagnostic
DiagnosticsForTextWithProjects adds no-fetch semantic checks when project data is available.
func DocumentSymbolsForText¶
func DocumentSymbolsForText(
path string,
text string,
) ([]protocol.DocumentSymbol, *protocol.ResponseError)
DocumentSymbolsForText parses UB text and returns document symbols.
func FileURIToPath¶
FileURIToPath converts a file URI to a local path.
func FormatText¶
FormatText formats one UB document and returns LSP text edits.
func HoverForText¶
func HoverForText(
path string,
text string,
pos protocol.Position,
projects *ProjectCache,
) (*protocol.Hover, *protocol.ResponseError)
HoverForText resolves a hover request.
func LSPToOffset¶
LSPToOffset converts a zero-based UTF-16 LSP position to a byte offset.
func OffsetToLSP¶
OffsetToLSP converts a byte offset to a zero-based UTF-16 LSP position.
func PathToFileURI¶
PathToFileURI converts a local path to a file URI.
func Serve¶
Serve runs an LSP session over stdio-compatible streams.
func ServeWithOptions¶
ServeWithOptions runs an LSP session over stdio-compatible streams.
Types¶
type Document¶
Document is the open-text state for one LSP text document.
type DocumentStore¶
DocumentStore tracks open documents by URI.
func NewDocumentStore¶
NewDocumentStore returns an empty document store.
func (*DocumentStore) Change¶
Change replaces an open document with a full text snapshot.
func (*DocumentStore) Close¶
Close removes an open document snapshot.
func (*DocumentStore) Get¶
Get returns an open document snapshot by URI.
func (*DocumentStore) Open¶
Open stores a full text document snapshot.
type ImportResolver¶
ImportResolver resolves LSP imports without network access.
func NewImportResolver¶
func NewImportResolver(
root string,
project *deps.Project,
lock *deps.ProjectLock,
remote cachedRemoteSource,
) *ImportResolver
NewImportResolver returns an import resolver for one project root.
func (*ImportResolver) Resolve¶
Resolve resolves ref or returns an error when no cached source exists.
func (*ImportResolver) ResolveNoFetch¶
ResolveNoFetch resolves ref from local files or cached remote data only.
type LineInfo¶
LineInfo records byte offsets for one logical line.
type Options¶
Options configures an LSP session.
type Project¶
type Project struct {
Root string
Marker projectmarker.Marker
DepsProject *deps.Project
ProjectLock *deps.ProjectLock
Resolver *ImportResolver
GoSchemas *compile.SchemaCache
GoIndex *goschema.SourceIndexCache
GoModuleRoots []goschema.ModuleRoot
}
Project holds cached LSP data for one project marker root.
func (*Project) EnsureGoModuleRoot¶
EnsureGoModuleRoot adds the Go module root for source when it can be found.
type ProjectCache¶
ProjectCache stores project data by marker root.
func NewProjectCache¶
NewProjectCache returns an empty project cache.
func (*ProjectCache) InvalidatePath¶
InvalidatePath removes cached project data affected by a saved path.
func (*ProjectCache) ProjectForPath¶
ProjectForPath returns cached project data for path's nearest marker root.
func (*ProjectCache) SetWorkspaceRoots¶
SetWorkspaceRoots sets weak roots used for loose files without project markers.
type Session¶
Session owns the state for one LSP client connection.
func NewSession¶
NewSession returns a new LSP session.
func (*Session) Exit¶
Exit reports whether the client has requested exit.
func (*Session) HandleRequest¶
func (s *Session) HandleRequest(
ctx context.Context,
req *protocol.RequestMessage,
) (any, *protocol.ResponseError)
HandleRequest dispatches one JSON-RPC request to the session.
func (*Session) SetSender¶
SetSender sets the server-to-client notification sender.
func (*Session) Shutdown¶
Shutdown reports whether the client has requested shutdown.
func (*Session) StopRequested¶
StopRequested reports whether the protocol server should stop serving.