Files
lucisv/docs/features/lint-config-contract/README.md
T
lucioandClaude Fable 5.1 4b2dad87fe One lint-configuration contract for project and editor: the server picks the editor's selection when set, else the project's, and logs rejected project entries once
TODO §42 (docs/features/lint-config-contract). Closes topo §2.9-28 and
repository-analysis finding 2.

`enabled_rules(settings, project, has_oracle)`: rung 2 is
`lucisv.lint.select` when non-empty else `[lint] select`, rung 5 the same
for `ignore` — the CLI's `pick` applied to the editor — so one buffer
linted two ways is linted the same way (asserted equal over the wire for
three configurations). `lint::project`: `ProjectLint` read from the
`Discovery` result `configured` already computes (no extra read per
pass); an unknown rule name in a project list is dropped and said rather
than silently emptying the selection. `ConfigProblems`/`ProblemLog`:
rejected `[lint.<rule>]` options, unknown names and bad `[lint] waivers`
lines are logged once per (config file, entry) in `lucisv check`'s
wording, re-armed when the config's lint content changes; the buffer
keeps linting with the entry dropped.

Docs applied: README, the linter guide, configuration.md, the analysis,
topo (28 struck; 29 filed for the editor-side unknown-name silence), site
rebuilt.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
2026-09-05 01:45:48 -05:00

26 KiB
Raw Blame History

lint-config-contract

TODO §42. Repository-analysis finding 2, topology handshake 28.

Goal

One lint-configuration contract for the two front ends. Before this round the CLI read a project's [lint] select / ignore out of lucisv.toml and the server did not: enabled_rules selected rules from ClientSettings alone, and configured discovered the same config file only to read its rule options and its line length. A team that checked in select = ["no-tabs"] therefore got one answer from CI and a different one from every editor in the project, and the docs had to say so. The server also dropped a [lint.<rule>] entry the registry refused (let _ = options.set_raw(...)) with nothing said, while the same mistake made in lucisv.lint.options was logged.

The contract, which is the CLI's today applied to the editor: the editor's settings play the role the CLI's flags play. lucisv/src/lint.rs picks the flag when one was given and the project file otherwise (pick); the server now picks lucisv.lint.select when it is non-empty and [lint] select otherwise, and the same for ignore, key by key. And a project entry that cannot be used is said — once per (config file, entry), in the words lucisv check fails the run with — rather than silently dropped.

Assumptions

  • A server cannot fail a run. Everything the CLI treats as fatal (an unknown rule name, a rejected rule option, a waiver file that is not there or holds an unparsable directive) is here a dropped entry plus one log line. The buffer keeps being linted with everything that was understood. This is the standing rule of lint.rs and settings::rule_options, applied to the project file for the first time.
  • Rungs 3 and 4 are the editor's alone. lucisv.lint.severity.<class> and lucisv.lint.rules.<name> have no counterpart in lucisv.toml and none on the command line, so nothing about them changed. They still apply over a selection the project made, which is what "all style off except no-tabs" needs.
  • One discovery per pass, no new file read. configured already ran Discovery::new(true).for_file(path) once per LintRun::for_document; the project's selection is read out of the FileConfig that discovery already produced, so 42.1 costs zero stats and zero opens. The waiver files are now read in two calls instead of one (the project's paths, then the editor's) so a problem in the project's can be attributed to the lucisv.toml that named it — the same files, the same number of reads.
  • The memo is keyed by (config path, message), re-armed by content. The server has no "config generation": nothing invalidates on a lucisv.toml write, because the file is re-read on every pass. So ProblemLog stamps each config path with a hash of that file's lint-relevant content ([lint] select/ignore/waivers and every [lint.<rule>] entry) and clears that path's memo when the stamp moves. A user who edits the file and gets it wrong again is told again; a user who types in a .sv buffer is not told a hundred times. A problem in a waiver file named by an unchanged lucisv.toml is said once per session, which is the one edge the stamp does not see; it is a log line, not a diagnostic, and lucisv check is the place that fails over it.
  • The memo lives behind a RefCell. A lint pass runs behind &self — the pull models compute diagnostics inside a map over the open buffers — and the memo is the one thing a pass writes. try_borrow_mut with an early return, so no panic is reachable even if a future caller nests.
  • An unknown rule name in the project's lists is dropped rather than obeyed: see the Work log's "beyond the plan".

Handshakes

Consumed

  • lucisv_core::config::{Discovery, FileConfig, LintOption} — lint_select, lint_ignore, lint_waivers, lint_options (with LintOption::line) and source. Unchanged by this round; source and line are what let a server message name the file and line lucisv check names.
  • vlog_linter::{rules_named, rule_by_name, all_rules, default_rules, workspace_rules, RuleOptions::set_raw, ExternalWaivers::{read, absorb}} — unchanged. set_raw's error text is reused verbatim, so the server's line and the CLI's are the same sentence.
  • crate::settings::ClientSettings — unchanged.

Promised

  • lint::enabled_rules changed signature: enabled_rules(&ClientSettings, &ProjectLint, has_oracle). The only caller outside the module's own tests was LintRun::for_document. A caller that wants the editor-only ladder passes &ProjectLint::default().
  • lint::LintRun::config_problems() -> &ConfigProblems is new, and server::diagnostics is the one place that reports them. A future caller that builds a LintRun outside the diagnostics path (today: the code-action entry in server/dispatch.rs) says nothing, deliberately — one reporter, so the memo cannot be raced by two.
  • lint::waiver_paths keeps its signature and its behaviour (project paths first, then the editor's, resolved as before); server::notification still calls it with a default FileConfig to check the editor's alone.

Requested of others (not done here)

  • README.md, docs/site/src/content/docs/start/configuration.md and docs/repository-analysis.md carry the old sentence. The replacement text is below, for the lead to apply at merge.
  • docs/features/server-lint/README.md line 228 still reads "Not done, deliberately: rule selection. No lucisv.toml lint key…", which was already stale before this round (the key landed in §33) and is now doubly so. Out of this lane's file set; flagged for the lead.

Status / TODO

  • 42.1 project selection into the ladder, editor-when-set-else-project
  • 42.2 rejected project options logged with <file>:<line>: <message>, once per (config file, entry), the lint still running
  • unit tests: the four-way table, severity words in the toml lists, the editor-only rungs over a project selection, the once-only log across three passes, the re-arm on an edited config
  • e2e tests: the project selects / the editor replaces / an emptied setting hands it back; the rejected option logged once over the wire; the CLI and the server asserted equal for three configurations
  • docs text for README / site / repository-analysis (below)
  • topo §2.9-28 struck (lead); finding 2 annotated (lead)
  • QA

Work log

2026-09-05 — dev (Opus 5)

New module crates/lucisv_server/src/lint/project.rs (Rust 2018 lets lint.rs own a lint/ directory), so nothing was added to lint.rs's test block, which already dwarfs its 201 production lines. It holds ProjectLint, ConfigProblems, ProblemLog and their tests.

The ladder as implemented, in lint::enabled_rules:

  1. base = default_on, plus the needs_workspace rules when has_oracle;
  2. pick(lucisv.lint.select, [lint] select) — the editor's list when it is non-empty, else the project's — replaces the base when it names anything;
  3. lucisv.lint.severity.<class> off removes that class (editor only);
  4. lucisv.lint.rules.<name> sets or clears one rule (editor only);
  5. pick(lucisv.lint.ignore, [lint] ignore) removes.

pick is a five-line twin of the CLI's, and rungs 2 and 5 are picked independently — a project that selects and a user who only ignores keep both halves. Every list takes a severity word wherever a rule name fits, the project's as much as the editor's, because both go through vlog_linter::rules_named.

configured now returns its problems instead of let _-ing them away, in lucisv check's wording ({file}:{line}: rule {rule} {error} — the format string is lucisv/src/lint.rs's rule_options, copied deliberately rather than shared, since the two crates are bins and neither can depend on the other). for_document reads the project's waiver files apart from the editor's and keeps the project's problems; the editor's are still said once by notification::apply_settings, so nothing is said twice.

Server::report_config_problems (in server/diagnostics.rs, on the one path that publishes) filters them through ProblemLog and logs the survivors as lucisv: <file>:<line>: <message>; ignored at MessageType::WARNING — window/logMessage, not showMessage: a typo in a checked-in config is not worth a popup on every editor in the project.

Beyond the plan (one addition, deliberate). ProjectLint::read also drops and reports a name in [lint] select / ignore that the registry does not know. The plan named only the rejected [lint.<rule>] entry and the bad waiver directive. The reason for adding it: named() skips an unknown word, so select = ["no-tab"] taken at face value resolves to no rules at all and blanks the file's squiggles, which reads as "lucisv is happy" rather than "lucisv could not read your config" — the same silent-drop failure §42.2 exists to close, one line up. lucisv check fails the run over it; the server drops the name, says it once, and applies the rest of the list (a select left empty by the dropping falls back to the base set, which is the safe direction: some rules rather than none). The message has no line number, because lucisv_core::config records one per [lint.<rule>] entry and not per list element: <toml>: [lint] select: unknown rule: no-tab.

Cost. No new file read per diagnostics pass: the project selection comes out of the FileConfig the pass's single Discovery already produced, and the waiver files are the same files read the same number of times, just in two calls instead of one. The only new work per pass is a DefaultHasher over the config's [lint] entries (a handful of short strings) and a HashMap probe, both of which are skipped entirely when the config has no problems — ConfigProblems::is_empty returns before the memo is touched, which is every buffer in a project whose config is correct.

Files touched (all within the expected set):

  • crates/lucisv_server/src/lint/project.rs (new)
  • crates/lucisv_server/src/lint.rs
  • crates/lucisv_server/src/server/mod.rs (the memo field)
  • crates/lucisv_server/src/server/diagnostics.rs (the one reporter)
  • crates/lucisv_server/tests/e2e.rs (three tests appended)
  • TODO.md (§42's own checkboxes)
  • this README

Docs to apply at merge (lead)

README.md, the two sentences at the end of the linter section (~line 432)

Replace:

The server currently selects rules from lucisv.lint.* editor settings; project [lint] select/ignore lists affect the CLI only. Project per-rule options are read by both front ends.

with:

Both front ends read the same configuration, and the editor's settings play the role the CLI's flags play: lucisv.lint.select when it is set, else [lint] select from the buffer's lucisv.toml, else the default set — and the same for ignore, decided independently. lucisv.lint.severity.* and lucisv.lint.rules.* have no project counterpart and apply over whichever selection stands. Project per-rule options are read by both front ends. A project entry lucisv cannot use — an unknown rule name in [lint] select/ignore, a rejected [lint.<rule>] option, an unreadable waiver file or a directive that does not parse — fails lucisv check with <file>:<line>: <message> and exit 2; in an editor it is dropped, written once to the lucisv log in the same words, and everything lucisv did understand still lints the buffer.

Also, five lines above, the waiver sentence "a bad line in a file named by the editor setting is written once to the lucisv log, one named by lucisv.toml is not (run lucisv check to see it)" becomes:

a bad line is written once to the lucisv log whether the file was named by the editor setting or by lucisv.toml.

docs/site/src/content/docs/start/configuration.md

The Keys table, rows 33–34 — the "Used by" column becomes "CLI and editor":

| [lint].select | string array | defaults | rule names or severity classes | CLI and editor | | [lint].ignore | string array | [] | rule names or severity classes | CLI and editor |

The "Editor settings" paragraph (~line 91) replaces:

For lint selection, the server currently reads editor settings only. Project [lint] select/ignore lists affect the CLI and are not inherited by the server. Selection proceeds through defaults → select → severity switches → per-rule toggles → ignore. Editor rule options overlay project rule options key by key. Invalid editor options are logged and dropped. Invalid project rule-option entries are currently dropped by server linting without a per-entry log; lucisv check reports them as configuration errors.

with:

For lint selection, the editor's settings play the role the CLI's flags play. Selection proceeds through defaults → select → severity switches → per-rule toggles → ignore. select is lucisv.lint.select when that setting is non-empty and the project's [lint] select otherwise; ignore is decided the same way and independently. The severity switches and per-rule toggles are editor-only — a lucisv.toml has no such keys — and apply over whichever selection stands. Editor rule options overlay project rule options key by key. An entry that cannot be used is dropped and logged once per configuration file and entry, in the same <file>:<line>: <message> wording lucisv check fails with: an invalid editor option, an invalid [lint.<rule>] entry, an unknown rule name in [lint] select/ignore, or an unreadable waiver file. lucisv check treats each of these as a configuration error and exits 2; the server keeps linting with the entry dropped.

The Discovery section (~line 57) sentence "A bad configuration is an error for the CLI, preventing partial writes. In an editor, the server reports the problem and falls back to the next available setting." is still true and needs no change.

docs/repository-analysis.md, finding 2

Replace the "The docs now describe the implemented behavior…" paragraph with a fix note in the shape finding 1 already uses:

Fixed by TODO §42 (0.43.0, 2026-09-05): enabled_rules now takes the project's selection beside the editor's and picks the editor's list when it is non-empty, the project's otherwise, key by key — the CLI's pick applied to the editor. Rejected project entries are logged once per (configuration file, entry) as <file>:<line>: <message>, the wording lucisv check fails with, and the buffer is still linted with the entry dropped. Pinned by lint::project's four-way table test and by three wire-level tests in crates/lucisv_server/tests/e2e.rs, one of which asserts the CLI's and the server's rule lists equal for three configurations. See docs/features/lint-config-contract/README.md.

QA log

2026-09-05 — QA (Sonnet)

Read the plan (TODO §42), the finding/handshake it answers (repository- analysis finding 2, docs/topo.md §2.9-28), and this feature's README in full, including the "beyond the plan" deviation (unknown rule names in [lint] select/ignore dropped and logged) and the waiver-file edge (memo keyed by the toml's stamp, not the waiver file's). Read the diffs of lint.rs, the new lint/project.rs, server/diagnostics.rs, server/mod.rs, and the three tests appended to tests/e2e.rs, and the CLI's own lucisv/src/lint.rs (pick, rule_options) and vlog_linter::registry::select_rules/rules_named for the wording and precedence this feature is required to mirror.

Built cargo build --release -p lucisv -p lucisv_server once. Wrote a throwaway attack suite as extra #[test] functions appended to crates/lucisv_server/tests/e2e.rs (never committed to the dev's file — removed before this pass ends; verified by git diff --stat matching the dev's original 205-line insertion both before and after), driving the real server binary over framed JSON-RPC, plus one wire-level test against a real file copied read-only out of opentitan (hw/ip/aes/dv/tb/tb.sv, no write). Two attack tests needed a raw child process with an explicit read/write interleaving (rather than talk()'s single write-then-read-to-EOF) to test disk-edit timing without a race, and to drive a hover request as a synchronization barrier between passes — documented inline while they existed; removed with the rest.

Verified, all as specified:

  • The four-way matrix {toml select ∅/set, editor select ∅/set} × {toml ignore ∅/set, editor ignore ∅/set} over the wire, using a buffer with findings in all three severities (no-tabs/no-trailing-whitespace/ line-length = style, unused-signal/undriven-net = warning, duplicate-declaration = error) rather than the unit test's two rules — every cell matches the documented ladder, and select/ignore are confirmed decided independently (a project select plus a project ignore both apply when the editor names neither).
  • Severity words in the toml's lists (select = ["style"], ignore = ["style"]), including mixed with a rule name in the same list.
  • Rungs 3/4 (editor-only class switch, per-rule toggle) apply over a project selection, including the per-rule word beating the class word (note: the editor's rules.<name> setting takes the string "on"/"off", not a JSON boolean — confirmed against settings.rs's rule_toggles after an initial test mistake).
  • didChangeConfiguration transitions: editor select set then cleared restores the project's; same, independently, for ignore.
  • Nested lucisv.tomls: an outer and an inner buffer in one workspace each follow their own nearest config file. (First attempt used identical buffer text in both files and got [] for the inner buffer — not a product bug: the shared file-scope oracle correctly saw the identically- named unused-signal candidate declared in the other indexed file and suppressed it, docs/features/semantic-lints-on/README.md's documented false-negative-safe direction. Fixed by giving each file's declarations distinct names.)
  • An unknown rule name in [lint] select: dropped, logged once (<toml>: [lint] select: unknown rule: no-tab), the rest of the list still applies, and the buffer keeps being linted — confirmed against lucisv check on the identical config, which exits 2 and prints the same unknown rule: no-tab wording before failing the run. The two front ends' reactions differ by design (a server cannot fail a run); their diagnosis of the same mistake does not.
  • A rejected [lint.<rule>] option (length = "wide"): exactly one window/logMessage across five didChange passes over the same bad config; the message's core (<toml>:<line>: rule <detail>) found verbatim inside lucisv check's own stderr on the identical config (the CLI prepends error: , which the server's log line has no equivalent of — compared by substring, not equality, for that reason); the buffer still linted with the entry dropped. Edited live to a different bad value (length = "-1") mid-session: logged again, once. Then fixed (length = 100): silence from there on. (This needed the raw read/write-interleaved harness — a talk() one-shot builds the whole session string, std::fs::writes included, before the server is even spawned, so every edit would already be on disk before anything runs; used a hover request after each edit as a synchronization barrier, since Server::answer_request flushes the dirty buffer before answering any request.)
  • A bad directive in a waiver file named by [lint] waivers: logged once, naming the waiver file's own path and line, not the toml's.
  • Extra probe beyond the plan, for the README's stated waiver/toml-stamp edge: fixed the waiver file, then brought back the exact same bad line, toml untouched throughout — not logged a second time, confirming the memo really is keyed by exact message text under an unchanged toml stamp, not merely "one waiver problem per session" in some coarser sense. Contrast: two different bad lines in the same unedited-toml waiver file during one session are each logged once (not suppressed by the first) — consistent with ProblemLog's BTreeSet<String> keyed by message text, not a defect, but worth the lead/dev knowing the precise grain the "once per session" sentence in Assumptions describes.
  • CLI/server rule-set equality: five configurations (none, an explicit select, select=["style"] + one ignored, ignore=["style"], a select containing an unknown name) plus one real file copied read-only out of opentitan (hw/ip/aes/dv/tb/tb.sv, no lucisv.toml in that repo, so a scratch one governed the copy) — server and CLI rule-code sets equal in every case.
  • Robustness: select = [] (explicit empty) falls back to the base set, same as absent; duplicate names in select collapse harmlessly; a name in both select and ignore ends up ignored (ignore is the top rung); a [lint] key the parser rejects outright fails parse() entirely, which the CLI turns into an exit-2 run failure and the server (via the pre-existing .ok() fallback in configured, unchanged by §42) swallows into defaults across several passes with zero log lines — confirmed it does not newly start logging under this feature.
  • Performance: 20 consecutive diagnostics passes over a 2000-line buffer with a valid config, this server against a 0.42.0 server built in a scratch worktree (git worktree add .../scratchpad/base v0.42.0, removed with git worktree remove before finishing). Three runs: ratios 0.985, 1.001, 0.983 (new server negligibly faster or equal, never slower) — no measurable regression, as the README's cost analysis claims.
  • Gates, guarded: cargo clippy --all-targets clean; cargo test --workspace — 3780 passed, 0 failed (matches the dev's count exactly); tools/corpus_check.sh — 814/820 (99.3%), the same six pre-existing parse errors; node editors/vscode/smoke.js target/release/lucisv-server — OK.
  • git -C /Users/guoliangchen/repo/opentitan status --porcelain after use: unchanged, the same three pre-existing modified files (hw/ip/aes/dv/tb/tb.sv, the two ast.svs) as before this session — no lucisv.toml was written there.

Findings.

  • LOW, pre-existing, not introduced by §42 — a didChange sent in the same message burst as shutdown is never flushed: lsp_server:: Connection::handle_shutdown (called from crates/lucisv_server/src/server/mod.rs's process_batch) answers shutdown directly, bypassing Server::answer_request's flush_dirty(). A dirty buffer's last edit is silently dropped — no republish, no config-problem log for that pass — if the client shuts down before the 150ms CHANGE_DEBOUNCE fires or before another request arrives. This interacts with §42's own "a lucisv.toml edited on disk takes effect at the next publish" claim: that claim holds only when some republish actually happens before the session ends, which is not the same as saying the edit's diagnostics are guaranteed to reach the client at all in a fast open-edit-shutdown session. Reproduced in the (removed) attack test by sending a didChange immediately before shutdown in one write and observing zero further publishes; fixed the test by sleeping past the debounce instead of treating it as a §42 bug, since the behavior predates this feature and is a property of the lsp-server crate's own shutdown handling, not of anything lint.rs/lint/project.rs changed. Not a §42 regression; flagging for whoever owns change-debounce next.
  • LOW, pre-existing, not introduced by §42 — an unknown name in the editor's lucisv.lint.select/ignore is silently dropped at settings-parse time (crates/lucisv_server/src/settings.rs's rules, called from from_payload), with no log line — unlike lucisv.lint. options, whose rejected entries are logged (lint_option_warnings). §42 makes the project side of the same mistake ([lint] select/ ignore in lucisv.toml) both dropped and logged (the "beyond the plan" addition in the Work log), which is more informative than the editor's own settings for the identical typo. Not this feature's handshake to fix (ClientSettings is unchanged by §42) and not asked for by the plan, but the asymmetry is now sharper than before this round landed; worth a line in the lead's notes for a future pass over settings.rs.
  • No correctness, idempotency, or comment-preservation issues found; no masked-corruption concern applies (this feature touches lint configuration, not verify.rs's forgiveness).

Verdict: PASS. No blocking findings. The two LOW findings above are pre-existing behavior outside this feature's stated handshakes, not regressions introduced by §42; recorded for whoever picks them up next. Ticked TODO §42's QA checkbox and this feature's own Status / TODO "QA" line.

Review

2026-09-05 — lead. Accepted; ships in 0.43.0. The contract is the ruled one and it is now the same sentence on both front ends: the editor's list when set, else the project's, key by key, with the editor-only rungs applied over whichever stands — and the wire-level equality test is what makes that a fact rather than a description. The dev's one step beyond the plan (dropping and logging an unknown rule name in a project list) is accepted: an editor cannot fail the run, and a typo that silently resolves to "no rules" reads as a clean file, which is the wrong kind of quiet. The once-only memo keyed by config content is the right shape for a server with no config generation; its stated edge (a waiver file's bad line under an unchanged toml is said once per session) is acceptable and documented. QA's two LOWs are pre-existing and out of scope; the second — an unknown name in the editor's lucisv.lint.select still silently dropped — is worth a line in a later round and is filed in topo §2.9 as item 29. Docs applied to README, the linter guide, configuration.md, the analysis and topo.