Help us shape the future of Go! Take the 2026 Go Developer Survey

libs

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package libs loads SysML/KerML standard-library files (bundled via embed.FS or overridden on disk) and maintains a persistent cache of their indexed symbols. See spec section 10.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

Cache persists reduced library IndexRecords to disk keyed by content hash and format version. A hit lets the loader skip lexing/parsing entirely. The same mechanism serves git dependencies (Plan 5c) since it keys purely on content.

func NewCache

func NewCache() (*Cache, error)

NewCache resolves the cache directory ($XDG_CACHE_HOME or os.UserCacheDir), appends "sysml-ls/libs", creates it, and returns a ready Cache.

func (*Cache) Load

func (c *Cache) Load(key string) (*IndexRecord, bool)

Load returns the cached record for key, or (nil, false) on any miss (absent file, read error, or decode error — all treated as a benign miss).

func (*Cache) Prune added in v0.0.5

func (c *Cache) Prune()

Prune removes records that no load has hit for maxIdleAge, and the temp files a crashed store left behind. Cache entries are otherwise never invalidated explicitly — a key that no longer matches is simply missed — so without this the directory keeps every record any library version ever produced.

func (*Cache) Store

func (c *Cache) Store(key string, rec *IndexRecord) error

Store gob-encodes rec and writes it to <dir>/<key>.idx atomically: it writes a temp file of its own then renames it into place, so a concurrent Load or a crash never observes a partially written file, and two writers of one key cannot truncate or publish each other's temp. A failed encode/write removes the temp and leaves any existing final file untouched.

type IndexRecord

type IndexRecord struct {
	Name    string
	Symbols []symRecord
}

IndexRecord is the serializable snapshot of one library document's symbols.

type Loader

type Loader struct {

	// RequireResolved makes Persist skip a document with an unresolved
	// specialization target: a key does not describe the index a record was built
	// in, so one built in a partially populated index must not be reused where
	// the target exists.
	RequireResolved bool
	// contains filtered or unexported fields
}

Loader lazily loads library files from a Source and registers their symbols into a target index, using a Cache to skip parsing on repeat loads (Task 6).

func NewLoader

func NewLoader(src Source, cache *Cache) *Loader

NewLoader returns a Loader over src, using cache for persistence.

func (*Loader) Load

func (l *Loader) Load(name string, idx *symbols.Index) error

Load reads the named library file and registers its symbols into idx, marked as library content. On a cache hit the reduced record is restored directly, skipping lexing/parsing; on a miss the file is parsed and registered, and its record is written by a later call to Persist.

func (*Loader) Persist added in v0.0.4

func (l *Loader) Persist(idx *symbols.Index)

Persist caches a reduced record of every document this loader parsed. It is separate from Load because a record holds resolved supertype names: a specialization target in one library file may be declared in another, so records can only be built once every file has been indexed. Records the library has stopped asking for are pruned here, where a write already happened.

type Source

type Source interface {
	// List returns the relative paths of available library files, sorted.
	List() []string
	// Read returns the bytes of the named library file, or an error.
	Read(name string) ([]byte, error)
}

Source yields standard-library file contents by relative path (e.g. "Kernel Libraries/Kernel Data Type Library/ScalarValues.kerml").

func DefaultSource

func DefaultSource() Source

DefaultSource returns a dirSource rooted at SYSML_LIBRARY_PATH when that environment variable is set and non-empty, otherwise the embedded source.

func NewDirSource

func NewDirSource(dir string) Source

NewDirSource returns a Source that reads .kerml/.sysml files from dir.

Jump to

Keyboard shortcuts

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