Skip to content

Structure: formatting and lint CI, document registry, shared-data revisions, cursor context - #39

Merged
ajuvercr merged 10 commits into
mainfrom
claude/dreamy-mendel-uxxfa0
Nov 18, 2026
Merged

ajuvercr merged 10 commits into
mainfrom
claude/dreamy-mendel-uxxfa0

Conversation

@ajuvercr

@ajuvercr ajuvercr commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Structural improvements that make features like the SHACL templates and shape docs easier and safer to add. Every commit builds and passes the tests on its own.

Merging: please use Create a merge commit. The formatting-only commit is listed by hash in .git-blame-ignore-revs. Squash and "Rebase and merge" both give commits new hashes, which would leave that entry pointing at nothing.

Formatting and lints

  • rustfmt.toml keeps only stable options. imports_granularity and group_imports need nightly, so on stable cargo fmt warned and could not reproduce the intended formatting.
  • One formatting-only commit (style: cargo fmt --all), listed in .git-blame-ignore-revs.
  • cargo clippy --workspace --all-targets -- -D warnings passes, checked with Rust 1.97 and with Rust 1.100 (CI's current stable):
    • Workspace lints: [workspace.lints.clippy] allows type_complexity and too_many_arguments, because Bevy systems naturally have many parameters and nested Query types.
    • Automatic fixes: cargo clippy --fix handled the mechanical lints.
    • By hand:
      • an MSRV violation in components-rs (is_none_or);
      • the deprecated try_next;
      • into_oxi returning Option instead of Result<_, ()>;
      • a canonical PartialOrd for MyTerm;
      • a needed clone that clippy wanted to remove;
      • a redundant test import that only newer clippy flags.
  • CI has a new lint job (cargo fmt --all --check and clippy), next to build and test.

Document registry

  • A Documents resource maps URL → entity. It is kept up to date by Label's on_insert / on_replace hooks, so it stays correct however a document is spawned, relabelled or despawned.
  • Label is now immutable, so it cannot change without the hooks running.
  • find_document replaces every label scan:
    • spawn_or_insert;
    • spawn_background;
    • the document lifecycle;
    • the JSON-LD loader;
    • the test harness.
  • Backend drops its own URL → entity map. Requests carry the URL, and the document is looked up inside the world in the same step that runs the request. Before, a document closed between lookup and request made entity_mut panic.

Revisions for shared data

  • core::revisions::Revisions counts changes to data shared between documents:
    • the store;
    • known ontologies;
    • the class hierarchy;
    • SHACL shapes;
    • configured sources.
  • Producers bump a counter when their data changed. Consumers keep a Local<Seen> and process every open document once after a bump, otherwise only documents whose own triples changed.
  • These replace the ad-hoc triggers: Changed<ShaclShapes>, Added<ConfiguredOntology>, running the save schedule after imports, and revalidating every open document on every parse.
  • Fixes along the way:
    • Types inferred from property domains stayed wrong until the next edit when the ontology arrived after the document was opened. infer_types now reruns on ontology and hierarchy changes, ordered after its producers.
    • Editing one document no longer revalidates every other open document.

Cursor semantics and completion context

  • Token lookup: token_at_cursor treats the cursor as sitting between characters. It belongs to a word it is inside of, else a word ending at it (ex:fo|; is ex:fo), else punctuation it touches, else nothing (whitespace). The triple lookup uses the same rule.
  • No position shift: Backend no longer moves positions one character left. That shift made completion at the end of a word work, but hovering the first character of a term resolved the term before it. The server and the test harness now handle positions identically.
  • CursorContext: resolved once per completion request. It holds the role at the cursor, the subject being described, the typed word, the insertion range, and whether a space is needed after ; / , / [.
    • Inside [ … ], with the cursor not on a term, it is a predicate position of that blank node.
    • Class, property, shape-template and shape-property completion use it. Property completion inside a blank node now works, with domain-aware ordering for its type.

Shapes

  • shapes::visible holds the single rule for which shape documents apply to a document: global, the document itself, or linked. Validation, templates, hover and completion all use it.
  • Templates, hover and completion share shapes::model. Validation keeps the rudof engine.
  • Shape documentation shortens IRIs with all shape documents' prefixes as one set.
  • Prefixes::shorten breaks ties between equally long namespaces by preferring a named prefix, then alphabetical order. The result no longer depends on the order documents are visited.

Naming

  • TypeHierarchy::iter_subclass walked superclasses and iter_superclass walked subclasses. They are now iter_ancestors / iter_descendants, with the old names kept as deprecated aliases. Callers' variables are renamed to match. Behaviour is unchanged.

Testing

  • cargo fmt --all --check, clippy with -D warnings, build, and cargo test --workspace (576 tests) all pass.
  • New tests:
    • registry hooks;
    • Seen;
    • cursor token resolution;
    • prefix tie-breaking;
    • hierarchy walks;
    • e2e/tests/late_data.rs: types and closed-namespace warnings after a late ontology, and no revalidation of unrelated documents;
    • e2e/tests/cursor.rs: a word before ;, hover on the first character, completion inside a blank node.
  • Ran the real binary over stdio:
    • goto-definition into the cache, the cached-copy notice and didClose;
    • shape templates at the exact cursor;
    • shape hover with the RML shapes, deterministic across runs.

`imports_granularity` and `group_imports` need a nightly rustfmt, so on
stable `cargo fmt` warned about them and could not reproduce the intended
formatting. Keep `use_field_init_shorthand`, which is stable.
Formatting only, no code changes. Listed in .git-blame-ignore-revs.
Makes `cargo clippy --workspace --all-targets -- -D warnings` pass.

- Workspace lints (`[workspace.lints.clippy]`, inherited by every crate):
  `type_complexity` and `too_many_arguments` are allowed, because Bevy
  systems take their data as parameters and nested `Query` types.
- `cargo clippy --fix` for the mechanical lints (needless borrows, redundant
  closures and returns, `'static` on constants, …).
- By hand:
  - `Option::is_none_or` (Rust 1.82) replaced in components-rs, whose MSRV
    is 1.75;
  - `try_next` (deprecated) replaced by `try_recv` on the command and
    diagnostic channels;
  - `MyQuad::into_oxi(_graph)` return `Option` instead of `Result<_, ()>`;
  - `PartialOrd` for `MyTerm` delegates to `Ord`;
  - `assert!(false, …)` → `panic!` in the conformance tests;
  - a few `sort_by_key`, `while let`, `is_err()` and merged `if` branches;
  - `TestFs: Default`;
  - kept the needed clone in the config loaders (clippy's suggestion does
    not compile, the value moves into a spawned future);
  - pinned a lifetime in `prefix_completion_helper` that the elided form
    could not express.
- `wrong_self_convention` is allowed on the two public `into_triples` trait
  methods rather than renaming them across crates.
New `lint` job: `cargo fmt --all --check` and
`cargo clippy --workspace --all-targets -- -D warnings`. It runs next to
the build and test job, so a lint failure does not hide test results.
Documents were found by scanning every `Label` (in `spawn_or_insert`,
`spawn_background`, the document lifecycle, the JSON-LD loader and the test
harness), while `Backend` kept its own URL → entity map, filled on
`didOpen`. The two could disagree, and a request looked up its entity
before running, so a document closed in between would make
`entity_mut` panic.

- `Documents`: a resource mapping URLs to entities, kept up to date by
  `Label`'s `on_insert` / `on_replace` hooks, so it is correct however a
  document is spawned, relabelled or despawned. `Label` is now an
  immutable component, so it cannot change without the hooks running.
- `find_document(world, url)` is the one lookup, used everywhere a label
  scan was. Without the registry (a bare test world) it falls back to a
  scan.
- `Backend` drops its map. Requests carry the URL, and `run_schedule`
  looks the document up inside the world, in the same step that runs the
  schedule.
- The registry docs describe the kinds of documents: `Open`, `Background`,
  both, and cached (a background document in the ontology cache).
Shared data (the store, known ontologies, the class hierarchy, SHACL
shapes, configured sources) usually arrives after the documents that use it
were opened. Each consumer had its own trigger: `Changed<Triples>` on
background documents, `Changed<ShaclShapes>`, `Added<ConfiguredOntology>`,
running the save schedule after an import, or simply rerunning for every
open document on every parse.

`Revisions` (`core::revisions`) counts changes per kind of shared data.
Producers bump a counter when their data changed; consumers keep a
`Local<Seen>` and process every open document once after a bump, otherwise
only documents whose own triples changed.

- `load_store` → `store`; `derive_ontologies` recomputes on `store` and
  bumps `ontologies`; `extract_type_hierarchy` and `derive_ontologies` bump
  `hierarchy` when it grew; `derive_shapes` bumps `shapes` only when a
  document has or had actual shapes; configured ontologies bump `sources`.
- `infer_types` now reruns when ontologies or the hierarchy change. Before,
  types inferred from property domains stayed wrong until the next edit
  when the ontology arrived after the document was opened. It is ordered
  after its producers, so the change is seen in the same pass.
- `validate_namespace_properties` no longer reruns for every open document
  on every parse; it runs on edits, ontology changes and config changes.
- `validate_shapes`, `derive_prefix_links` and `fetch_lov_properties` use
  the counters instead of their ad-hoc queries, and imports no longer run
  the save schedule to force revalidation.
…y rule

Positions
- The token at a cursor is resolved with cursor semantics
  (`token_at_cursor`): a cursor sits between characters, so it belongs to a
  word it is inside of, else a word ending at it (`ex:fo|;` is `ex:fo`),
  else punctuation it touches, else no token (whitespace). The triple
  lookup prefers a term containing the cursor, then one ending at it.
- `Backend` no longer shifts positions one character left. The shift made
  completion at the end of a word work, but hovering the first character of
  a term resolved the term before it. The server and the test harness now
  handle positions identically; the harness docs say so.

Completion context
- `CursorContext`, resolved once per completion request
  (`get_cursor_context`): the role at the cursor, the subject being
  described, the typed word, where to insert, and whether a space is needed
  after `;` / `,` / `[`. Inside `[ … ]`, not on a term, the cursor is at a
  predicate position of that blank node.
- Class, property, shape-template and shape-property completion use it,
  replacing the templates' private cursor helpers. Property completion
  inside a blank node now works, with domain-aware ordering for its type.

Shape visibility
- `shapes::visible`: one rule for which shape documents apply to a document
  (global, the document itself, or linked), used by validation, templates,
  hover and completion.
- Shape documentation shortens IRIs with all shape documents' prefixes as
  one set, and `Prefixes::shorten` breaks ties between equally long
  namespaces by preferring a named prefix, then alphabetical order, so the
  result no longer depends on the order documents are visited.
`TypeHierarchy::iter_subclass` walked a class's *superclasses* and
`iter_superclass` its *subclasses* (the `subclass` field held a class's
parents). The outputs were labelled correctly, but only because every
caller knew the names were swapped.

- Fields `parents` / `children`; `iter_ancestors(_ids)` (the class and its
  superclasses) and `iter_descendants(_ids)` (the class and its
  subclasses), sharing one breadth-first `walk`.
- The old names stay as deprecated aliases, since `swls-core` is published.
- Callers and their variables are renamed to match (`refinements` in class
  completion, `ancestors` in property and JSON-LD completion), with
  comments on what each set is used for. Behaviour is unchanged; a unit
  test pins the direction of both walks.
Rust 1.100 (CI stable) reports `prelude::*` in the code action tests as
unused: `use super::*` already brings the prelude in. Rust 1.97 did not
flag it.
@ajuvercr
ajuvercr force-pushed the claude/dreamy-mendel-uxxfa0 branch from eccfc17 to cbe9b3a Compare November 18, 2026 09:46
@ajuvercr
ajuvercr merged commit c66b6c9 into main Nov 18, 2026
2 checks passed
@ajuvercr
ajuvercr deleted the claude/dreamy-mendel-uxxfa0 branch November 18, 2026 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants