Workspace Lifecycle¶
The workspace layer keeps documents, indexes, and text content in sync. You need it as soon as your language grows beyond "parse one file and stop".
Key pieces¶
DocumentFactoryDocumentsTextDocumentsDocumentBuilderIndexManagerWorkspaceManagerWorkspaceLock
Lifecycle overview¶
- Text documents are opened or updated.
- Pegium rebuilds parse results and syntax trees.
- Index data and exported symbols are refreshed.
- References, validation, and LSP features observe the updated document state.
Documents move through staged states:
ChangedParsedIndexedContentComputedScopesLinkedIndexedReferencesValidated
This staging lets language features depend on stable intermediate results instead of reparsing or relinking ad hoc.
Document versus TextDocument¶
Pegium separates source text from derived analysis.
Documentowns the parse result, AST/CST, references, diagnostics, and analysis state.TextDocumentowns the current source text, language id, version, and offset/position helpers.
Use document.textDocument() for source text or position conversions. Use Document for parse results, scopes, or diagnostics.
Scope resolution, rename, references, and workspace symbols all rely on this shared document and index infrastructure.
What DocumentBuilder does¶
DocumentBuilder orchestrates the pipeline. It turns a file change into a coherent rebuild instead of a pile of ad hoc reparsing.
Readiness versus stable phases¶
WorkspaceManager::ready() only means startup documents have been discovered. If a feature needs a stronger guarantee such as Linked or Validated, wait for that phase explicitly.
Practical advice¶
- Keep parsing deterministic.
- Customize scoping and indexing before touching workspace internals.
- Treat the workspace as the shared foundation for references, diagnostics, and editor features.