lsp

package
v0.13.0-a.5 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 33 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

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

func DiagnosticsForError(text string, err error) []protocol.Diagnostic

DiagnosticsForError converts UB parser and syntax errors to LSP diagnostics.

func DiagnosticsForText

func DiagnosticsForText(path string, text string) []protocol.Diagnostic

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

func FileURIToPath(rawURI string) (string, error)

FileURIToPath converts a file URI to a local path.

func FormatText

func FormatText(path string, text string) ([]protocol.TextEdit, *protocol.ResponseError)

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

func LSPToOffset(text string, pos protocol.Position) (int, bool)

LSPToOffset converts a zero-based UTF-16 LSP position to a byte offset.

func OffsetToLSP

func OffsetToLSP(text string, offset int) protocol.Position

OffsetToLSP converts a byte offset to a zero-based UTF-16 LSP position.

func PathToFileURI

func PathToFileURI(path string) string

PathToFileURI converts a local path to a file URI.

func Serve

func Serve(ctx context.Context, in io.Reader, out io.Writer, version string) error

Serve runs an LSP session over stdio-compatible streams.

func ServeWithOptions

func ServeWithOptions(
	ctx context.Context,
	in io.Reader,
	out io.Writer,
	options Options,
) (serveErr error)

ServeWithOptions runs an LSP session over stdio-compatible streams.

Types

type Document

type Document struct {
	URI     string
	Path    string
	Version int32
	Text    string
	Lines   []LineInfo
}

Document is the open-text state for one LSP text document.

type DocumentStore

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

DocumentStore tracks open documents by URI.

func NewDocumentStore

func NewDocumentStore() *DocumentStore

NewDocumentStore returns an empty document store.

func (*DocumentStore) Change

func (s *DocumentStore) Change(uri string, version int32, text string) (*Document, error)

Change replaces an open document with a full text snapshot.

func (*DocumentStore) Close

func (s *DocumentStore) Close(uri string)

Close removes an open document snapshot.

func (*DocumentStore) Get

func (s *DocumentStore) Get(uri string) (*Document, bool)

Get returns an open document snapshot by URI.

func (*DocumentStore) Open

func (s *DocumentStore) Open(uri string, version int32, text string) (*Document, error)

Open stores a full text document snapshot.

type ImportResolver

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

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

func (r *ImportResolver) Resolve(ref resolve.ImportRef) (*resolve.Source, error)

Resolve resolves ref or returns an error when no cached source exists.

func (*ImportResolver) ResolveNoFetch

func (r *ImportResolver) ResolveNoFetch(
	ref resolve.ImportRef,
) (*resolve.Source, bool, error)

ResolveNoFetch resolves ref from local files or cached remote data only.

func (*ImportResolver) ResolveNoFetchFrom added in v0.11.0

func (r *ImportResolver) ResolveNoFetchFrom(
	ref resolve.ImportRef,
	parent *resolve.Source,
) (*resolve.Source, bool, error)

ResolveNoFetchFrom resolves local refs from the declaring source and other refs from cached project data.

type LineInfo

type LineInfo struct {
	Start int
	End   int
}

LineInfo records byte offsets for one logical line.

type Options

type Options struct {
	Version string
	Trace   io.Writer
	Log     io.Writer
}

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

func (p *Project) EnsureGoModuleRoot(source *resolve.Source)

EnsureGoModuleRoot adds the Go module root for source when it can be found.

type ProjectCache

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

ProjectCache stores project data by marker root.

func NewProjectCache

func NewProjectCache(workspaceRoot string) *ProjectCache

NewProjectCache returns an empty project cache.

func (*ProjectCache) InvalidatePath

func (c *ProjectCache) InvalidatePath(path string)

InvalidatePath removes cached project data affected by a saved path.

func (*ProjectCache) ProjectForPath

func (c *ProjectCache) ProjectForPath(path string) (*Project, error)

ProjectForPath returns cached project data for path's nearest marker root.

func (*ProjectCache) SetWorkspaceRoots

func (c *ProjectCache) SetWorkspaceRoots(roots []string)

SetWorkspaceRoots sets weak roots used for loose files without project markers.

type Session

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

Session owns the state for one LSP client connection.

func NewSession

func NewSession(version string) *Session

NewSession returns a new LSP session.

func (*Session) Exit

func (s *Session) Exit() bool

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

func (s *Session) SetSender(sender protocol.Sender)

SetSender sets the server-to-client notification sender.

func (*Session) Shutdown

func (s *Session) Shutdown() bool

Shutdown reports whether the client has requested shutdown.

func (*Session) StopRequested

func (s *Session) StopRequested() bool

StopRequested reports whether the protocol server should stop serving.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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