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
- Variables
- func IsModelSource(path string) bool
- func LoadStdlibInto(idx *symbols.Index)
- type ChangeEvent
- type Debouncer
- type Document
- type EventKind
- type EventLoop
- type ViewInfo
- type Watcher
- type Workspace
- func (w *Workspace) AnalyzedContent(name string) ([]byte, []passes.Diagnostic, bool)
- func (w *Workspace) Close(name string)
- func (w *Workspace) DeleteOnDisk(name string)
- func (w *Workspace) Diagnostics(name string) []passes.Diagnostic
- func (w *Workspace) Document(name string) *Document
- func (w *Workspace) DocumentNames() []string
- func (w *Workspace) HighlightTokens(name string) []highlight.Token
- func (w *Workspace) IsOpen(name string) bool
- func (w *Workspace) LookupQualified(fqn string) []*symbols.Symbol
- func (w *Workspace) MembersOnPath(scope *symbols.Scope, path []string) []*symbols.Symbol
- func (w *Workspace) Open(name string, content []byte, version int)
- func (w *Workspace) OpenNames() []string
- func (w *Workspace) Remove(name string)
- func (w *Workspace) RenderView(doc, fqn string) (*view.Rendering, 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) ResolveReferenceSegmentsInDoc(name string, ref resolve.Reference) []*symbols.Symbol
- func (w *Workspace) SetOnDisk(name string, content []byte)
- func (w *Workspace) TopLevelSymbols(doc string) []*symbols.Symbol
- func (w *Workspace) Update(name string, content []byte, version int)
- func (w *Workspace) Views(doc string) []ViewInfo
Constants ¶
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 ¶
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 ¶
IsModelSource reports whether path is a SysML/KerML source file.
func LoadStdlibInto ¶
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 ¶
NewDebouncer returns a debouncer with the given coalescing window.
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 )
type EventLoop ¶
type EventLoop struct {
// contains filtered or unexported fields
}
EventLoop is the single owner goroutine that serializes workspace mutations.
func NewEventLoop ¶
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.
type ViewInfo ¶ added in v0.1.2
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.
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 ¶
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 ¶
Close drops the open buffer for name; the document reverts to on-disk content if any, otherwise it is removed.
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) 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) DocumentNames ¶
DocumentNames returns a snapshot of the names of all known documents.
func (*Workspace) HighlightTokens ¶
HighlightTokens returns the semantic tokens of a document, ordered by source position. Returns nil for unknown documents.
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) 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) Remove ¶
Remove deletes the document entirely (open buffer, on-disk cache, and index).
func (*Workspace) RenderView ¶ added in v0.1.2
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 ¶
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 ¶
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) Views ¶ added in v0.1.2
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.