model

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: Apache-2.0 Imports: 33 Imported by: 0 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

Overview

Package model owns the workspace: the set of documents, the global symbol index, and the reindex pipeline that keeps them consistent.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoDocument = errors.New("workspace: no such document")

ErrNoDocument reports a name the workspace holds no document under.

View Source
var ErrNoView = errors.New("declares no view")

ErrNoView is a document that declares no view, which is rendered through a pseudo-view instead.

View Source
var ErrRecordMismatch = errors.New("workspace: content does not match its interface record")

ErrRecordMismatch reports content offered with an interface record that was written from other bytes: its diagnostics and spans would not be the content's.

View Source
var ErrRecordStale = errors.New("workspace: the interface record was written among other documents")

ErrRecordStale reports an interface record installed among documents other than the ones its analysis read: its diagnostics and evaluated facts would not follow from them, so the document was parsed instead and is held loaded.

View Source
var ErrRecorded = errors.New("workspace: the document is held as its interface record")

ErrRecorded reports a document held as its interface record where its tree is asked for: the workspace does not keep the record it was installed from.

View Source
var ErrWorkers = errors.New("workspace: the worker count must be a positive integer")

ErrWorkers is the error for a worker count below one.

Functions

func DeclaredDocumentDefinitions

func DeclaredDocumentDefinitions(index *symbols.Index, sem *semantics.Model, scope *symbols.Scope) []*symbols.Symbol

DeclaredDocumentDefinitions returns the document definitions declared in scope and its nested scopes, outermost first and in declaration order.

func DeclaredViews

func DeclaredViews(scope *symbols.Scope) []*symbols.Symbol

DeclaredViews returns the views declared in scope and its nested scopes, outermost first and in declaration order.

func DefaultWorkers added in v0.9.2

func DefaultWorkers() int

DefaultWorkers is the worker count a workspace starts with: one per CPU the process may run on.

func DocumentNames added in v0.9.2

func DocumentNames(index *symbols.Index, sem *semantics.Model) []string

DocumentNames is the qualified name of every document definition the workspace documents declare, in name order.

func IsModelSource

func IsModelSource(path string) bool

IsModelSource reports whether path is a SysML/KerML source file.

func NewIndexWithStdlib

func NewIndexWithStdlib() (*symbols.Index, libs.Source)

NewIndexWithStdlib returns an index carrying the standard library for a consumer that resolves library names outside a workspace — the REPL's runtime, which has to resolve the measurement unit a quantity expression names. It shares the one library index every model reads, and hands out the source holding the bytes that index was built from.

func ParallelFor added in v0.9.2

func ParallelFor(workers, n int, fn func(i int))

ParallelFor runs fn(i) for every i below n on up to workers goroutines, and returns once every call has; it is how a batch spreads its documents.

func SiblingDocumentPlans

func SiblingDocumentPlans(index *symbols.Index, sem *semantics.Model, resolver *resolve.Resolver, entry *symbols.Symbol) []*docplan.Plan

SiblingDocumentPlans compiles the document definitions the workspace documents declare other than entry, skipping any whose plan does not compile, so a single-document render can emit the anchors incoming cross-document references expect.

func TopLevelDeclarations

func TopLevelDeclarations(root *symbols.Scope) []*symbols.Symbol

TopLevelDeclarations returns root declarations, expanding packages one level.

Types

type CallSignature added in v0.10.0

type CallSignature struct {
	Callee *symbols.Symbol
	Params []semantics.SignatureParameter
	// Result is the declared type of the result parameter, nil when it has none.
	Result *symbols.Symbol
	// Selected marks the overload the arguments select, as opposed to one of
	// several the call may still be read as.
	Selected bool
}

CallSignature is one declaration a call may invoke: the parameters its argument list binds, in signature order, and the type of its result.

type Debouncer

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

Debouncer coalesces bursts of triggers per key into a single delayed call.

func NewDebouncer

func NewDebouncer(window time.Duration) *Debouncer

NewDebouncer returns a debouncer with the given coalescing window.

func (*Debouncer) Trigger

func (d *Debouncer) Trigger(key string, fn func())

Trigger (re)starts key's timer; fn runs once when the window elapses with no further trigger for that key. A trigger within the window resets the timer.

type Dependency

type Dependency struct {
	Doc  string
	FQN  string
	Text string
}

Dependency is a declaration a behavior's run reads, in a document the workspace holds: named by document and qualified name, with its text.

func (Dependency) Name

func (dep Dependency) Name() string

Name is what a message calls the dependency: its qualified name, or its document when it is one.

type Detached added in v0.10.0

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

Detached is the workspace's documents as they stood when it was taken, on an index of its own that later edits do not touch: what a runtime is built over.

func (*Detached) DeclarationOf added in v0.10.0

func (d *Detached) DeclarationOf(sym *symbols.Symbol) (Dependency, bool)

DeclarationOf is the dependency sym is listed as: the nearest declaration its document names around it; false when the detached model does not hold its document or names nothing around it.

func (*Detached) Declared added in v0.10.0

func (d *Detached) Declared(doc, fqn string) *symbols.Symbol

Declared is the element fqn names in doc as the detached model's own index has it, by qualified name or among the document's declarations; build executors from it.

func (*Detached) Dependencies added in v0.10.0

func (d *Detached) Dependencies(roots ...*symbols.Symbol) []Dependency

Dependencies lists the declarations a run from roots reads: the roots, what their text names, what that names in turn — in the detached model's documents alone, as no edit reaches a library — sorted by document then name, each listed as the nearest declaration its document names (see dependencyWalk.declaration).

func (*Detached) Documents added in v0.10.0

func (d *Detached) Documents() []string

Documents are the sorted names of the held documents and must not be modified.

func (*Detached) FQN added in v0.10.0

func (d *Detached) FQN(sym *symbols.Symbol) string

FQN spells sym's fully qualified name as the detached model's index holds it.

func (*Detached) Generation added in v0.10.0

func (d *Detached) Generation() uint64

Generation is the workspace's generation the detached model was built from; the workspace still holds the same documents while Workspace.Generation equals it.

func (*Detached) Index added in v0.10.0

func (d *Detached) Index() *symbols.Index

Index is the detached model's index.

func (*Detached) Named added in v0.10.0

func (d *Detached) Named(doc, fqn string) (*symbols.Symbol, error)

Named is the element fqn names from doc: doc's own, else the one another held document declares by qualified name; an error names the documents when several do.

func (*Detached) Referenced added in v0.10.0

func (d *Detached) Referenced(scope *symbols.Scope, expr ast.Node) []*symbols.Symbol

Referenced is the symbols expr's names reach when resolved in scope, as the detached model's index has them.

func (*Detached) Resolver added in v0.10.0

func (d *Detached) Resolver() *resolve.Resolver

Resolver is the resolver over the detached model's index.

func (*Detached) Semantics added in v0.10.0

func (d *Detached) Semantics() *semantics.Model

Semantics is the typed semantic model over the detached model's index.

func (*Detached) Source added in v0.10.0

func (d *Detached) Source(doc string) *source.SourceFile

Source is the held source file for doc, or nil when doc is not held.

func (*Detached) Version added in v0.10.0

func (d *Detached) Version(doc string) (int, bool)

Version is the version of the named document the detached model was built from, and false for a document it does not hold.

type Document

type Document struct {
	Name             string
	Content          []byte
	Version          int
	AST              *ast.RootNamespace
	ParseDiagnostics []parser.Diagnostic
	ParseWarnings    []parser.Diagnostic
	Scope            *symbols.Scope
	// contains filtered or unexported fields
}

Document is the parsed state of one source file. It is immutable once built: it is parsed from bytes the workspace owns, newDocument sets every field and nothing writes one afterwards, so a document the workspace hands out is a snapshot that neither a later update nor whoever supplied the bytes can touch.

func (*Document) Digest

func (d *Document) Digest() string

Digest fingerprints the document's text: equal for equal content, so a position read from one snapshot can be checked against a later one.

func (*Document) Kind added in v0.10.0

func (d *Document) Kind() source.Kind

Kind reports the document's source kind, inferred from its name when none is stored.

func (*Document) Lines

func (d *Document) Lines() *source.LineIndex

Lines returns the document's line index, built once and cached.

func (*Document) Recorded added in v0.9.2

func (d *Document) Recorded() bool

Recorded reports whether the document is held as its interface record: its scope tree carries facts in place of declarations, so AST is nil while Content, Digest and Lines are the text's.

func (*Document) TopMembers added in v0.9.2

func (d *Document) TopMembers() []libs.TopMember

TopMembers reports the document's top-level members as written, from its tree when loaded and from its record when recorded.

type DocumentDefinition

type DocumentDefinition struct {
	FQN      string
	Notation string
	Doc      string
	Line     int
}

DocumentDefinition is one native document definition the workspace holds: a part def specializing DocumentQueries::Document, and the file declaring it. Notation is the qualified name as the notation writes it, and Line the 1-based line the declaration starts on.

type DocumentEdit

type DocumentEdit struct {
	Name     string
	Original []byte
	Content  []byte
	Applied  []edit.Applied
	Version  int
	Open     bool
}

DocumentEdit is one document's rewrite: the content it was computed from, what it becomes, and what each operation changed in it. Version is the one the workspace held the content at; Open reports whether that is a client buffer's version, or 0 for content read from disk.

type EditResult

type EditResult struct {
	Documents []DocumentEdit
}

EditResult is what ApplyEdit computed: the edited document first, then every other document the edit rewrote or read a target's declaration in, in name order. A document read and left as it was has its content as its rewrite.

type FeatureHint added in v0.10.0

type FeatureHint struct {
	Symbol *symbols.Symbol
	// Type is the inferred type: that of the value, else the type the features
	// it redefines or subsets give it. Nil for a feature that declares its type.
	Type *symbols.Symbol
	// Value is the constant the feature's value evaluates to, when HasValue.
	Value    semantics.Value
	HasValue bool
}

FeatureHint is what an editor may show beside a feature declaration: the type a feature declared without one is inferred to have, and the constant its value evaluates to from the model alone. Either may be absent.

type Input added in v0.9.2

type Input struct {
	Name      string
	Content   []byte
	Version   int
	Kind      source.Kind
	Transient bool
}

Input is one document a batch opens: the name it is indexed under, its text and its version. Kind is optional; when unknown the name determines it. A Transient input is a buffer no file holds, the REPL's transcript: it is never read from or written to the record cache.

type Option

type Option func(*Workspace)

Option configures a workspace at construction.

func WithConformanceMode

func WithConformanceMode(mode diag.ConformanceMode) Option

WithConformanceMode analyzes this workspace's documents at mode.

func WithDisabledLints added in v0.9.2

func WithDisabledLints(codes ...string) Option

WithDisabledLints leaves the lints with these codes (see passes.LintCodes) out of this workspace's diagnostics.

func WithEnabledLints added in v0.10.0

func WithEnabledLints(codes ...string) Option

WithEnabledLints keeps the opt-in lints with these codes (see passes.IsOptInLint) in this workspace's diagnostics; a disabled lint stays out.

func WithLibrarySource

func WithLibrarySource(src libs.Source) Option

WithLibrarySource names the source the index's library documents were read from, so LibraryDocument can serve their text. It must serve the bytes the index was built from, or the index's spans address the wrong text.

func WithRecordCache added in v0.9.2

func WithRecordCache(cache *libs.Cache) Option

WithRecordCache has the workspace hold closed documents as the interface records cache holds for their content, and write the records of the documents it analyzes to it. Records are filed under the identity of the library the index holds (Index.LibraryIdentity); without a cache, or over an index whose library identity is unknown, every document is held loaded.

type QueryTypeCandidate

type QueryTypeCandidate struct {
	Name string
	Sym  *symbols.Symbol
}

QueryTypeCandidate pairs a visible spelling with the element it reaches, so an alias completes under the name it is reachable by, not its target's.

type Reading

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

Reading answers questions of the workspace's documents as they all stand at one moment: it lives for one call of Workspace.Read, under the lock.

func (*Reading) DeclarationText

func (r *Reading) DeclarationText(sym *symbols.Symbol) string

DeclarationText is the source text of sym's declaration, "" when its document is gone.

func (*Reading) Declared

func (r *Reading) Declared(doc, fqn string) *symbols.Symbol

Declared is the element fqn names in doc: by qualified name in the index, else by qualified or simple name among the document's own declarations.

func (*Reading) DeclaredView

func (r *Reading) DeclaredView(doc, fqn string) *symbols.Symbol

DeclaredView is the view RenderView renders for fqn in doc: the view named, the document's one view for "", nil for a pseudo-view or a name declaring none.

func (*Reading) Dependencies

func (r *Reading) Dependencies(roots ...*symbols.Symbol) []Dependency

Dependencies is Detached.Dependencies over the documents as read.

func (*Reading) Detach added in v0.10.0

func (r *Reading) Detach() (*Detached, error)

Detach is Workspace.Detach over the documents as read.

func (*Reading) Diagnostics added in v0.11.0

func (r *Reading) Diagnostics(name string) []diag.Diagnostic

Diagnostics is the held document's analysis diagnostics, of the text the reading holds, lints filtered as the workspace is configured.

func (*Reading) Document

func (r *Reading) Document(name string) *Document

Document is the held document name, nil for one the workspace does not hold.

func (*Reading) Generation

func (r *Reading) Generation() uint64

Generation is the workspace's generation as read.

func (*Reading) Index added in v0.10.0

func (r *Reading) Index() *symbols.Index

Index is the workspace's index as read.

func (*Reading) LineIndex added in v0.10.0

func (r *Reading) LineIndex(name string) *source.LineIndex

LineIndex is the held document's line index, nil when the workspace does not hold it.

func (*Reading) LineIndexes added in v0.10.0

func (r *Reading) LineIndexes() map[string]*source.LineIndex

LineIndexes snapshots the line indexes of the held documents.

func (*Reading) LinkSites added in v0.10.0

func (r *Reading) LinkSites(rendering *view.Rendering, snapshot *Snapshot)

LinkSites is RenderViewLinked's source sites for a rendering made by this reading, frozen into its snapshot.

func (*Reading) Query added in v0.10.0

func (r *Reading) Query(doc string, fn func(*resolve.Resolver, *semantics.Model))

Query runs fn with the shared semantics, as a query of doc reads them.

func (*Reading) RelatedElements added in v0.11.0

func (r *Reading) RelatedElements(doc, fqn string) (*symbols.Symbol, []view.RelatedGroup, error)

RelatedElements groups the model's own elements related to the element fqn names from doc by the relationships a rendering draws edges for, with the element itself; nil when no held document declares it, an error when several do.

func (*Reading) RenderOverlaidView added in v0.10.0

func (r *Reading) RenderOverlaidView(doc, fqn string, overlay view.Overlay, verdicts view.Verdicts, depth int, include []string) (*view.Rendering, *Snapshot, error)

RenderOverlaidView is RenderView with overlay drawn over the rendering, its verdicts answered by verdicts, bounded by depth levels below each exposed element when depth is above 0, and drawing the elements include names by qualified name besides the view's own content.

func (*Reading) RenderView

func (r *Reading) RenderView(doc, fqn string) (*view.Rendering, *Snapshot, error)

RenderView is Workspace.RenderView of the documents as read.

func (*Reading) SourceText added in v0.10.0

func (r *Reading) SourceText() view.SourceText

SourceText is the text of the documents and the library files behind them.

func (*Reading) TextAt

func (r *Reading) TextAt(doc string, span source.Span) string

TextAt is the source text at span in doc, from the document or the library file behind the documents; "" when neither holds doc.

type ReferenceLocation

type ReferenceLocation struct {
	Doc     string
	Content []byte
	Span    source.Span
}

ReferenceLocation is one written name segment in a workspace document, with the document text its span addresses (the bytes the index was built from).

type Snapshot

type Snapshot struct {
	// Rendered is the document the rendering was asked of.
	Rendered *Document
	// contains filtered or unexported fields
}

Snapshot is the workspace's documents as one read of them, the read a rendering was made under, so that a span the rendering locates in any of them is a span of the text held here, whatever the workspace holds since.

func (*Snapshot) Document

func (s *Snapshot) Document(name string) *Document

Document is the named document as the snapshot holds it; nil for a name the workspace held no document of, a bundled library file's included.

func (*Snapshot) Sites added in v0.10.0

func (s *Snapshot) Sites() view.Sites

Sites returns the source locations for the rendering's origins.

type StaleError

type StaleError struct {
	Name string
}

StaleError reports that a document an operation was computed against has been replaced since, so a position in it may name something else now.

func (*StaleError) Error

func (e *StaleError) Error() string

type ViewInfo

type ViewInfo struct {
	Name      string
	Notation  string
	Kind      view.Kind
	Supported bool
	Reason    string
	Origin    view.Origin
	Doc       string
	Line      int
}

ViewInfo is one view a document declares: its qualified name, the rendering kind it states, whether this implementation produces that kind, and why not when it does not. Origin is where the view is declared, so a client can tell which view a cursor is in; the zero Origin for a view without a declaration. Doc is the declaring document, Line the 1-based line the declaration starts on, and Notation the qualified name as the notation writes it.

type VisibleName

type VisibleName struct {
	// Name is the path in the pilot's notation, segments joined by ".".
	Name string
	// FQN is the "::"-qualified name of the element the path reaches.
	FQN string
	// Kind classifies the element, an alias resolved to its target: a caller
	// restricting the set by metatype — a specialization names a type, a
	// redefinition names a feature — needs what the name reaches, not the name.
	Kind symbols.SymbolKind
	// Depth is the number of segments in Name.
	Depth int
}

VisibleName is one spelling resolution would consider at a point: the dotted path a reference there may be written as, and the element it reaches.

type VisibleNamesOptions

type VisibleNamesOptions struct {
	// Redefinition enumerates only what the anchor's owner inherits: a
	// redefinition's target is resolved against the generals of the owning type
	// rather than against its own members (KerML 8.3.3.3.6).
	Redefinition bool
	// LibraryRoots names the standard-library root packages the caller counts
	// as loaded: `Base` alone admits the implicit `self` and `that` it
	// contributes to a declaration. A library element is reachable through
	// inheritance and imports only when its root is named here, and a library
	// root package is never offered as a top-level name of its own.
	LibraryRoots []string
	// MaxDepth bounds the number of segments in an enumerated path.
	MaxDepth int
}

VisibleNamesOptions bounds a visible-name enumeration.

type Workspace

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

Workspace is the single source of truth for a server/REPL session: the document set plus the global symbol index. Mutations are serialized under a write lock; reads take a read lock.

func NewWorkspace

func NewWorkspace(opts ...Option) *Workspace

NewWorkspace returns a workspace with stdlib pre-loaded into the global index. Stdlib files are loaded from embedded sources (or OPENSYSML_LIBRARY_PATH if set). Without options it analyzes in the default conformance mode.

func NewWorkspaceWithIndex

func NewWorkspaceWithIndex(idx *symbols.Index, opts ...Option) *Workspace

NewWorkspaceWithIndex returns a workspace over a caller-built index, for a consumer whose resource set is not the bundled standard library. The options travel with the resource set, so any index is analyzed under the asked mode. The library files the index holds are the workspace's library, whatever their tier: a workspace document may stand in for one or take its name.

func (*Workspace) AllViews added in v0.10.0

func (w *Workspace) AllViews() []ViewInfo

AllViews lists the views declared across the workspace's own documents, in qualified-name order, as Views lists each document's; a library's views are not among them.

func (*Workspace) AmbiguousInvocationInDoc

func (w *Workspace) AmbiguousInvocationInDoc(name string, ref resolve.Reference) []*symbols.Symbol

AmbiguousInvocationInDoc returns the equally specific overloads an invocation's arguments leave tied, when ref is the name it calls; nil for any other reference and for a call that selects one declaration.

func (*Workspace) AnalysisStamp added in v0.10.0

func (w *Workspace) AnalysisStamp(name string) uint64

AnalysisStamp numbers name's current analysis: it changes exactly when the document is analyzed afresh, which happens only after an edit dropped what the previous analysis read (the document's own text, a name it resolved, a gather it took part in). Two reads of one stamp therefore saw one analysis, over the same inputs. Zero for a document not analyzed since it was opened or last changed.

func (*Workspace) AnalyzedContent

func (w *Workspace) AnalyzedContent(name string) ([]byte, []diag.Diagnostic, bool)

AnalyzedContent returns a document's diagnostics together with the content they were computed against, so an edit cannot split the two. Reports whether the document exists.

func (*Workspace) ApplyEdit

func (w *Workspace) ApplyEdit(name string, ops []edit.Operation, read []*Document) (result *EditResult, version int, ok bool, err error)

ApplyEdit rewrites the named document's current content by ops and returns the result without changing the workspace: the client owns the buffers, so it applies the text and the changes arrive back through the usual document notifications. A rename or a cascading delete also rewrites every other document of the workspace that refers to the target, open or read from disk; every document is read under the one lock, so the edit is computed from a single coherent state and each rewrite reports the version it was read at. Read are the workspace documents, as handed out earlier, that the operations' positions were computed from; when the workspace no longer holds one of those snapshots, the edit is refused with a *StaleError, and otherwise each is among the result's documents, rewritten or not, at the version it was read at, so that the client can pin the edit to it. The returned version is the named document's. An unknown document reports ok false; a refused edit is an *edit.Error and rewrites nothing.

func (*Workspace) CallSignaturesInDoc added in v0.10.0

func (w *Workspace) CallSignaturesInDoc(name string, ref resolve.Reference) []CallSignature

CallSignaturesInDoc lists the declarations the call whose name ref is may invoke: the overload its arguments select, else the overloads they leave tied, else whatever the name alone resolves to. Nil for a reference that names no call.

func (*Workspace) Close

func (w *Workspace) Close(name string)

Close drops the open buffer for name; the document reverts to on-disk content if any, otherwise it is removed. A document whose buffer holds what the file does is demoted to its interface record where one is to be had (see demoteLocked), releasing its tree.

func (*Workspace) ConformanceMode

func (w *Workspace) ConformanceMode() diag.ConformanceMode

ConformanceMode reports the strictness this workspace judges notation at.

func (*Workspace) DeleteOnDisk

func (w *Workspace) DeleteOnDisk(name string)

DeleteOnDisk forgets the on-disk bytes recorded for name. An open document keeps its authoritative buffer; a closed one leaves the document set.

func (*Workspace) Detach added in v0.10.0

func (w *Workspace) Detach() (*Detached, error)

Detach takes the workspace's current documents on an index of their own.

func (*Workspace) Diagnostics

func (w *Workspace) Diagnostics(name string) []diag.Diagnostic

Diagnostics returns the analysis diagnostics for name, computing them lazily (and caching) on first request after a change. Returns nil for unknown docs.

func (*Workspace) DiagnosticsAll added in v0.9.2

func (w *Workspace) DiagnosticsAll(names []string) [][]diag.Diagnostic

DiagnosticsAll returns the named documents' diagnostics in the order named (nil for an unknown name), analyzing the uncached ones on the workers, then caching. The workers share one gather of the workspace-wide audits, made on first use. Pending regathers settle first, so no cached entry they would drop is served.

func (*Workspace) DisabledLints added in v0.9.2

func (w *Workspace) DisabledLints() []string

DisabledLints reports the codes of the lints this workspace leaves out of its diagnostics, sorted.

func (*Workspace) Document

func (w *Workspace) Document(name string) *Document

Document returns the current parsed document for name, or nil. The document is a snapshot: an update installs a new one, so it stays consistent after the lock.

func (*Workspace) DocumentDefinitions

func (w *Workspace) DocumentDefinitions() []DocumentDefinition

DocumentDefinitions lists the document definitions declared across the workspace's own documents, in qualified-name order.

func (*Workspace) DocumentNames

func (w *Workspace) DocumentNames() []string

DocumentNames returns a snapshot of the names of all known documents.

func (*Workspace) ElementOnPath

func (w *Workspace) ElementOnPath(scope *symbols.Scope, path []string) (*symbols.Symbol, bool)

ElementOnPath resolves a dotted path from a scope to the element it names: the first segment as an unqualified name, each later one as a member of the previous, an alias replaced by its target.

func (*Workspace) EnabledLints added in v0.10.0

func (w *Workspace) EnabledLints() []string

EnabledLints reports the codes of the opt-in lints this workspace keeps in its diagnostics, sorted.

func (*Workspace) EnclosingMetadataBody

func (w *Workspace) EnclosingMetadataBody(scope *symbols.Scope) *symbols.Scope

EnclosingMetadataBody returns the nearest scope, from scope outward, whose declarations redefine the features of a metadata type; nil outside one.

func (*Workspace) FQNOf

func (w *Workspace) FQNOf(sym *symbols.Symbol) string

FQNOf is the qualified name the index registers an element under, which is how a caller comparing enumerations tells two paths to one element apart.

func (*Workspace) FeatureHintsInDoc added in v0.10.0

func (w *Workspace) FeatureHintsInDoc(name string, syms []*symbols.Symbol) []FeatureHint

FeatureHintsInDoc computes the hints for syms, usages declared in the named document, in one pass over the workspace's semantics. A value that is a literal gets no value hint: it already states what it is.

func (*Workspace) Generation

func (w *Workspace) Generation() uint64

Generation counts the changes made to the workspace's documents so far; two readings with the same generation read the same documents.

func (*Workspace) HighlightTokens

func (w *Workspace) HighlightTokens(name string) ([]byte, []semtok.Token)

HighlightTokens returns the semantic tokens of a document, ordered by source position, with the content they index; the workspace or bundled library document is chosen under one lock, so neither an edit nor a close can split or lose them. Nil for unknown documents.

func (*Workspace) Hydrate added in v0.9.2

func (w *Workspace) Hydrate(name string) error

Hydrate parses the named recorded document and holds it loaded: its record symbols are replaced by tree-backed ones, and its dependents are invalidated as by an edit. A loaded document is left as it is; ErrNoDocument names one the workspace does not hold.

func (*Workspace) HydrateAll added in v0.9.2

func (w *Workspace) HydrateAll()

HydrateAll hydrates every document held as its record, for a consumer that reads the trees of them all; dependents are invalidated as by an edit.

func (*Workspace) IdentityOf

func (w *Workspace) IdentityOf(name string, sym *symbols.Symbol) (*identity.Info, bool)

IdentityOf returns the identity side-table entry of a declaration of the named document, a bundled library file included; ok is false when it has no qualified name or is not indexed there.

func (*Workspace) InterfaceRecord added in v0.9.2

func (w *Workspace) InterfaceRecord(name string) (*libs.InterfaceRecord, error)

InterfaceRecord writes the interface record of the named loaded document from the analysis of it this workspace holds, analyzing it first if it has not been (see libs.WriteInterface). A document that stands in for a library file is not recordable: what it stands in for is read from its tree. A document already held as its record reports ErrRecorded: its record is in the cache it was read from. The relationships the workspace-wide audits gather from the body ride along by reference (see passes.GatherRelationships), and so does where the analysis got its answers (see libs.Provenance).

func (*Workspace) IsDocumentDefinition

func (w *Workspace) IsDocumentDefinition(sym *symbols.Symbol) bool

IsDocumentDefinition reports whether sym is a native document definition: a part def specializing DocumentQueries::Document.

func (*Workspace) IsLibraryDocument

func (w *Workspace) IsLibraryDocument(name string) bool

IsLibraryDocument reports whether name is a bundled library file, as opposed to a document of the workspace's own — a version of a library file included, whatever its mark in the index.

func (*Workspace) IsLibraryRoot

func (w *Workspace) IsLibraryRoot(name string) bool

IsLibraryRoot reports whether name is a top-level package of the workspace's library.

func (*Workspace) IsOpen

func (w *Workspace) IsOpen(name string) bool

IsOpen reports whether name has an authoritative open buffer.

func (*Workspace) LibraryDocument

func (w *Workspace) LibraryDocument(name string) *Document

LibraryDocument returns the parsed text of the named bundled library file, read from the source the index was built from, so its spans are the ones the index's symbols carry. It is nil for a name that is no library document and when the workspace has no library source. Library documents are read-only: they are never added to the index, which holds them already.

func (*Workspace) LibraryNames added in v0.11.0

func (w *Workspace) LibraryNames() []string

LibraryNames returns the relative paths of the bundled library files the workspace can serve through LibraryDocument, sorted; nil without a source.

func (*Workspace) LookupQualified

func (w *Workspace) LookupQualified(fqn string) []*symbols.Symbol

LookupQualified resolves a fully-qualified name against the global index under the read lock and returns a copy of the matching symbols, so callers never touch the shared index concurrently with a reindex. This is the safe read path for consumers (LSP/REPL); the raw index is intentionally not exposed.

func (*Workspace) MembersOnPath

func (w *Workspace) MembersOnPath(scope *symbols.Scope, path []string) []*symbols.Symbol

MembersOnPath returns the members visible on the element that path names from scope — the members of a usage's type included, since typing is a generalization edge — so that completion after `v.` offers what `v` has. Segments after the first are looked up as members of the previous one; an unresolved segment yields no members.

func (*Workspace) MetadataBodyMembers

func (w *Workspace) MetadataBodyMembers(scope *symbols.Scope) []*symbols.Symbol

MetadataBodyMembers returns the members of the metadata definition an annotation body's declarations redefine, as seen from the body scope, or nil when scope is not a metadata annotation body or its metaclass does not resolve.

func (*Workspace) MetadataBodyRedefines

func (w *Workspace) MetadataBodyRedefines(sym *symbols.Symbol) (*symbols.Symbol, string, bool)

MetadataBodyRedefines returns the metadata-definition feature a metadata annotation body declaration implicitly redefines (KerML 7.4.7), with the feature's qualified name. ok is false when sym is not such a declaration or the annotation's metaclass does not resolve.

func (*Workspace) NameReferencesTo

func (w *Workspace) NameReferencesTo(target *symbols.Symbol, name string) ([]ReferenceLocation, error)

NameReferencesTo returns every segment in the workspace's documents that writes name as target's own name — what renaming that name edits. A segment spelling target's other name (short for long, or the reverse) still resolves after the rename and is left alone; an alias use is edited via the alias. A recorded document is hydrated first, as for ReferencesTo.

func (*Workspace) OnDisk added in v0.11.0

func (w *Workspace) OnDisk(name string) ([]byte, bool)

OnDisk returns a copy of the bytes last recorded as name's file on disk, and whether any were.

func (*Workspace) Open

func (w *Workspace) Open(name string, content []byte, version int)

Open registers an authoritative open buffer for name and reindexes it. A buffer holding the text of a document already parsed, as the editor opens a file the folder scan indexed, is only marked open: the index is as it would be.

func (*Workspace) OpenAll added in v0.9.2

func (w *Workspace) OpenAll(inputs []Input)

OpenAll opens the inputs as one batch: parsed on the workers, added to the index in order, wildcard imports expanded once. Same result as opening them one by one as the batch starts: a document changed by another caller meanwhile keeps that change.

Over a record cache, an input whose content the cache holds a record for is held as that record, a closed file, where the record's provenance holds among the documents opened (see libs.Provenance); the others, and the records that do not hold, are parsed.

func (*Workspace) OpenNames

func (w *Workspace) OpenNames() []string

OpenNames returns a snapshot of the names with an open buffer.

func (*Workspace) OpenRecorded added in v0.9.2

func (w *Workspace) OpenRecorded(rec *libs.InterfaceRecord, content []byte) error

OpenRecorded installs a document from its interface record and the content the record was written from, in place of any document of its name: tree-less scopes and symbols carrying the record's facts, reporting the diagnostics stored with it against content, whose positions they hold. Content is checked against the record's digest, ErrRecordMismatch when it differs. Dependents are invalidated as by any replacement. A recorded document is a closed file: any open buffer of its name is dropped, and content is what the file holds on disk, so a later change to the file reindexes it. The workspace keeps what it built, not rec: a recorded document costs its text, scopes, symbols and diagnostics.

The record holds only among the documents its analysis read as they were (see libs.Provenance): where the workspace holds others, the document is parsed in the record's place, held loaded, and ErrRecordStale reported.

func (*Workspace) QueryBindingParameter

func (w *Workspace) QueryBindingParameter(sym *symbols.Symbol) (*symbols.Symbol, bool)

QueryBindingParameter resolves the parameter a document query binding names: for an `in` member of a calc usage typed by a query definition, the matching parameter declaration on that definition.

func (*Workspace) QueryDefinitions

func (w *Workspace) QueryDefinitions(syms []*symbols.Symbol) []*symbols.Symbol

QueryDefinitions filters syms to the query definitions among them: the calc defs specializing DocumentQueries::Query.

func (*Workspace) QueryTypeCandidates

func (w *Workspace) QueryTypeCandidates(scope *symbols.Scope) []QueryTypeCandidate

QueryTypeCandidates lists what a calc usage's type position may name: the query definitions reachable by a single name from scope — imports, aliases and inheritance included — and the namespaces a qualified name may start with.

func (*Workspace) QueryUsageParameters

func (w *Workspace) QueryUsageParameters(usage *symbols.Symbol) ([]*symbols.Symbol, bool)

QueryUsageParameters lists the `in` parameters of the query definition a calc usage is typed by; false when the usage is not typed by one.

func (*Workspace) Read

func (w *Workspace) Read(fn func(r *Reading) error) error

Read calls fn with a Reading under the write lock (its answers query the shared resolver), so all are of the same documents. fn must not call the workspace itself.

func (*Workspace) Recorded added in v0.9.2

func (w *Workspace) Recorded(name string) bool

Recorded reports whether the named document is held as its interface record.

func (*Workspace) ReferencesTo

func (w *Workspace) ReferencesTo(target *symbols.Symbol) ([]ReferenceLocation, error)

ReferencesTo returns every segment in the workspace's documents that reaches target or writes its name (an alias use counts for both), in document then position order. A document held as its interface record is hydrated first, since the references it writes are in its body, not its record.

func (*Workspace) Remove

func (w *Workspace) Remove(name string)

Remove deletes the document entirely (open buffer, on-disk cache, and index).

func (*Workspace) RenameConflict

func (w *Workspace) RenameConflict(target *symbols.Symbol, name, newName string) (*edit.RenameConflict, error)

RenameConflict reports why renaming target's name (long or short, as written) to newName is refused: the name already taken where target is declared, or a reference in any workspace document that would read another element afterwards. A recorded document is hydrated first, as for ReferencesTo.

func (*Workspace) RenderView

func (w *Workspace) RenderView(doc, fqn string) (*view.Rendering, *Snapshot, error)

RenderView renders a view of a document. fqn names a declared view or a pseudo-view (`#<kind>[:<fqn>]`); "" renders the document's own view. The snapshot returned holds the documents the rendering was made from, read under the same lock, so their versions, content and scopes are the rendering's.

func (*Workspace) RenderViewLinked added in v0.10.0

func (w *Workspace) RenderViewLinked(doc, fqn string) (*view.Rendering, *Snapshot, error)

RenderViewLinked renders a view and resolves its source sites under the workspace lock, so the returned snapshot can be used after the lock is released.

func (*Workspace) ResolveQualifiedInDoc

func (w *Workspace) ResolveQualifiedInDoc(name string, scope *symbols.Scope, qn *ast.QualifiedName) (*symbols.Symbol, bool)

ResolveQualifiedInDoc resolves a qualified name against the given scope using the workspace's symbol index. Used by the LSP layer for go-to-definition.

func (*Workspace) ResolveQualifiedSegmentsInDoc

func (w *Workspace) ResolveQualifiedSegmentsInDoc(name string, scope *symbols.Scope, qn *ast.QualifiedName) []*symbols.Symbol

ResolveQualifiedSegmentsInDoc resolves a qualified name and returns the symbol each of its segments denotes, so `A::B::C` yields the symbols for A, B and C. Entries are nil where a segment did not resolve. Used by rename, which must edit a name wherever it appears, qualifier positions included.

func (*Workspace) ResolveReferenceInDoc

func (w *Workspace) ResolveReferenceInDoc(name string, ref resolve.Reference) (*symbols.Symbol, bool)

ResolveReferenceInDoc resolves one name occurrence, which may be the target of a reference subsetting or a feature chain's member segment (see resolve.Reference).

func (*Workspace) ResolveReferenceNameSegmentsInDoc

func (w *Workspace) ResolveReferenceNameSegmentsInDoc(name string, ref resolve.Reference) []*symbols.Symbol

ResolveReferenceNameSegmentsInDoc is ResolveReferenceSegmentsInDoc reporting what each segment's name *is* rather than the element it reaches, so a segment written as an alias name is the alias. Rename edits names, not elements.

func (*Workspace) ResolveReferenceSegmentsInDoc

func (w *Workspace) ResolveReferenceSegmentsInDoc(name string, ref resolve.Reference) []*symbols.Symbol

ResolveReferenceSegmentsInDoc is ResolveQualifiedSegmentsInDoc for one name occurrence (see ResolveReferenceInDoc).

func (*Workspace) ScopeAt

func (w *Workspace) ScopeAt(doc string, offset int) *symbols.Scope

ScopeAt is the deepest scope of a document whose declaration contains offset, which is the namespace a name written there is resolved in.

func (*Workspace) SetConformanceMode

func (w *Workspace) SetConformanceMode(mode diag.ConformanceMode) error

SetConformanceMode switches the mode for a live session — an LSP client changing its setting, a REPL user asking the strict question — and drops the cached diagnostics, which answered the other question. A document held as its interface record stores the diagnostics of the mode it was recorded under and cannot answer another without its tree: while the workspace holds one, the mode stays and a symbols.NeedsHydration naming it is returned.

func (*Workspace) SetDisabledLints added in v0.9.2

func (w *Workspace) SetDisabledLints(codes []string) error

SetDisabledLints replaces the lints this workspace leaves out of its diagnostics with codes; none enables every lint. A code that names no lint is an error, and leaves the setting as it was. Nothing is re-analyzed: a lint is filtered from what analysis found, so a record answers either setting.

func (*Workspace) SetEnabledLints added in v0.10.0

func (w *Workspace) SetEnabledLints(codes []string) error

SetEnabledLints replaces the opt-in lints this workspace keeps in its diagnostics with codes; none leaves every opt-in lint out. A code that names no lint is an error, and leaves the setting as it was; one naming a lint on by default changes nothing, and a disabled lint stays out either way.

func (*Workspace) SetOnDisk

func (w *Workspace) SetOnDisk(name string, content []byte)

SetOnDisk records a copy of the bytes a file holds on disk. If the document is not open, it becomes the active content and the document is reindexed.

func (*Workspace) SetOnDiskAll added in v0.10.0

func (w *Workspace) SetOnDiskAll(inputs []Input)

SetOnDiskAll is SetOnDisk over the inputs as one batch: the files' content is recorded for them all, and those without an open buffer are parsed on the workers, added to the index in order and wildcard imports expanded once, as OpenAll does; an open buffer stays authoritative. Version is each file's document version, zero as SetOnDisk gives it.

func (*Workspace) SetRecordCache added in v0.9.2

func (w *Workspace) SetRecordCache(cache *libs.Cache)

SetRecordCache has the workspace hold closed documents as the interface records cache holds for their content from here on, and write the records of the documents it analyzes to it; nil holds every document loaded. The documents held are as they are: a recorded one stays recorded.

func (*Workspace) SetWorkers added in v0.9.2

func (w *Workspace) SetWorkers(n int) error

SetWorkers sets how many documents a batch parses and analyzes at once. The result of a batch is the same at any count; a count below one is an error.

func (*Workspace) ShortNameOf added in v0.10.1

func (w *Workspace) ShortNameOf(sym *symbols.Symbol) string

ShortNameOf is the short name sym is referable by: the declared one, or the one a feature declaring no name takes from its naming feature.

func (*Workspace) StandsIn added in v0.10.0

func (w *Workspace) StandsIn(name string) bool

StandsIn reports whether the workspace document name stands in for a bundled library file: a version of it, which the index marks with the file's tier.

func (*Workspace) StandsInFor

func (w *Workspace) StandsInFor(name string) string

StandsInFor is the bundled library document name is a version of and stands in for in the index, "" for the workspace's own file.

func (*Workspace) StateGraph added in v0.10.0

func (w *Workspace) StateGraph(sym *symbols.Symbol) (*lower.StateGraph, error)

StateGraph lowers the state machine sym declares through the workspace's shared resolver, so library-typed members the lowering reads — StateMachines metadata among them — resolve as the runtime's lowering resolves them.

func (*Workspace) TopLevelSymbols

func (w *Workspace) TopLevelSymbols(doc string) []*symbols.Symbol

TopLevelSymbols returns the symbols declared at the root of the index as seen from the document named doc: the standard library's top-level packages and every document's top-level declarations. This is the read path for completion, which offers library names that no open document declares.

func (*Workspace) UnfilteredDiagnostics added in v0.11.0

func (w *Workspace) UnfilteredDiagnostics(name string) []diag.Diagnostic

UnfilteredDiagnostics is Diagnostics with every lint finding kept, for a reader applying a lint selection of its own (passes.WithoutLints).

func (*Workspace) Update

func (w *Workspace) Update(name string, content []byte, version int)

Update replaces the open buffer content for name and reindexes.

func (*Workspace) Views

func (w *Workspace) Views(doc string) ([]ViewInfo, *Document)

Views lists the views a document declares, in qualified-name order, each with the rendering kind it states. A recognized kind this build does not produce is listed as unsupported with the reason. The document returned is the snapshot the listing was read from, so the origins are located in its text; nil when the workspace does not hold the document.

func (*Workspace) VisibleNames

func (w *Workspace) VisibleNames(scope *symbols.Scope, opts VisibleNamesOptions) []VisibleName

VisibleNames enumerates every name resolution would consider in scope: the members of the enclosing namespace chain, what those namespaces inherit and import, and the document roots the index holds, each under every path it can be reached by. It is the read-only enumeration behind the single-name lookup resolve performs, and it answers both halves of a visibility question — a name that should be reachable and is not, and one that is reachable and should not be. Results are sorted by name, so two runs agree byte for byte.

func (*Workspace) VisibleNamesAt

func (w *Workspace) VisibleNamesAt(doc string, offset int, opts VisibleNamesOptions) []VisibleName

VisibleNamesAt is VisibleNames for the deepest scope of a document that contains offset.

func (*Workspace) Workers added in v0.9.2

func (w *Workspace) Workers() int

Workers reports how many documents a batch parses and analyzes at once.

func (*Workspace) WriteRecord added in v0.9.2

func (w *Workspace) WriteRecord(name string) error

WriteRecord writes the named loaded document's interface record to the record cache, analyzing it first if it has not been: for a document just saved, so a later workspace holds it as its record. Without a cache, or for a recorded document, it does nothing; an unrecordable document is an error.

Jump to

Keyboard shortcuts

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