Files
lucisv/docs/features/editor-settings
lucioandClaude Fable 5 9a3a92cabb Expose vfmt.toml settings in VS Code: vfmt.lineLength, vfmt.indent, vfmt.exclude
All three vfmt.toml keys, pushed over workspace/didChangeConfiguration
(initial push verified against the real vscode-languageclient 9.0.1).
Precedence: vfmt.toml > vfmt.* settings > editor tabSize > built-in
default — a checked-in config stays authoritative so format-on-save never
diverges from CI. Invalid values are ignored, never clamped or coerced;
exclude is appended to the config's excludes and re-indexes the workspace
on change. Untitled buffers and toml-less projects gain an editor-set
line length, previously impossible over LSP.

Co-Authored-By: Claude Fable 5 <[email protected]>
2026-08-24 03:15:54 -07:00
..

editor-settings

Goal

Expose the three keys vfmt.toml supports — line-length, indent, exclude — as VS Code settings (vfmt.lineLength, vfmt.indent, vfmt.exclude), for the users who asked for them: people with no config file checked into the tree, who until now could set the indent only by accident (VS Code's tabSize leaked in through FormattingOptions) and could not set a line length at all, because LSP carries no line-length option. The settings are transported by workspace/didChangeConfiguration, validated at the server, and folded in one rung below a vfmt.toml — which stays authoritative, so a project that checks one in keeps exactly one source of truth and format-on-save cannot drift from CI's vfmt --check.

Assumptions

  • vfmt.toml has exactly three keys, and that is the whole surface. vfmt_core::config::parse_entry accepts line-length, indent and exclude and rejects everything else by name. Rule selection (--select/--ignore) has no config key yet, so there is nothing to expose for the linter; when it grows one, it grows a setting here in the same shape.
  • A repository outranks an editor. The precedence decision (below) is the one thing in this feature that is a judgement call rather than mechanics. It extends the reasoning format::settings_for already carried for tabSize: the further a setting is from the code it governs, the less it should win.
  • Nothing the client sends is trusted. package.json's JSON schema bounds the settings UI, but the notification is JSON on a socket and other editors have no schema at all — the Neovim setup in editors/nvim/README.md writes the same section by hand. Out-of-range, wrong-typed and missing values are all dropped, leaving that rung silent. Same philosophy as the existing tabSize guard: honouring half of a nonsensical request is worse than ignoring it.
  • The accepted ranges must match vfmt.toml's. A value has to be exactly as acceptable from the settings UI as it is in a config file, or the two front ends would disagree about what is valid. vfmt_core exports no constant for its bounds, so settings.rs copies them and the_accepted_ranges_are_the_ones_vfmt_toml_accepts checks the copy against the real parser (vfmt_core::config::parse) rather than against another hard-coded number. If a range ever widens in vfmt_core, that test fails.
  • Only exclude can invalidate anything. lineLength and indent are read afresh by every formatting request, so a change to them needs no cache work at all. exclude changes which files exist as far as the workspace index is concerned, so it — and only it — triggers a rescan.
  • A non-integral number cannot arrive from VS Code. JavaScript serializes 4.0 as 4, so serde_json's as_u64 rejecting fractions costs nothing real; there is no "close enough" case worth forgiving.
  • The vfmt.exclude patterns are matched by the same engine as the config's. They are appended to the same Vec<String> that reaches vfmt_core::walk::collect_files, so the glob syntax, the trailing-component matching and the .gitignore interaction are whatever the CLI already does. An empty-string pattern is harmless (walk::matches returns false for one), so it is not filtered out.

Handshakes

The precedence ladder (the contract this feature is)

Highest first. Each rung applies only where every rung above it is silent, and each key climbs independently — a vfmt.toml naming only indent leaves vfmt.lineLength in charge of the width.

# Source Why here
1 vfmt.toml The project speaking. Must stay authoritative or format-on-save disagrees with vfmt --check in CI — the divergence that lifting the config into vfmt_core exists to remove.
2 vfmt.lineLength / vfmt.indent Typed on purpose into a settings UI, so more deliberate than a tab size — but it is one user's editor, and the repository outranks it.
3 FormattingOptions::tab_size Sent on every request whether or not the user ever chose it (it is the editor's default, or its guess from the file). The weakest thing that is still a signal.
4 Built-in defaults indent 2, width 100.

Two paths use a shortened ladder, and both are unchanged in spirit:

  • format::indent_width (the no-tabs quick fix) has no rung 3 — a textDocument/codeAction request carries no FormattingOptions.
  • Rung 1 is absent for an untitled: buffer, which has no directory to discover a config from. Such a buffer therefore honours rung 2 now, where before it had only the tab size.

A broken vfmt.toml contributes nothing at all (as before), so rung 2 is what answers under it — the user still gets the warning, and still gets their settings.

The wire shape

Consumed: workspace/didChangeConfiguration, whose settings field carries

{ "settings": { "vfmt": { "lineLength": 120, "indent": 4, "exclude": ["vendor"] } } }

settings.rs::from_payload reads settings.vfmt and nothing else. A payload without that section — including the {"settings": null} form — means "no opinion about anything" and resets every key. Keys may be absent, null, or garbage; each is dropped independently.

Verified against the real client library, not assumed (the plan required this): [email protected], node_modules/vscode-languageclient/lib/common/configuration.js. Its SyncConfigurationFeature.initialize() registers when clientOptions.synchronize.configurationSection is set, and register() ends with an unconditional this.onDidChangeConfiguration(section, undefined) — with event === undefined the affectsConfiguration filter is skipped, so the notification is sent immediately at startup as well as on every later change. No initializationOptions fallback is needed, and none was added. extractSettingsInformation(['vfmt']) calls workspace.getConfiguration(undefined).get('vfmt'), which returns the whole section with every key at its effective value — so the server sees serverPath and rainbowBeginEnd in the payload too, and ignores them.

Other editors: anything that can send workspace/didChangeConfiguration with that settings shape works. Neovim's vim.lsp.config sends its settings table verbatim, so settings = { vfmt = { indent = 4 } } is the whole setup.

Within the server

  • Consumed from vfmt_core: config::parse (in a test, to pin the ranges), config::FileConfig, walk::collect_files's exclude parameter.
  • Promised to state.rs: Workspace::client_settings() and set_client_settings(), the latter returning true exactly when the caller must rebuild_index().
  • Promised to server.rs: settings::from_payload. The DidChangeConfiguration arm is the only caller.
  • Changed signatures (all callers updated in the same change): format::settings_for(doc, client, options), format::indent_width(path, client), and the private format::config_from(file, client, options).

Request to the lead (outside this feature's scope, unchanged from M2/M3): docs/features/vfmt-server/README.md and TODO.md §6 still understate the server (documentHighlight, the missing-closer diagnostics, vfmt/scopePairs, and now these settings). Separately, docs/features/editor-packaging/README.md's What was deliberately left out table has a row reading "Settings beyond serverPath — formatter options belong in vfmt.toml, one source of truth", which this feature supersedes: the one-source-of-truth rule is now enforced by precedence rather than by absence. editors/vscode/README.md said the same thing and was updated here, because this feature owns that file's settings table.

Status / TODO

  • settings.rs: ClientSettings, from_payload, validation.
  • Workspace stores them; set_client_settings reports whether a rescan is needed.
  • Folded into settings_for / config_from / indent_width.
  • exclude appended to the workspace scan's excludes; a change rebuilds the index and republishes.
  • extension.js synchronize.configurationSection: 'vfmt'; initial-push behaviour verified against the library source.
  • Three settings in package.json with schema bounds.
  • editors/vscode/README.md settings table and precedence ladder.
  • Tests: precedence per rung, invalid values, exclude append, mid-session change (e2e), untitled buffers, smoke.js.
  • Not done, deliberately: no per-language or per-folder override ([verilog]-scoped settings). VS Code resolves those per resource, and the server holds one workspace-wide ClientSettings; a vfmt.toml is the per-directory mechanism and it already works.
  • Not done, deliberately: no workspace/configuration pull. The push arrives at startup and on every change, which is all that is needed; pulling would add a request per document to answer the same question.
  • Not done, deliberately: no setting for lint rule selection — there is no vfmt.toml key for it yet, and inventing one here would put the editor ahead of the CLI.

Work log

2026-08-24 — M4: vfmt.toml's three keys as VS Code settings

The thing that had to be checked first. The plan said to verify, not assume, whether [email protected]'s synchronize emits an initial push — because if it did not, the settings would only reach the server after the user edited them, and the whole feature would look broken on a fresh window. Read lib/common/configuration.js in node_modules: initialize() registers the section, and register() unconditionally calls onDidChangeConfiguration(section, undefined), whose undefined event skips the affectsConfiguration filter and sends the notification straight away. It does push at startup, so no initializationOptions fallback was added. The finding, with file and function names, is in Handshakes so the next person does not have to re-derive it.

Server. New settings.rs — ClientSettings plus from_payload, which is all the validation. Workspace gained the field, a getter, and set_client_settings returning "you must rescan", which is true only for exclude. format.rs grew one rung in the ladder, written weakest-first so the last writer wins and the code reads in the same order as the doc comment. server.rs gained the DidChangeConfiguration arm and a small reindex() helper, since rebuild-and-republish now has two callers (a save, and a new exclude); the comment on the save path saying the index is rebuilt "on save and nowhere else" was true before this change and is now corrected rather than left to rot.

Two decisions worth recording.

  1. Settings sit below vfmt.toml, not above. This is the opposite of the CLI's flag-beats-config order, and it is the same call settings_for already made for tabSize, for the same reason: a CLI flag is typed for one run, while an editor setting persists silently and belongs to one machine. If a vfmt.lineLength of 80 could override a project's line-length = 120, every save would reflow files that CI then rejects. Pinned by rung_1_a_config_file_beats_a_pushed_setting.
  2. Ranges are checked against the real config parser. Copying 40..=400 and 1..=8 into settings.rs is a duplication hazard —vfmt_core exports no constant, and CLAUDE.md says not to reach into another module for this feature's convenience. Rather than leave the copy unguarded, the test asks vfmt_core::config::parse whether each edge is accepted. That is strictly better than a shared constant would have been: it tests the behaviour, not the number.

Tests. 190 unit (was 177) and 9 e2e (was 7) in this crate:

  • format.rs — one test per rung of the ladder, plus each-key-independence, a broken config falling through to rung 2, the untitled buffer, the quick-fix path's shortened ladder, and the capability that did not exist before: a_pushed_line_length_is_the_only_way_to_set_a_width_without_a_config asserts the text actually reflows, not just that a number was stored.
  • settings.rs — the exact VS Code payload shape at its defaults (must be "no opinion"), out-of-range numbers, wrong types, a non-array exclude, a mixed array, a payload with no vfmt section, settings: null, and the range cross-check above.
  • state.rs — a pushed exclude hiding a file from the index; appended, not substituted, so a user's setting cannot put the project's vendored code back in the index for them alone; and that only an exclude change asks for a rescan.
  • tests/e2e.rs — pushed_settings_reach_the_formatter_and_can_change_mid_session drives five formats over one session: tab size → pushed 4 → pushed 8 → back to null → a garbage payload, asserting the emitted text each time. This is the mid-session requirement and the ignore-invalid requirement in one place. a_pushed_exclude_rebuilds_the_index_mid_session covers the one link no unit test can reach — that the notification handler re-scans — by watching workspace/symbol hits appear and disappear as the setting is pushed and cleared. It was written after a hand-driven session proved the path worked; the check is worth keeping, because a set_client_settings that returned false for exclude would break this silently and nothing else would notice.
  • smoke.js — pushes indent: 4 in the real payload shape while asking for tabSize: 2, and asserts the returned edit is 4-space indented. Mutation-checked: changing the pushed value to null fails the assertion with the 2-space output, so it is live rather than vacuous.

Deviations from the plan. None on substance. Two notes: (a) the plan allowed the mid-session test to be a unit test "if the harness does not support notifications" — it does, so it is an e2e; (b) the plan's conditional initializationOptions fallback was not implemented, because the verification it was conditioned on came back negative-for-need (the library does push).

Verification. cargo fmt --all clean, cargo clippy --all-targets clean, cargo test --workspace green, node smoke.js against a freshly built target/debug/vfmt-server OK, npx @vscode/vsce ls still accepts the manifest, node --check on both JS files.

QA log

2026-08-24 — round 3, Sonnet QA (M4)

Scope: the uncommitted working tree only (git diff/status vs HEAD; everything through aa26e5e already QA'd). Verified settings.rs, format.rs, state.rs, server.rs, main.rs, tests/e2e.rs, extension.js, package.json, smoke.js, editors/vscode/README.md, and this README.

1. Precedence ladder. Read every rung's test in format.rs (rung_1.. rung_4, each_key_climbs_the_ladder_independently, a_broken_config_leaves_the_pushed_settings_in_charge, an_untitled_buffer_honours_pushed_settings). Every mixed case the charter named is present and passes: toml-names-indent-only + settings-names-lineLength- only (each_key_climbs_the_ladder_independently); settings-indent vs. differing tabSize (rung_2_a_pushed_setting_beats_the_editors_tab_size); a broken vfmt.toml falls through to the pushed settings (rung 2), not straight to default — pinned by format.rs:499 and documented, not just tested: the Handshakes section states it explicitly ("A broken vfmt.toml contributes nothing at all... so rung 2 is what answers under it"). No undocumented hole found.

2. Validation hostility. Every value the charter listed (indent 0, 9, -1, 400.5-equivalent via 4.5, "4" string; lineLength 39, 401, 39.9-equivalent; exclude as a string, exclude with non-string entries; settings: null; missing vfmt section; extra unknown keys) is covered in settings.rs's unit tests. Went further and hand-drove the built binary (not just unit tests) with a script sending all of the above plus indent: 400.5, lineLength: 39.9, exclude: [1,2,3], a params with no settings key at all, and a payload mixing valid siblings (indent: 4, lineLength: 120) with an unknown nested key and a dirty exclude array — the server processed the whole session, kept the valid siblings (final format came back 4-space indented, confirming lineLength/indent both survived alongside the garbage), and answered shutdown cleanly. No panics anywhere in the pipeline (deserialization included, not just from_payload).

3. exclude append + re-index + republish. state.rs unit tests (a_pushed_exclude_is_appended_to_the_configs_and_does_not_replace_it, only_an_exclude_change_asks_for_a_rescan) correctly prove append-not-replace and the "only exclude triggers rescan" contract.

Finding (non-blocking, test-coverage gap): crates/vfmt_server/tests/e2e.rs:690-746 (a_pushed_exclude_rebuilds_the_index_mid_session) opens no document — it only drives workspace/symbol queries before/after the exclude push. That proves the scan half of reindex() (server.rs:319-324) ran, but nothing in this test, or anywhere else in the diff, asserts the republish half: that self.publish(&uri) actually fires a new textDocument/publishDiagnostics for an open buffer when an exclude-triggered rebuild — as opposed to a didSave-triggered one — happens. The dev's own work-log entry is honest about this ("covers... that the notification handler re-scans"); it does not claim the republish is covered, and it isn't. Traced the actual runtime impact: diagnostics::all() (diagnostics.rs:26-31) composes parse diagnostics, missing-end diagnostics and lint diagnostics — none of which read doc.external or the workspace index. Only hover.rs:106 and nav.rs:16 consume doc.external. So today a republish after an exclude change is content-identical to the previous publish for any open buffer whose own text didn't change; the only observable proof available to a test is that a second publishDiagnostics notification for that uri was sent at all (or, more usefully, that a goto-definition/hover result for an open buffer changes after the exclude flips a file in or out of the index — that would exercise doc.external and be a stronger test than diagnostics republish). This reindex() helper and its two callers are not new logic invented for this gap — the rebuild+republish loop already existed for didSave before this diff and had (and still has) no e2e assertion of its own either, so this is not a regression this feature introduced, just a required test from the plan ("exclude... change triggers re-index + republish... e2e") that is not actually closed. Suggested fix for the dev: extend a_pushed_exclude_rebuilds_the_index_mid_session (or add a sibling test) that opens a buffer referencing a symbol in the file being excluded/un-excluded and asserts a goto-definition (or a second publishDiagnostics) reflects the change, so the republish half has a real assertion rather than an implicit one.

4. The real client library claim. Read editors/vscode/node_modules/vscode-languageclient/lib/common/configuration.js directly (installed version confirmed 9.0.1 via node_modules/vscode- languageclient/package.json). SyncConfigurationFeature.initialize() (line 109) registers when clientOptions.synchronize.configurationSection is set; register() (line 121-128) ends with an unconditional this.onDidChangeConfiguration(data.registerOptions.section, undefined) — the event === undefined case skips the affectsConfiguration filter, so the notification is sent immediately. Confirmed: the dev's claim is accurate, and so is the wire shape claim — extractSettingsInformation(['vfmt']) (line 174-207) calls workspace.getConfiguration(undefined).get('vfmt') and wraps it under result.vfmt, i.e. exactly {settings: {vfmt: {...every declared key at its effective value...}}}, matching settings.rs's vscode_payload() test helper and the README's documented shape. extension.js's synchronize: { configurationSection: 'vfmt' } and package.json's three new properties are all spelled vfmt.lineLength / vfmt.indent / vfmt.exclude — the prefix matches. No mismatch found.

5. smoke.js. Built fresh with cargo build -p vfmt_server, ran node smoke.js ../../target/debug/vfmt-server — OK. Mutation-checked the pushed-indent assertion: changed indent: 4 to indent: 2 in the didChangeConfiguration push, reran — got a clean FAIL reporting the 2-space (tabSize) output instead of 4-space, confirming the assertion is live; restored the edit and reran — OK again, and md5sum before/after the round-trip matched byte-for-byte (a33792c93538b89b8d64debe117f2ab1).

6. Untitled buffers. format.rs's an_untitled_buffer_honours_pushed_settings pins both vfmt.indent and vfmt.lineLength applying with no path and no toml. Confirmed.

7. Invariants.

  • cargo test --workspace: all green, including vfmt_server's 190 unit + 9 e2e (matches the work log's claimed counts).
  • cargo fmt --all -- --check: clean.
  • cargo clippy --all-targets: clean (touched settings.rs to force a recheck rather than trust a stale cache; still clean).
  • node --check on both extension.js and smoke.js: OK. package.json parses as JSON.
  • git diff --stat HEAD -- crates/vlog_formatter crates/vlog_parser crates/verify: empty — nothing under those paths touched.
  • No unwrap()/expect()/panic! in the non-test portions of settings.rs, format.rs, state.rs, server.rs (grepped each file up to its #[cfg(test)] marker).
  • package.json schema bounds (minimum/maximum 40/400 and 1/8) cross-checked against settings.rs's LINE_LENGTH_RANGE/INDENT_RANGE and against vfmt_core::config::parse_entry (crates/vfmt_core/src/config.rs:56-57, which is the real source of truth) — all three agree.
  • Cross-checked the "exclude append mirrors the CLI" claim in Assumptions against crates/vfmt/src/args.rs:103-107 (exclude_with) — the CLI does extend its own --exclude with the config's, same append-not-replace pattern. Accurate.

Verdict: PASS. One finding, non-blocking (test-coverage gap in the exclude-republish e2e path, item 3 above) — the underlying behavior was independently verified by code reading to be correct and shares its implementation with the already-shipped didSave path, so this is a request to close a documented required test, not a functional defect.

Review

2026-08-24 — lead review of M4 (after QA round 3)

Read settings.rs in full plus the format.rs, server.rs, state.rs and extension.js diffs. Approved and committed. Notes:

  • Settings-below-vfmt.toml is the right call and the rewritten settings_for ladder doc states it well; the the_accepted_ranges_are_the_ones_vfmt_toml_accepts test (asking the real parser about the copied bounds) is a pattern worth reusing.
  • QA's non-blocking finding stands: the exclude e2e proves the rescan but not the republish half of reindex(). Functionally moot today (nothing in diagnostics::all reads the index), so accepted as-is; the next round touching e2e.rs should close it per QA's suggested fix.
  • extractSettingsInformation sending the whole vfmt section (so the server sees and ignores serverPath/rainbowBeginEnd) is correctly mirrored in the tests' payload shape rather than an idealized one.