model

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: Apache-2.0 Imports: 26 Imported by: 0

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 ErrNoView = errors.New("declares no view")

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

Functions

func DeclaredDocumentDefinitions added in v0.4.2

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 added in v0.3.1

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 IsModelSource

func IsModelSource(path string) bool

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

func NewIndexWithStdlib added in v0.2.0

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 SiblingDocumentPlans added in v0.4.2

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 added in v0.3.1

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

TopLevelDeclarations returns root declarations, expanding packages one level.

Types

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 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.

type DocumentDefinition added in v0.4.2

type DocumentDefinition struct {
	FQN string
	Doc string
}

DocumentDefinition is one native document definition the workspace holds: a part def specializing DocumentQueries::Document, and the file declaring it.

type Option added in v0.2.0

type Option func(*Workspace)

Option configures a workspace at construction.

func WithConformanceMode added in v0.2.0

func WithConformanceMode(mode conformance.Mode) Option

WithConformanceMode analyzes this workspace's documents at mode.

func WithLibrarySource added in v0.5.0

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.

type QueryTypeCandidate added in v0.4.2

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 ReferenceLocation added in v0.5.0

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 ViewInfo added in v0.1.2

type ViewInfo struct {
	Name      string
	Kind      view.Kind
	Supported bool
	Reason    string
}

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.

type VisibleName added in v0.2.0

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 added in v0.2.0

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 added in v0.2.0

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.

func (*Workspace) AmbiguousInvocationInDoc added in v0.5.0

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) AnalyzedContent

func (w *Workspace) AnalyzedContent(name string) ([]byte, []passes.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) 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.

func (*Workspace) ConformanceMode added in v0.2.0

func (w *Workspace) ConformanceMode() conformance.Mode

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) Diagnostics

func (w *Workspace) Diagnostics(name string) []passes.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) Document

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

Document returns the current parsed document for name, or nil.

func (*Workspace) DocumentDefinitions added in v0.4.2

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 added in v0.2.0

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) EnclosingMetadataBody added in v0.5.0

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 added in v0.2.0

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) HighlightTokens

func (w *Workspace) HighlightTokens(name string) []highlight.Token

HighlightTokens returns the semantic tokens of a document, ordered by source position. Returns nil for unknown documents. A bundled library document is highlighted from its text like a workspace one.

func (*Workspace) IdentityOf added in v0.5.0

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; ok is false when it has no qualified name or is not indexed there.

func (*Workspace) IsDocumentDefinition added in v0.4.2

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 added in v0.5.0

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

IsLibraryDocument reports whether name is a bundled library file the index holds, as opposed to a document of the workspace's own.

func (*Workspace) IsOpen

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

IsOpen reports whether name has an authoritative open buffer.

func (*Workspace) LibraryDocument added in v0.5.0

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) 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 added in v0.2.0

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 added in v0.2.0

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 added in v0.5.0

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

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.

func (*Workspace) Open

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

Open registers an authoritative open buffer for name and reindexes.

func (*Workspace) OpenNames

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

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

func (*Workspace) QueryBindingParameter added in v0.4.2

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 added in v0.4.2

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 added in v0.4.2

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 added in v0.4.2

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) ReferencesTo added in v0.5.0

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

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.

func (*Workspace) Remove

func (w *Workspace) Remove(name string)

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

func (*Workspace) RenameConflict added in v0.5.1

func (w *Workspace) RenameConflict(target *symbols.Symbol, name, newName string) *rename.Conflict

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.

func (*Workspace) RenderDocumentMarkdown added in v0.4.2

func (w *Workspace) RenderDocumentMarkdown(fqn string) (string, error)

RenderDocumentMarkdown compiles the named document definition, evaluates its queries against the workspace model, and renders the result as Markdown.

func (*Workspace) RenderView added in v0.1.2

func (w *Workspace) RenderView(doc, fqn string) (*view.Rendering, 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.

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 added in v0.2.0

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 added in v0.2.0

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 added in v0.2.0

func (w *Workspace) SetConformanceMode(mode conformance.Mode)

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.

func (*Workspace) SetOnDisk

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

SetOnDisk records 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) 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) Update

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

Update replaces the open buffer content for name and reindexes.

func (*Workspace) Views added in v0.1.2

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

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.

func (*Workspace) VisibleNames added in v0.2.0

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 added in v0.2.0

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

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

Jump to

Keyboard shortcuts

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