model

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: Apache-2.0 Imports: 20 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

View Source
const PseudoViewPrefix = "#"

PseudoViewPrefix marks a rendering asked for by element rather than by a view the document declares: `#tree`, `#state:<fqn>`, `#action:<fqn>`, `#interconnection:<fqn>`. Nothing is added to the model or the index for one.

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

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.

Types

type ChangeEvent

type ChangeEvent struct {
	Kind    EventKind
	Name    string
	Content []byte
	Version int
	// contains filtered or unexported fields
}

ChangeEvent is one mutation posted to the workspace owner goroutine. ack, when non-nil, is closed after the event has been applied (test/sync aid).

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 EventKind

type EventKind int

EventKind classifies a change event feeding the reindex pipeline.

const (
	EventOpen   EventKind = iota // LSP didOpen: register authoritative buffer
	EventChange                  // LSP didChange: replace buffer content
	EventClose                   // LSP didClose: drop buffer, revert to on-disk
	EventCreate                  // fsnotify: file created on disk
	EventModify                  // fsnotify: file modified on disk
	EventDelete                  // fsnotify: file deleted on disk
)

func (EventKind) String

func (k EventKind) String() string

type EventLoop

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

EventLoop is the single owner goroutine that serializes workspace mutations.

func NewEventLoop

func NewEventLoop(ws *Workspace) *EventLoop

NewEventLoop returns a loop bound to ws. Call Run in a goroutine, then Post.

func (*EventLoop) Close

func (l *EventLoop) Close()

Close stops the owner goroutine. Events still buffered when Close is observed are not guaranteed to be applied; callers that need delivery should drain before closing.

func (*EventLoop) Post

func (l *EventLoop) Post(ev ChangeEvent)

Post enqueues an event for the owner goroutine. If the loop has been closed, Post returns without blocking (the event is dropped) so late producers such as the fsnotify watcher never hang on a stopped loop.

func (*EventLoop) Run

func (l *EventLoop) Run()

Run is the owner loop; run it in its own goroutine. It is the sole writer to the workspace, so mutations are serialized even with many event producers.

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.

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 Watcher

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

Watcher translates filesystem events for .sysml/.kerml files into ChangeEvents posted to an EventLoop, debounced per path. Open documents (per the isOpen predicate) have their on-disk events dropped, so the LSP buffer stays authoritative.

func NewWatcher

func NewWatcher(loop *EventLoop, window time.Duration, isOpen func(name string) bool) (*Watcher, error)

NewWatcher creates a Watcher posting to loop, coalescing bursts within window, and consulting isOpen(name) to skip open documents.

func (*Watcher) Add

func (w *Watcher) Add(dir string) error

Add registers a directory to watch.

func (*Watcher) Close

func (w *Watcher) Close() error

Close stops watching and releases resources.

func (*Watcher) Run

func (w *Watcher) Run()

Run consumes filesystem events until Close. It is the sole caller of the debouncer, which in turn posts to the EventLoop (the sole workspace writer).

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 (and, in Task 5, through a single owner goroutine); 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 SYSML_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) 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) 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) 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.

func (*Workspace) IsOpen

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

IsOpen reports whether name has an authoritative open buffer.

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

func (w *Workspace) Remove(name string)

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

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 view the document declares, by qualified name; a pseudo-view (`#tree`, `#state:<fqn>`, `#action:<fqn>`, `#interconnection:<fqn>`) renders an element as if a view exposing it had been declared; and "" renders the document's own view, which is the ambiguity error when it declares more than one and ErrNoView when it declares none.

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 on-disk bytes (from fsnotify). 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 view stating a kind that is recognized but not produced — sequence, geometry, textual — is listed as unsupported with the reason, so a client can say why it cannot be drawn.

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