model

package
v0.1.2 Latest Latest
Warning

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

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

func LoadStdlibInto(idx *symbols.Index)

LoadStdlibInto loads the standard library into idx, for a consumer that resolves library names through an index of its own — the REPL's runtime, which has to resolve the measurement unit a quantity expression names.

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 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 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() *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).

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

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

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

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.

Jump to

Keyboard shortcuts

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