RELAX NG validation and schema-aware completion for TEI documents and ODDs, as a language server. Used by the ODDity VS Code extension.
Completion only suggests elements and attributes that the schema allows at the
cursor position, and it respects their required order. For example, right after
<TEI> it suggests only <teiHeader>. Each suggestion shows the description
that the ODD provides for that element or attribute.
The language server tries to find the schema associated with a document by checking the following locations in order:
- a local
.rngnamed by the document's<?xml-model?> - for documents other than ODDs,
[editor] schemain the nearestopm.toml - defaults by vocabulary:
schema/odd/teipublisher_odds.rngfor.oddfiles, and for documents recognised as TEI, DocBook or JATStei_all, DocBook 5.2 or JATS 1.3 Archiving with MathML 3 (seeschema/README.mdfor sources and licences)
An <?xml-model?> or [editor] schema naming one of these by its published URL
(e.g. the TEI's tei_all.rng) uses the bundled copy; other remote schemas are ignored.
If no schema can be determined, the language server still supports well-formedness checks, an outline and tag renaming.
src/core/: editor-independent code (validation, completion, schema association, outline, tag matching), exported fromsrc/index.ts.validate.ts,complete.tsandtoml.tscome from opm studio.src/server/server.ts: the language server, independent of its transport.src/node.ts: Node entry (--node-ipcor--stdio), built todist/node.cjs.ODDITY_LS_SCHEMASpoints it at aschema/folder for the defaults; clients can passinitializationOptions.defaultSchemasinstead.
Custom protocol: request oddity/schemaFor { uri } returns the schema in use;
notification oddity/schemaChanged { uri, schema } is sent when it changes.
npm install
npm test # node --test, runs the TypeScript directly
npm run check # tsc
npm run build # dist/
npm run schemas # regenerate schema/ (opm compiles teipublisher_odds.odd from jinks)
npm run schemas looks for jinks in $JINKS_DIR, ../../apps/tei-publisher/jinks
or ../jinks, and falls back to GitHub.