@pretextbook/completions
v0.5.3
Published
Reusable completion logic for PreTeXt documents
Readme
@pretextbook/completions
Reusable completion logic for PreTeXt editing.
This package extracts completion generation from the VS Code extension LSP so it can be used by other tools (including non-LSP projects).
Usage
import { getPretextCompletions } from "@pretextbook/completions";
const items = await getPretextCompletions({
text,
position: { line: 10, character: 4 },
references,
currentFileDir,
sourceFiles,
});The returned completion items follow the LSP completion item types from vscode-languageserver-types, which has no runtime side effects, so the package can be bundled into browsers and extension hosts as well as language servers.
The element snippet bodies behind the completions are exported as ELEMENTS (keyed by element name), for hosts that want to expand a snippet by name.
If schema is omitted, the package uses a bundled precomputed PreTeXt dev schema.
You can still provide schema explicitly (for custom/stable/publication/project schema behavior).
For href/source file completions, pass sourceFiles explicitly (typically discovered by the host environment).
Absolute paths are recommended when currentFileDir is provided so the package can offer ../-style relative suggestions.
Schema Refresh Workflow
The bundled default schema is generated from extension/assets/schema/pretext-dev.rng.
npm run build -w @pretextbook/completionsrefreshes the latest dev schema and regeneratessrc/default-dev-schema.tsbefore compiling.npm run refresh:schemas(from workspace root) refreshes all extension schemas and regenerates the completions default schema.
