TODO section 28, lane C (the file-size rule in CLAUDE.md).
server.rs (2 559 production + 6 293 test lines) becomes server/{mod,
dispatch, client, index, notification, progress, diagnostics, batch,
formatting, large_file, semantic_tokens}.rs with the tests in
server/tests/ (16 files, one per former banner section, 15 shared
helpers hoisted into the harness); completion.rs (1 716 + 2 463)
becomes completion/{mod, member, module, tiers, word, site,
harness}.rs with each provider's tests beside it. answer_request (393)
and handle_notification (197) stay whole as the dispatch tables they
are; perf.rs stays whole because its one sentence has no and. Every
import elsewhere in the crate resolves through pub(crate) re-exports,
so main.rs, inline.rs, instantiate.rs, hover.rs, nav.rs and state.rs
are byte-identical. Proof: per-binary counts identical (1 435 / 85 / 3;
workspace 3 215 / 48), e2e and the vsix smoke green, a live LSP session
against opentitan answering byte-identically from this build and the
base, and a line-multiset + signature census (360/360, 188/188) done
by the dev and redone from scratch by QA.
docs/features/decomposition-server/README.md.
Co-Authored-By: Claude Fable 5 <[email protected]>
411 lines
18 KiB
Rust
411 lines
18 KiB
Rust
//! Pulled settings (2026-08-27): `workspace/configuration` beside the push.
|
|
|
|
use super::*;
|
|
use crate::settings;
|
|
|
|
// ------------------------------------------------------------------
|
|
// pulled settings (2026-08-27)
|
|
// ------------------------------------------------------------------
|
|
|
|
/// A client that answers `workspace/configuration`.
|
|
fn pulling_settings() -> ClientAbilities {
|
|
ClientAbilities { configuration: true, ..Default::default() }
|
|
}
|
|
|
|
#[test]
|
|
fn a_client_that_can_be_asked_is_asked_for_its_settings_at_startup() {
|
|
let tree = Tree::new("pullstartup");
|
|
tree.package("rtl/a.sv", "a");
|
|
let session = Session::with(vec![tree.path.clone()], pulling_settings());
|
|
let (_id, params) = configuration_request(&session);
|
|
assert_eq!(
|
|
params,
|
|
serde_json::json!({ "items": [{ "section": "lucisv" }] }),
|
|
"one item, our section, no scope"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn the_startup_pull_is_sent_after_the_watcher_registration_on_the_wire() {
|
|
// `Server::new` calls `register_watchers` and then
|
|
// `request_configuration`, in that order — this pins it on the actual
|
|
// wire rather than trusting the call order in the source. Every
|
|
// outgoing request's id is `lucisv-{n}` off one monotonically
|
|
// increasing counter, so the numeric suffix *is* the send order.
|
|
// QA (2026-08-27): pinned per the dev's own review checklist item
|
|
// ("verify on the wire").
|
|
let tree = Tree::new("pulloraftwatch");
|
|
let abilities =
|
|
ClientAbilities { file_watching: true, configuration: true, ..pulling_settings() };
|
|
let session = Session::with(vec![tree.path.clone()], abilities);
|
|
let sent = session.sent();
|
|
let index_of = |method: &str| -> usize {
|
|
sent.iter()
|
|
.position(|r| r.method == method)
|
|
.unwrap_or_else(|| panic!("no {method} in {sent:#?}"))
|
|
};
|
|
let watchers = index_of(RegisterCapability::METHOD);
|
|
let pull = index_of(WorkspaceConfiguration::METHOD);
|
|
assert!(watchers < pull, "watcher registration must precede the pull: {sent:#?}");
|
|
|
|
let numeric_suffix = |request: &Request| -> u32 {
|
|
request
|
|
.id
|
|
.to_string()
|
|
.trim_matches('"')
|
|
.trim_start_matches("lucisv-")
|
|
.parse()
|
|
.unwrap_or_else(|_| panic!("not a lucisv-N id: {:?}", request.id))
|
|
};
|
|
assert!(
|
|
numeric_suffix(&sent[watchers]) < numeric_suffix(&sent[pull]),
|
|
"the pull's id must be issued after the watcher registration's: {sent:#?}"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn a_client_that_cannot_be_asked_is_never_asked() {
|
|
// Every client that predates this — `smoke.js` included — sends
|
|
// `capabilities: {}` and must see nothing new at all.
|
|
let tree = Tree::new("pullnone");
|
|
let session = Session::new(vec![tree.path.clone()], false);
|
|
assert!(session.requests().is_empty(), "{:#?}", session.requests());
|
|
}
|
|
|
|
#[test]
|
|
fn a_pulled_answer_reaches_the_formatter_through_the_same_parser_a_push_uses() {
|
|
let tree = Tree::new("pullapply");
|
|
let mut session = Session::with(vec![tree.path.clone()], pulling_settings());
|
|
let uri = session.open(&tree.path.join("m.sv"), "module m;\nwire a;\nendmodule\n");
|
|
let (id, _) = configuration_request(&session);
|
|
|
|
// The editor's tab size, until the client answers.
|
|
assert_eq!(
|
|
formatting_result(&mut session, &uri)[0]["newText"],
|
|
serde_json::json!("module m;\n wire a;\nendmodule\n")
|
|
);
|
|
|
|
// The answer is an array with one entry per requested item, and the
|
|
// entry is the *section*, not the `{lucisv: ...}` wrapper a push has.
|
|
session.answer(id, serde_json::json!([{ "indent": 4, "lineLength": 120 }]));
|
|
assert_eq!(
|
|
formatting_result(&mut session, &uri)[0]["newText"],
|
|
serde_json::json!("module m;\n wire a;\nendmodule\n"),
|
|
"the pulled indent is in force"
|
|
);
|
|
assert_eq!(session.server.workspace.client_settings().line_length, Some(120));
|
|
}
|
|
|
|
#[test]
|
|
fn a_pulled_answer_that_changes_the_scope_rebuilds_the_index() {
|
|
// The pull applies through the same path a push does, so an `exclude`
|
|
// that arrives this way must cost the same rescan.
|
|
let tree = Tree::new("pullexclude");
|
|
tree.package("rtl/a.sv", "a");
|
|
tree.package("scratch/wip.sv", "scratch_pkg");
|
|
let mut session = Session::wide_with(vec![tree.path.clone()], pulling_settings());
|
|
assert_eq!(indexed(&session, "scratch_pkg"), 1, "premise: indexed at first");
|
|
|
|
let (id, _) = configuration_request(&session);
|
|
// The pulled section carries the scope for the same reason a pushed
|
|
// one does: an answer is the *whole* section, so leaving it out would
|
|
// narrow the index in the same breath as the exclude.
|
|
session.answer(
|
|
id,
|
|
serde_json::json!([{ "exclude": ["scratch"], "index": { "scope": "workspace" } }]),
|
|
);
|
|
assert_eq!(indexed(&session, "scratch_pkg"), 0, "the pulled exclude took effect");
|
|
assert_eq!(indexed(&session, "a"), 1, "and nothing else moved");
|
|
}
|
|
|
|
#[test]
|
|
fn a_pulled_filelist_re_registers_the_watchers_through_the_same_chain_a_push_uses() {
|
|
// `apply_settings` is the one function both doors go through, but
|
|
// nothing pinned it for the *pull* path specifically before this: the
|
|
// answer changing `lucisv.filelist` must move `filelist_path()` and
|
|
// cost a watcher re-registration exactly as a pushed one does.
|
|
// QA (2026-08-27): pinned per the dev's own review checklist item
|
|
// ("the full chain: pull answer -> apply_settings -> filelist moved
|
|
// -> re-register").
|
|
let tree = Tree::new("pullfilelistwatch");
|
|
tree.package("rtl/a.sv", "a");
|
|
tree.write("files.f", "rtl/a.sv\n");
|
|
let abilities =
|
|
ClientAbilities { configuration: true, file_watching: true, ..Default::default() };
|
|
let mut session = Session::with(vec![tree.path.clone()], abilities);
|
|
// Drains the startup watcher registration and the startup pull's own
|
|
// request together; `configuration_request` needs only the latter.
|
|
let (id, _) = configuration_request(&session);
|
|
|
|
session.answer(id, serde_json::json!([{ "filelist": "files.f" }]));
|
|
let requests = session.requests();
|
|
assert_eq!(requests.len(), 2, "{requests:#?}");
|
|
assert_eq!(requests[0].0, UnregisterCapability::METHOD, "the old registration first");
|
|
assert_eq!(requests[1].0, RegisterCapability::METHOD);
|
|
assert_eq!(
|
|
requests[1].1["registrations"][0]["registerOptions"]["watchers"][1]["globPattern"],
|
|
tree.path.join("files.f").to_str().expect("utf-8").to_string(),
|
|
"{requests:#?}"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn an_unusable_pull_answer_leaves_the_defaults_and_says_nothing() {
|
|
// Nothing here is the user's fault and nothing here is actionable, so
|
|
// every one of these must be as quiet as a client that answered
|
|
// `null` — which is what the spec asks a client without the section
|
|
// to do.
|
|
let tree = Tree::new("pulljunk");
|
|
for answer in [
|
|
serde_json::json!(null),
|
|
serde_json::json!([]),
|
|
serde_json::json!([null]),
|
|
serde_json::json!("lucisv"),
|
|
serde_json::json!({ "indent": 4 }),
|
|
serde_json::json!([{ "indent": "four", "exclude": 7 }]),
|
|
serde_json::json!([{ "lucisv": { "indent": 4 } }]),
|
|
] {
|
|
let mut session = Session::with(vec![tree.path.clone()], pulling_settings());
|
|
let (id, _) = configuration_request(&session);
|
|
session.answer(id, answer.clone());
|
|
assert_eq!(
|
|
session.server.workspace.client_settings(),
|
|
&settings::ClientSettings::default(),
|
|
"the answer {answer} must leave the defaults"
|
|
);
|
|
assert!(session.shown().is_empty(), "and must not open a popup");
|
|
}
|
|
|
|
// An error response is the same news, said differently.
|
|
let mut session = Session::with(vec![tree.path.clone()], pulling_settings());
|
|
let (id, _) = configuration_request(&session);
|
|
session.server.response(Response::new_err(
|
|
id,
|
|
lsp_server::ErrorCode::MethodNotFound as i32,
|
|
"no configuration here".to_string(),
|
|
));
|
|
assert_eq!(session.server.workspace.client_settings(), &settings::ClientSettings::default());
|
|
assert!(session.shown().is_empty(), "a refused pull is not worth a popup");
|
|
}
|
|
|
|
#[test]
|
|
fn an_empty_push_pulls_instead_of_resetting_everything_to_default() {
|
|
// The modern client's "something changed, ask me for what you need".
|
|
// Applying it as a payload would silently clear the settings it just
|
|
// told us to come and fetch.
|
|
let tree = Tree::new("pushempty");
|
|
let mut session = Session::with(vec![tree.path.clone()], pulling_settings());
|
|
let (id, _) = configuration_request(&session);
|
|
session.answer(id, serde_json::json!([{ "indent": 4 }]));
|
|
assert_eq!(session.server.workspace.client_settings().indent, Some(4), "premise");
|
|
|
|
for empty in [serde_json::json!({ "settings": {} }), serde_json::json!({ "settings": null })] {
|
|
let _ = session.drain();
|
|
session.notify(DidChangeConfiguration::METHOD, empty.clone());
|
|
assert_eq!(
|
|
session.server.workspace.client_settings().indent,
|
|
Some(4),
|
|
"{empty} must not clear what was pulled"
|
|
);
|
|
let (id, _) = configuration_request(&session);
|
|
session.answer(id, serde_json::json!([{ "indent": 8 }]));
|
|
assert_eq!(session.server.workspace.client_settings().indent, Some(8), "{empty}");
|
|
// Put it back for the next round.
|
|
session.server.workspace.set_client_settings(settings::ClientSettings {
|
|
indent: Some(4),
|
|
..Default::default()
|
|
});
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn an_empty_push_to_a_client_that_cannot_be_asked_still_means_no_opinion() {
|
|
// The legacy path, unchanged: with nobody to ask, an empty payload is
|
|
// what it has always been — no opinion about anything.
|
|
let tree = Tree::new("pushemptylegacy");
|
|
let mut session = Session::new(vec![tree.path.clone()], false);
|
|
session.notify(
|
|
DidChangeConfiguration::METHOD,
|
|
serde_json::json!({ "settings": { "lucisv": { "indent": 4 } } }),
|
|
);
|
|
assert_eq!(session.server.workspace.client_settings().indent, Some(4), "premise");
|
|
|
|
session.notify(DidChangeConfiguration::METHOD, serde_json::json!({ "settings": null }));
|
|
assert_eq!(session.server.workspace.client_settings().indent, None, "cleared, as before");
|
|
assert!(session.requests().is_empty(), "and nothing was asked of it");
|
|
}
|
|
|
|
#[test]
|
|
fn a_push_with_a_payload_is_applied_directly_even_when_the_client_could_be_asked() {
|
|
// The legacy `synchronize.configurationSection` path survives the
|
|
// pull model: a client that sends both must not have its own push
|
|
// ignored in favour of a round trip.
|
|
let tree = Tree::new("pushpayload");
|
|
let mut session = Session::with(vec![tree.path.clone()], pulling_settings());
|
|
let (id, _) = configuration_request(&session);
|
|
session.answer(id, serde_json::json!([null]));
|
|
|
|
session.notify(
|
|
DidChangeConfiguration::METHOD,
|
|
serde_json::json!({ "settings": { "lucisv": { "indent": 8 } } }),
|
|
);
|
|
assert_eq!(session.server.workspace.client_settings().indent, Some(8));
|
|
let sent = session.sent();
|
|
assert!(
|
|
!sent.iter().any(|r| r.method == WorkspaceConfiguration::METHOD),
|
|
"a payload is not a request to go and fetch one: {sent:#?}"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn a_late_pull_answer_overrides_a_push_that_landed_while_it_was_outstanding() {
|
|
// The other half of the precedence question: a client that both
|
|
// pushes (the legacy `synchronize.configurationSection`) and can be
|
|
// pulled may have its own push arrive *before* the startup pull's
|
|
// answer does — both mechanisms firing off the same connection at
|
|
// once. The loop is single-threaded and processes messages strictly
|
|
// in receive order, with no notion of "the push is newer" beyond
|
|
// that: `apply_settings` always replaces the whole struct, so
|
|
// whichever of the two is processed *last* is simply what is in
|
|
// force afterward. QA (2026-08-27): pinned per the dev's own review
|
|
// checklist item ("push-with-payload arriving while a pull is
|
|
// outstanding — which wins").
|
|
let tree = Tree::new("latepullwins");
|
|
let mut session = Session::with(vec![tree.path.clone()], pulling_settings());
|
|
let (id, _) = configuration_request(&session);
|
|
|
|
// The push lands first, while the startup pull is still outstanding.
|
|
session.notify(
|
|
DidChangeConfiguration::METHOD,
|
|
serde_json::json!({ "settings": { "lucisv": { "indent": 8 } } }),
|
|
);
|
|
assert_eq!(session.server.workspace.client_settings().indent, Some(8), "the push landed");
|
|
|
|
// The pull's answer arrives after — and, being processed last,
|
|
// overwrites it.
|
|
session.answer(id, serde_json::json!([{ "indent": 4 }]));
|
|
assert_eq!(
|
|
session.server.workspace.client_settings().indent,
|
|
Some(4),
|
|
"processed last, so in force last — the pull's answer, not the push"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn three_outstanding_requests_are_answered_by_id_in_any_order() {
|
|
// `applyEdit`, a progress `create` and a `workspace/configuration`
|
|
// all in flight at once. Only two of them are in `pending`, and the
|
|
// arrival order is not the send order — the id is the whole lookup,
|
|
// and neither answer may be delivered to the other's handler.
|
|
let abilities = ClientAbilities {
|
|
apply_edit: true,
|
|
work_done_progress: true,
|
|
configuration: true,
|
|
..Default::default()
|
|
};
|
|
let (tree, mut session, params) = propagating("threeway", abilities);
|
|
let _ = session.drain();
|
|
// `propagating` answered nothing, so the startup pull is already
|
|
// spent; an empty push asks again, and that one is left outstanding
|
|
// alongside the other two.
|
|
session.notify(DidChangeConfiguration::METHOD, serde_json::json!({ "settings": null }));
|
|
|
|
let result = session.result(ExecuteCommand::METHOD, params);
|
|
assert!(result.is_null(), "the edit was pushed, not returned");
|
|
// Two files, so the rescan is the whole one that puts a bar up.
|
|
session.watched(&[tree.path.join("sub.sv"), tree.path.join("top.sv")]);
|
|
|
|
let sent = session.sent();
|
|
let of = |method: &str| -> RequestId {
|
|
sent.iter()
|
|
.find(|request| request.method == method)
|
|
.unwrap_or_else(|| panic!("no {method} in {sent:#?}"))
|
|
.id
|
|
.clone()
|
|
};
|
|
let (edit, create, pull) = (
|
|
of(ApplyWorkspaceEdit::METHOD),
|
|
of(WorkDoneProgressCreate::METHOD),
|
|
of(WorkspaceConfiguration::METHOD),
|
|
);
|
|
|
|
// Backwards: the pull first, then the ignorable create, then the edit.
|
|
session.answer(pull, serde_json::json!([{ "indent": 4 }]));
|
|
assert_eq!(session.server.workspace.client_settings().indent, Some(4), "the pull landed");
|
|
assert!(session.shown().is_empty(), "and said nothing to the user");
|
|
|
|
session.answer(create, serde_json::json!(null));
|
|
assert!(session.shown().is_empty(), "a create answer says nothing either");
|
|
|
|
session.answer(edit, serde_json::json!({ "applied": false }));
|
|
let shown = session.shown();
|
|
assert_eq!(shown.len(), 1, "{shown:#?}");
|
|
assert!(shown[0].1.contains("lucisv.propagatePorts"), "{shown:#?}");
|
|
}
|
|
|
|
#[test]
|
|
fn two_outstanding_configuration_pulls_are_each_answered_by_their_own_id() {
|
|
// A second pull can go out before the first is answered — an empty
|
|
// `didChangeConfiguration` racing the client's answer to the startup
|
|
// pull, say. Both ids sit in `pending` at once; each answer is
|
|
// applied through its own id, and whichever is processed last is
|
|
// simply what ends up in force — there is no notion of the newer
|
|
// pull's answer winning over the older one, only processing order.
|
|
// QA (2026-08-27): pinned per the dev's own review checklist item.
|
|
let tree = Tree::new("twopulls");
|
|
let mut session = Session::with(vec![tree.path.clone()], pulling_settings());
|
|
let sent = session.sent();
|
|
let first = sent
|
|
.iter()
|
|
.find(|r| r.method == WorkspaceConfiguration::METHOD)
|
|
.expect("the startup pull")
|
|
.id
|
|
.clone();
|
|
|
|
session.notify(DidChangeConfiguration::METHOD, serde_json::json!({ "settings": null }));
|
|
let sent = session.sent();
|
|
let second = sent
|
|
.iter()
|
|
.find(|r| r.method == WorkspaceConfiguration::METHOD)
|
|
.expect("the re-pull")
|
|
.id
|
|
.clone();
|
|
assert_ne!(first, second, "two distinct outstanding requests, not one reused");
|
|
|
|
// Answered out of order: the second (newer) pull first, then the
|
|
// first (older, startup) one.
|
|
session.answer(second, serde_json::json!([{ "indent": 8 }]));
|
|
assert_eq!(session.server.workspace.client_settings().indent, Some(8), "the newer landed");
|
|
session.answer(first, serde_json::json!([{ "indent": 4 }]));
|
|
assert_eq!(
|
|
session.server.workspace.client_settings().indent,
|
|
Some(4),
|
|
"whichever answer is processed last is what is in force — no id-based precedence"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn an_answer_to_a_request_the_server_never_tracked_is_silently_ignored() {
|
|
// An id the server never sent, or a duplicate answer to one already
|
|
// consumed, names nothing in `pending`: `response` must not panic and
|
|
// must leave whatever settings are in force untouched.
|
|
// QA (2026-08-27): pinned per the dev's own review checklist item.
|
|
let tree = Tree::new("forgottenid");
|
|
let mut session = Session::with(vec![tree.path.clone()], pulling_settings());
|
|
let (id, _) = configuration_request(&session);
|
|
session.answer(id.clone(), serde_json::json!([{ "indent": 4 }]));
|
|
assert_eq!(session.server.workspace.client_settings().indent, Some(4), "premise");
|
|
|
|
// The same id, answered a second time — already removed from `pending`.
|
|
session.answer(id, serde_json::json!([{ "indent": 8 }]));
|
|
assert_eq!(
|
|
session.server.workspace.client_settings().indent,
|
|
Some(4),
|
|
"a stale re-answer is a no-op"
|
|
);
|
|
|
|
// An id that was never sent by this server at all.
|
|
session.answer(RequestId::from("never-sent".to_string()), serde_json::json!([{ "indent": 2 }]));
|
|
assert_eq!(session.server.workspace.client_settings().indent, Some(4));
|
|
}
|