Documentation
¶
Overview ¶
Package model owns the workspace: the set of documents, the global symbol index, and the reindex pipeline that keeps them consistent.
Index ¶
- Variables
- func DeclaredViews(scope *symbols.Scope) []*symbols.Symbol
- func DefaultWorkers() int
- func IsModelSource(path string) bool
- func NewIndexWithStdlib() (*symbols.Index, libs.Source)
- func ParallelFor(workers, n int, fn func(i int))
- func TopLevelDeclarations(root *symbols.Scope) []*symbols.Symbol
- func UnifiedDiff(name string, old, updated []byte) string
- type CallSignature
- type Debouncer
- type Dependency
- type Detached
- func (d *Detached) DeclarationOf(sym *symbols.Symbol) (Dependency, bool)
- func (d *Detached) Declared(doc, fqn string) *symbols.Symbol
- func (d *Detached) Dependencies(roots ...*symbols.Symbol) []Dependency
- func (d *Detached) Documents() []string
- func (d *Detached) FQN(sym *symbols.Symbol) string
- func (d *Detached) Generation() uint64
- func (d *Detached) Index() *symbols.Index
- func (d *Detached) Named(doc, fqn string) (*symbols.Symbol, error)
- func (d *Detached) Referenced(scope *symbols.Scope, expr ast.Node) []*symbols.Symbol
- func (d *Detached) Resolver() *resolve.Resolver
- func (d *Detached) Semantics() *semantics.Model
- func (d *Detached) Source(doc string) *source.SourceFile
- func (d *Detached) Version(doc string) (int, bool)
- type Document
- type DocumentDefinition
- type DocumentEdit
- type EditResult
- type FeatureHint
- type Hunk
- type Input
- type Member
- type Option
- type QueryTypeCandidate
- type Reading
- func (r *Reading) DeclarationText(sym *symbols.Symbol) string
- func (r *Reading) Declared(doc, fqn string) *symbols.Symbol
- func (r *Reading) DeclaredView(doc, fqn string) *symbols.Symbol
- func (r *Reading) Dependencies(roots ...*symbols.Symbol) []Dependency
- func (r *Reading) Detach() (*Detached, error)
- func (r *Reading) Diagnostics(name string) []diag.Diagnostic
- func (r *Reading) Document(name string) *Document
- func (r *Reading) Documents() []*Document
- func (r *Reading) Generation() uint64
- func (r *Reading) Index() *symbols.Index
- func (r *Reading) LineIndex(name string) *source.LineIndex
- func (r *Reading) LineIndexes() map[string]*source.LineIndex
- func (r *Reading) LinkSites(rendering *view.Rendering, snapshot *Snapshot)
- func (r *Reading) Query(doc string, fn func(*resolve.Resolver, *semantics.Model))
- func (r *Reading) RelatedElements(doc, fqn string) (*symbols.Symbol, []view.RelatedGroup, error)
- func (r *Reading) RenderOverlaidView(doc, fqn string, overlay view.Overlay, verdicts view.Verdicts, depth int, ...) (*view.Rendering, *Snapshot, error)
- func (r *Reading) RenderView(doc, fqn string) (*view.Rendering, *Snapshot, error)
- func (r *Reading) SourceText() view.SourceText
- func (r *Reading) TextAt(doc string, span source.Span) string
- type ReferenceLocation
- type Snapshot
- type StaleError
- type ViewInfo
- type VisibleName
- type VisibleNamesOptions
- type Workspace
- func (w *Workspace) AllViews() []ViewInfo
- func (w *Workspace) AmbiguousInvocationInDoc(name string, ref resolve.Reference) []*symbols.Symbol
- func (w *Workspace) AnalysisStamp(name string) uint64
- func (w *Workspace) AnalyzedContent(name string) ([]byte, []diag.Diagnostic, bool)
- func (w *Workspace) ApplyEdit(name string, ops []edit.Operation, read []*Document) (result *EditResult, version int, ok bool, err error)
- func (w *Workspace) CallSignaturesInDoc(name string, ref resolve.Reference) []CallSignature
- func (w *Workspace) Close(name string)
- func (w *Workspace) ConformanceMode() diag.ConformanceMode
- func (w *Workspace) DeleteOnDisk(name string)
- func (w *Workspace) Detach() (*Detached, error)
- func (w *Workspace) Diagnostics(name string) []diag.Diagnostic
- func (w *Workspace) DiagnosticsAll(names []string) [][]diag.Diagnostic
- func (w *Workspace) DisabledLints() []string
- func (w *Workspace) Document(name string) *Document
- func (w *Workspace) DocumentDefinitions() []DocumentDefinition
- func (w *Workspace) DocumentNames() []string
- func (w *Workspace) DocumentationOf(sym *symbols.Symbol) []string
- func (w *Workspace) ElementOnPath(scope *symbols.Scope, path []string) (*symbols.Symbol, bool)
- func (w *Workspace) EnabledLints() []string
- func (w *Workspace) EnclosingMetadataBody(scope *symbols.Scope) *symbols.Scope
- func (w *Workspace) FQNOf(sym *symbols.Symbol) string
- func (w *Workspace) FeatureHintsInDoc(name string, syms []*symbols.Symbol) []FeatureHint
- func (w *Workspace) FindingsOn(name string) []checkws.Finding
- func (w *Workspace) Generation() uint64
- func (w *Workspace) HighlightTokens(name string) ([]byte, []semtok.Token)
- func (w *Workspace) Hydrate(name string) error
- func (w *Workspace) HydrateAll()
- func (w *Workspace) IdentityOf(name string, sym *symbols.Symbol) (*identity.Info, bool)
- func (w *Workspace) InheritedTypesOf(sym *symbols.Symbol) []*symbols.Symbol
- func (w *Workspace) InterfaceRecord(name string) (*libs.InterfaceRecord, error)
- func (w *Workspace) IsDocumentDefinition(sym *symbols.Symbol) bool
- func (w *Workspace) IsLibraryDocument(name string) bool
- func (w *Workspace) IsLibraryRoot(name string) bool
- func (w *Workspace) IsOpen(name string) bool
- func (w *Workspace) LibraryDocument(name string) *Document
- func (w *Workspace) LibraryNames() []string
- func (w *Workspace) LookupQualified(fqn string) []*symbols.Symbol
- func (w *Workspace) MemberSummaryOf(sym *symbols.Symbol, inherited bool) []Member
- func (w *Workspace) MembersOnPath(scope *symbols.Scope, path []string) []*symbols.Symbol
- func (w *Workspace) MetadataBodyMembers(scope *symbols.Scope) []*symbols.Symbol
- func (w *Workspace) MetadataBodyRedefines(sym *symbols.Symbol) (*symbols.Symbol, string, bool)
- func (w *Workspace) NameReferencesTo(target *symbols.Symbol, name string) ([]ReferenceLocation, error)
- func (w *Workspace) OnDisk(name string) ([]byte, bool)
- func (w *Workspace) Open(name string, content []byte, version int)
- func (w *Workspace) OpenAll(inputs []Input)
- func (w *Workspace) OpenNames() []string
- func (w *Workspace) OpenRecorded(rec *libs.InterfaceRecord, content []byte) error
- func (w *Workspace) OpenWithKind(name string, content []byte, version int, kind source.Kind)
- func (w *Workspace) QueryBindingParameter(sym *symbols.Symbol) (*symbols.Symbol, bool)
- func (w *Workspace) QueryDefinitions(syms []*symbols.Symbol) []*symbols.Symbol
- func (w *Workspace) QueryTypeCandidates(scope *symbols.Scope) []QueryTypeCandidate
- func (w *Workspace) QueryUsageParameters(usage *symbols.Symbol) ([]*symbols.Symbol, bool)
- func (w *Workspace) Read(fn func(r *Reading) error) error
- func (w *Workspace) Recorded(name string) bool
- func (w *Workspace) ReferencesTo(target *symbols.Symbol) ([]ReferenceLocation, error)
- func (w *Workspace) Remove(name string)
- func (w *Workspace) RenameConflict(target *symbols.Symbol, name, newName string) (*edit.RenameConflict, error)
- func (w *Workspace) RenderView(doc, fqn string) (*view.Rendering, *Snapshot, error)
- func (w *Workspace) RenderViewLinked(doc, fqn string) (*view.Rendering, *Snapshot, error)
- func (w *Workspace) ResolveQualifiedInDoc(name string, scope *symbols.Scope, qn *ast.QualifiedName) (*symbols.Symbol, bool)
- func (w *Workspace) ResolveQualifiedSegmentsInDoc(name string, scope *symbols.Scope, qn *ast.QualifiedName) []*symbols.Symbol
- func (w *Workspace) ResolveReferenceInDoc(name string, ref resolve.Reference) (*symbols.Symbol, bool)
- func (w *Workspace) ResolveReferenceNameSegmentsInDoc(name string, ref resolve.Reference) []*symbols.Symbol
- func (w *Workspace) ResolveReferenceSegmentsInDoc(name string, ref resolve.Reference) []*symbols.Symbol
- func (w *Workspace) ScopeAt(doc string, offset int) *symbols.Scope
- func (w *Workspace) SetConformanceMode(mode diag.ConformanceMode) error
- func (w *Workspace) SetDisabledLints(codes []string) error
- func (w *Workspace) SetEnabledLints(codes []string) error
- func (w *Workspace) SetOnDisk(name string, content []byte)
- func (w *Workspace) SetOnDiskAll(inputs []Input)
- func (w *Workspace) SetRecordCache(cache *libs.Cache)
- func (w *Workspace) SetWorkers(n int) error
- func (w *Workspace) ShortNameOf(sym *symbols.Symbol) string
- func (w *Workspace) StandsIn(name string) bool
- func (w *Workspace) StandsInFor(name string) string
- func (w *Workspace) StateGraph(sym *symbols.Symbol) (*lower.StateGraph, error)
- func (w *Workspace) TopLevelSymbols(doc string) []*symbols.Symbol
- func (w *Workspace) UnfilteredDiagnostics(name string) []diag.Diagnostic
- func (w *Workspace) Update(name string, content []byte, version int)
- func (w *Workspace) Views(doc string) ([]ViewInfo, *Document)
- func (w *Workspace) VisibleNames(scope *symbols.Scope, opts VisibleNamesOptions) []VisibleName
- func (w *Workspace) VisibleNamesAt(doc string, offset int, opts VisibleNamesOptions) []VisibleName
- func (w *Workspace) Workers() int
- func (w *Workspace) WorkspaceFindings() []checkws.Finding
- func (w *Workspace) WriteRecord(name string) error
Constants ¶
This section is empty.
Variables ¶
var ErrNoDocument = errors.New("workspace: no such document")
ErrNoDocument reports a name the workspace holds no document under.
var ErrNoView = errors.New("declares no view")
ErrNoView is a document that declares no view, which is rendered through a pseudo-view instead.
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.
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.
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.
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 DeclaredViews ¶
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 IsModelSource ¶
IsModelSource reports whether path is a SysML/KerML source file.
func NewIndexWithStdlib ¶
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
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 TopLevelDeclarations ¶
TopLevelDeclarations returns root declarations, expanding packages one level.
func UnifiedDiff ¶ added in v0.12.0
UnifiedDiff renders what turns old into updated as a unified diff of name, three lines of context around each Hunk; empty when nothing changed.
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 ¶
NewDebouncer returns a debouncer with the given coalescing window.
type Dependency ¶
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
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
Documents are the sorted names of the held documents and must not be modified.
func (*Detached) FQN ¶ added in v0.10.0
FQN spells sym's fully qualified name as the detached model's index holds it.
func (*Detached) Generation ¶ added in v0.10.0
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) Named ¶ added in v0.10.0
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
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
Resolver is the resolver over the detached model's index.
func (*Detached) Semantics ¶ added in v0.10.0
Semantics is the typed semantic model over the detached model's index.
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 ¶
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
Kind reports the document's source kind, inferred from its name when none is stored.
func (*Document) Recorded ¶ added in v0.9.2
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) SourceFile ¶ added in v0.12.0
func (d *Document) SourceFile() *source.SourceFile
Lines returns the document's line index, built once and cached. SourceFile is the document's text as the parser read it.
func (*Document) TopMembers ¶ added in v0.9.2
TopMembers reports the document's top-level members as written, from its tree when loaded and from its record when recorded.
type DocumentDefinition ¶
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
// Types is what types a feature written without a typing: nil when it writes one.
Types []*symbols.Symbol
// FromValue marks Types as read off the value; otherwise they are the feature's
// own, inherited from what it redefines, subsets or references.
FromValue bool
// 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 types of a feature that writes none, and the constant its value evaluates to.
type Hunk ¶ added in v0.12.0
Hunk is a run of lines a diff rewrites: old[OldStart:OldEnd] becomes new[NewStart:NewEnd]. A pure insertion has OldStart == OldEnd, a pure deletion NewStart == NewEnd.
type Input ¶ added in v0.9.2
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 Member ¶ added in v0.13.0
type Member struct {
Symbol *symbols.Symbol
// Name is the name the member is known under: its effective name.
Name string
// Direction is a feature's direction as the summarized type sees it,
// reversed through a conjugation.
Direction ast.FeatureDirection
// Types are the types a feature is written with, directly or through the
// features it specializes.
Types []*symbols.Symbol
// Multiplicity is the multiplicity a feature declares or takes from the features it
// redefines or subsets, as `[0..*]`; "" for a default.
Multiplicity string
// Origin is the type the member is inherited from; nil for an owned one.
Origin *symbols.Symbol
}
Member is one named member of a definition or usage, as an editor summarizes it.
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
WithDisabledLints leaves the lints with these codes (see passes.LintCodes) out of this workspace's diagnostics.
func WithEnabledLints ¶ added in v0.10.0
WithEnabledLints keeps the opt-in lints with these codes (see passes.IsOptInLint) in this workspace's diagnostics; a disabled lint stays out.
func WithLibrarySource ¶
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
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 ¶
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 ¶
DeclarationText is the source text of sym's declaration, "" when its document is gone.
func (*Reading) Declared ¶
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 ¶
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) 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 ¶
Document is the held document name, nil for one the workspace does not hold.
func (*Reading) Generation ¶
Generation is the workspace's generation as read.
func (*Reading) LineIndex ¶ added in v0.10.0
LineIndex is the held document's line index, nil when the workspace does not hold it.
func (*Reading) LineIndexes ¶ added in v0.10.0
LineIndexes snapshots the line indexes of the held documents.
func (*Reading) LinkSites ¶ added in v0.10.0
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
Query runs fn with the shared semantics, as a query of doc reads them.
func (*Reading) RelatedElements ¶ added in v0.11.0
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 ¶
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.
type ReferenceLocation ¶
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 ¶
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.
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 ¶
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 ¶
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
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 ¶
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
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 ¶
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 ¶
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 ¶
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
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
DisabledLints reports the codes of the lints this workspace leaves out of its diagnostics, sorted.
func (*Workspace) 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 ¶
DocumentNames returns a snapshot of the names of all known documents.
func (*Workspace) DocumentationOf ¶ added in v0.13.0
DocumentationOf returns the prose of the `doc` members sym owns, in declaration order: its `Element::documentation`, as the model reads it.
func (*Workspace) ElementOnPath ¶
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
EnabledLints reports the codes of the opt-in lints this workspace keeps in its diagnostics, sorted.
func (*Workspace) EnclosingMetadataBody ¶
EnclosingMetadataBody returns the nearest scope, from scope outward, whose declarations redefine the features of a metadata type; nil outside one.
func (*Workspace) FQNOf ¶
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) FindingsOn ¶ added in v0.12.0
FindingsOn reports the workspace findings attached to the named document.
func (*Workspace) Generation ¶
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 ¶
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
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 ¶
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) InheritedTypesOf ¶ added in v0.13.0
InheritedTypesOf is Feature::type (KerML 8.3.3.3.4) of a usage whose declaration shows no typing: one that writes none, or one held as its record, which keeps no declaration to read.
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 ¶
IsDocumentDefinition reports whether sym is a native document definition: a part def specializing DocumentQueries::Document.
func (*Workspace) IsLibraryDocument ¶
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 ¶
IsLibraryRoot reports whether name is a top-level package of the workspace's library.
func (*Workspace) LibraryDocument ¶
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
LibraryNames returns the relative paths of the bundled library files the workspace can serve through LibraryDocument, sorted; nil without a source.
func (*Workspace) LookupQualified ¶
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) MemberSummaryOf ¶ added in v0.13.0
MemberSummaryOf returns the named members a definition or usage owns, in declaration order, then, when inherited is set, those it inherits; an alias stands for the element it names.
func (*Workspace) MembersOnPath ¶
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 ¶
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 ¶
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
OnDisk returns a copy of the bytes last recorded as name's file on disk, and whether any were.
func (*Workspace) Open ¶
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
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) 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) OpenWithKind ¶ added in v0.12.0
OpenWithKind is Open for a buffer whose language its name does not tell: the buffer is parsed as kind for as long as it is open.
func (*Workspace) QueryBindingParameter ¶
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 ¶
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 ¶
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 ¶
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
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 ¶
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 ¶
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
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 ¶
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
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
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 ¶
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
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
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
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
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
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 ¶
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
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 ¶
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) Views ¶
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
Workers reports how many documents a batch parses and analyzes at once.
func (*Workspace) WorkspaceFindings ¶ added in v0.12.0
WorkspaceFindings reports what is wrong with the workspace as a whole rather than with one document: today, a library package more than one document declares. Each finding is attached to the document it is reported in, which may be a library document. The findings are computed once per generation.
func (*Workspace) WriteRecord ¶ added in v0.9.2
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.