Skip to content

Editor database

The language server's inputs, memoized parses, and its one compile of the project.

atoll build, check, run, test and serve compile a project through the layered compile in atoll-driver: each dependency sealed into a layer kept on disk, then the project’s own files compiled over the sealed world. What a compile keeps for the next is that pipeline’s own output, keyed by its inputs.

The language server’s database, atoll_lsp::db, is not a second compiler. It holds what the editor has open, memoizes what is cheap to keep per file, and compiles the project through the same pipeline.

Tracked inputs

Input Examples
SourceFile Stable path, module path, mutable file contents
Project Root module, ordered files, dependencies, host allowlist, datasource routing, package directories

The editor updates a SourceFile through its Salsa setter as the user types. Changing a file’s contents invalidates the queries that read that file. Adding, removing or reordering a project’s files changes its file list, and with it the project’s compile. A setter stamps a new revision even when the value is unchanged, so the editor compares before it writes.

Queries

SourceFile ─→ parse_file ─→ position_index
                  │
dependency files ─┼─→ project_seed_q   (sealed dependencies)
                  │          │
project files ────┴──────────┴─→ sema_project_q ─→ compile_project_q
                                        │
                                        └─→ Diag accumulator (published diagnostics)
  • parse_file is memoized per SourceFile. Editing one file reparses that file; unchanged files keep their prior Arc<ParsedFile>.
  • project_seed_q seals the project’s dependencies. It reads the dependency files alone, so an edit to the app leaves it cached, and a keystroke never re-checks a module the app imports.
  • sema_project_q compiles the project’s own files over that sealed world, through the pipeline every command takes. The dependencies’ diagnostics come first, as the CLI orders them.
  • contracts_q runs the project’s contracts.

Hover, go to definition, completion, inlay hints, references and signature help all read the one compile_project_q result, so an edit pays for one compile however many features ask about it.

Incremental parses

The language server can populate a separate incremental parse cache for an exact (path, contents) pair. parse_file accepts that parse only when the contents match. Otherwise it performs a normal parse, so one source snapshot has one parse.

Query design rules

When adding a query:

  1. key it on the smallest stable identity, not a transient pointer;
  2. read every tracked input that can change the result;
  3. return immutable shared snapshots;
  4. define equality or backdating only for facts truly irrelevant downstream;
  5. avoid ambient options that Salsa cannot observe;
  6. never compute a compiler stage the pipeline does not: a query composes the pipeline’s results, it does not hold a second implementation of one.

Type to search…

↑↓ navigate↵ selectEsc close