workspace

package
v0.0.0-...-6cc8dd8 Latest Latest
Warning

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

Go to latest
Published: May 28, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateLexerDiagnostics

func CreateLexerDiagnostics(doc *core.Document) []*core.Diagnostic

CreateLexerDiagnostics creates diagnostics from lexer errors.

func CreateLinkerDiagnostics

func CreateLinkerDiagnostics(doc *core.Document) []*core.Diagnostic

CreateLinkerDiagnostics creates diagnostics from linker errors (unresolved references).

func CreateParserDiagnostics

func CreateParserDiagnostics(doc *core.Document) []*core.Diagnostic

CreateParserDiagnostics creates diagnostics from parser errors.

func SetupDefaultServices

func SetupDefaultServices(sc *service.Container)

SetupDefaultServices sets up the default services for the workspace package. If any service is already set, it's not overwritten.

Types

type BuildStepListener

type BuildStepListener func(ctx context.Context, doc *core.Document) error

BuildStepListener is called right after a document has completed a build step. If the listener returns an error, it will be logged but will not prevent other listeners from being called.

type Builder

type Builder interface {
	// Build processes the provided documents through all build phases (parse, compute
	// symbol table, link, validate). It should regularly check ctx for cancellation
	// between phases. downgrade must be called by the implementation once phases 1 and 2
	// (the write phase) are complete; this transitions the workspace lock to readable so
	// that read requests can proceed while phase 3 (validation) runs.
	Build(ctx context.Context, docs []*core.Document, downgrade func()) error
	// Reset selectively clears build results of a document. The state parameter is a
	// bitmask of states to keep; for every bit that is not set, the corresponding document
	// fields are reset to their initial values and the bit is cleared from doc.State.
	Reset(doc *core.Document, state core.DocumentState)
	// AddBuildStepListener registers a listener to be called after documents complete the
	// specified build steps. The states parameter is a bitmask, so multiple steps can be
	// selected with e.g. DocStateParsed | DocStateLinked.
	AddBuildStepListener(states core.DocumentState, listener BuildStepListener)
	// RemoveBuildStepListener unregisters a previously registered listener from all steps.
	RemoveBuildStepListener(listener BuildStepListener)
}

Builder is a service for applying build steps to workspace documents.

func NewDefaultBuilder

func NewDefaultBuilder(sc *service.Container) Builder

type DefaultBuilder

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

DefaultBuilder is the default implementation of Builder.

func (*DefaultBuilder) AddBuildStepListener

func (s *DefaultBuilder) AddBuildStepListener(states core.DocumentState, listener BuildStepListener)

func (*DefaultBuilder) Build

func (s *DefaultBuilder) Build(ctx context.Context, docs []*core.Document, downgrade func()) error

func (*DefaultBuilder) RemoveBuildStepListener

func (s *DefaultBuilder) RemoveBuildStepListener(listener BuildStepListener)

func (*DefaultBuilder) Reset

func (s *DefaultBuilder) Reset(doc *core.Document, state core.DocumentState)

type DefaultDocumentManager

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

DefaultDocumentManager is the default implementation of DocumentManager.

func (*DefaultDocumentManager) All

func (*DefaultDocumentManager) Clear

func (d *DefaultDocumentManager) Clear()

func (*DefaultDocumentManager) Delete

func (d *DefaultDocumentManager) Delete(uri core.URI) *core.Document

func (*DefaultDocumentManager) Get

func (*DefaultDocumentManager) Has

func (d *DefaultDocumentManager) Has(uri core.URI) bool

func (*DefaultDocumentManager) Set

func (d *DefaultDocumentManager) Set(document *core.Document)

type DefaultDocumentParser

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

DefaultDocumentParser is the default implementation of DocumentParser.

func (*DefaultDocumentParser) Parse

func (s *DefaultDocumentParser) Parse(doc *core.Document)

type DefaultDocumentUpdater

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

DefaultDocumentUpdater is the default implementation of DocumentUpdater.

func (*DefaultDocumentUpdater) Update

func (s *DefaultDocumentUpdater) Update(ctx context.Context, changed []textdoc.Handle, deleted []core.URI)

type DefaultDocumentValidator

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

DefaultDocumentValidator is the default implementation of DocumentValidator.

func (*DefaultDocumentValidator) Validate

func (s *DefaultDocumentValidator) Validate(ctx context.Context, doc *core.Document, level string) []*core.Diagnostic

type DefaultInitializer

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

DefaultInitializer is the default implementation of Initializer.

func (*DefaultInitializer) Initialize

func (s *DefaultInitializer) Initialize(ctx context.Context, folders []lsp.WorkspaceFolder) error

type DefaultLock

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

DefaultLock is the default implementation of WorkspaceLock.

The key property is atomic write-to-read downgrade: when downgrade is called, the caller atomically transitions from holding the exclusive write lock to holding a shared read lock, with no window in which a new writer could sneak in. This guarantees that phase 3 (validation) completes under a read lock before any subsequent write phase can begin.

Cancellation only cancels the context passed to do - every write that enters Write always calls do, even if its context was cancelled by a newer write. This ensures that document mutations inside do (e.g. applying text changes) are never silently dropped; the cancelled do simply skips expensive work by checking ctx.Err() before each phase.

func (*DefaultLock) Read

func (l *DefaultLock) Read(ctx context.Context, do func(ctx context.Context)) error

func (*DefaultLock) Write

func (l *DefaultLock) Write(ctx context.Context, do func(ctx context.Context, downgrade func()))

type DocumentManager

type DocumentManager interface {
	// Checks if a document with the given URI exists.
	Has(uri core.URI) bool
	// Retrieves the document for the given URI, or nil if it does not exist.
	Get(uri core.URI) *core.Document
	// Adds or updates the given document.
	Set(document *core.Document)
	// Returns a sequence of all managed documents.
	All() iter.Seq[*core.Document]
	// Deletes the document with the given URI and returns it, or nil if it did not exist.
	Delete(uri core.URI) *core.Document
	// Clears all documents from the manager.
	Clear()
}

DocumentManager holds all known documents of a workspace in memory. All methods of DocumentManager are thread-safe and can be called concurrently.

func NewDefaultDocumentManager

func NewDefaultDocumentManager(sc *service.Container) DocumentManager

type DocumentParser

type DocumentParser interface {
	// Parses the document and stores the resulting Tokens and AST node Root (incl. potential errors) into the document.
	// The caller must hold the document's write lock.
	Parse(doc *core.Document)
}

DocumentParser is a service for parsing documents.

func NewDefaultDocumentParser

func NewDefaultDocumentParser(sc *service.Container) DocumentParser

type DocumentUpdater

type DocumentUpdater interface {
	// Update processes document changes and triggers a new build.
	// Changed handles are used to create or update Documents in the DocumentManager.
	// Deleted URIs cause documents to be removed from the DocumentManager.
	// Any in-progress build is cancelled before starting a new one.
	Update(ctx context.Context, changed []textdoc.Handle, deleted []core.URI)
}

DocumentUpdater manages document updates and coordinates builds. It sits between the document synchronization layer and the Builder, handling write-locking for safe concurrent requests and cancellation of in-progress builds.

Thread Safety: All methods are safe for concurrent use.

func NewDefaultDocumentUpdater

func NewDefaultDocumentUpdater(sc *service.Container) DocumentUpdater

type DocumentValidator

type DocumentValidator interface {
	// Validate validates the given document by traversing all nodes and calling
	// any [core.Validator] implementations found on them.
	// The level parameter identifies when validation runs (e.g. "on-type", "on-save").
	// The accept callback is used to collect diagnostics.
	Validate(ctx context.Context, doc *core.Document, level string) []*core.Diagnostic
}

DocumentValidator validates a document's AST.

func NewDefaultDocumentValidator

func NewDefaultDocumentValidator(sc *service.Container) DocumentValidator

type FileExtensions

type FileExtensions []string

FileExtensions contains the file extensions to include, with leading dot (e.g. []string{".statemachine"}). It must be set by adopters.

type Initializer

type Initializer interface {
	// Initialize walks the given workspace folders, reads files matching the
	// configured extensions, and creates documents for them.
	Initialize(ctx context.Context, folders []lsp.WorkspaceFolder) error
}

Initializer initializes the documents of a workspace.

func NewDefaultInitializer

func NewDefaultInitializer(sc *service.Container) Initializer

type LanguageID

type LanguageID string

LanguageID is the identifier of the language managed by this workspace. It must be set by adopters and corresponds to the language ID used in the LSP protocol.

type Lock

type Lock interface {
	// Write cancels any pending or in-progress write, then acquires an exclusive
	// lock and calls do with a fresh context and a downgrade function. Calling
	// downgrade atomically transitions from the exclusive write lock to a shared
	// read lock, allowing reads to proceed while the caller's read phase continues.
	// downgrade is idempotent; a safety net ensures it is always called.
	Write(ctx context.Context, do func(ctx context.Context, downgrade func()))
	// Read acquires a shared lock, calls do, then releases the lock.
	// It blocks while a write is in progress or pending.
	// Returns ctx.Err() if the context is cancelled while waiting.
	Read(ctx context.Context, do func(ctx context.Context)) error
}

Lock controls read/write access to the workspace.

func NewDefaultLock

func NewDefaultLock() Lock

NewDefaultLock creates a new default workspace lock.

Jump to

Keyboard shortcuts

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