Skip to main content

Crate gdscript_db

Crate gdscript_db 

Source
Expand description

gdscript-db — the input layer for the analyzer.

Holds the virtual file system (FileId → text, always injected — never std::fs), the project model, and (from Phase 3) the salsa query graph: #[salsa::input]s set via apply_change, #[salsa::tracked] derived queries, durability tiers. The Phase-0/1/2 plain VFS map + reparse-on-change is being replaced here, localized behind the unchanged gdscript-ide public API (Playbook §3.M0).

Crate boundary: gdscript-db is the base of the salsa stack — it owns the Db trait, the inputs, and the parse query (it may depend on gdscript-syntax, never on gdscript-hir). The higher queries (item_tree, analyze_file) live in gdscript-hir, which depends on this crate for &dyn Db. This one-way layering is what avoids a db ↔ hir dependency cycle.

FileId is deliberately not a salsa input. The FileId → FileText mapping is a side table (Files) the database owns, mirroring rust-analyzer’s base-db: FileIds are assigned by the client/loader and stay opaque ids, while the salsa input is the text.

Must build for wasm32 (single-threaded; salsa with default-features = false).

Structs§

EngineGeneration
A generation counter that makes the otherwise-untracked runtime engine model invalidate correctly. The engine model is a leaked &'static side handle (not a salsa input), so a query memoized while it was still absent (engine() == None, on wasm32 before set_engine_api) would otherwise return that stale empty result forever. Every engine() read records a dependency on this input; set_engine_api bumps it, recomputing those queries. The value is irrelevant — only that setting it advances the revision. Used on wasm32 only (native has the bundled model from the start, so it never changes — no generation tracking, no overhead).
FileText
The VFS leaf: one file’s UTF-8 text, as a salsa input, plus its FileId (so a query holding only a FileText can recover the id for cross-file resolution) and its res:// path (so preload/extends "res://…" resolve to the declaring file — M3).
Files
The FileId → FileText side table. Arc-backed so a cheap clone shares the same map — needed to mutate an input (&mut dyn Db) without simultaneously borrowing self.files.
ProjectConfig
The project’s project.godot, injected as raw text — the wasm-clean core never reads the filesystem, so the loader pushes the bytes exactly like a .gd file. The autoload index is a tracked query that parses this text (M4). Held at MEDIUM durability (project structure, stable across .gd keystrokes), so a body edit (LOW) never invalidates the autoload registry.
RootDatabase
The concrete analyzer database — a salsa Storage plus the Files side table.
SourceRoot
The project’s file set — a salsa input so project-wide queries (the global class_name registry, M1) iterate the files incrementally. It changes only when a file is added or removed, never on a body edit, and is held at MEDIUM durability — so a keystroke (a LOW change) never invalidates project-wide derived data.

Traits§

Db
The database trait gdscript-hir / gdscript-ide depend on. #[salsa::db] on the trait makes it a salsa supertrait, so any &dyn Db upcasts to &dyn salsa::Database and every #[salsa::tracked] free function downstream can take db: &dyn Db.

Functions§

parse
Parse a file to its lossless CST. Memoized; re-parses only when the file text changes.