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]>
115 lines
3.5 KiB
Rust
115 lines
3.5 KiB
Rust
//! The completion tests' harness: a scratch workspace on disk, and the
|
|
//! handful of helpers every provider's tests ask through.
|
|
//!
|
|
//! `#[cfg(test)]` only; the tests themselves sit at the foot of the file
|
|
//! whose code they pin.
|
|
|
|
use std::fs;
|
|
use std::path::PathBuf;
|
|
|
|
use super::*;
|
|
use crate::uri::path_to_uri;
|
|
|
|
pub(super) const SUB: &str = "\
|
|
module sub #(
|
|
parameter int WIDTH = 8
|
|
) (
|
|
input logic clk,
|
|
input logic [WIDTH-1:0] data,
|
|
output logic ready
|
|
);
|
|
endmodule
|
|
";
|
|
|
|
/// A scratch workspace root. Removed on drop.
|
|
pub(super) struct Tree {
|
|
pub(super) path: PathBuf,
|
|
}
|
|
|
|
impl Tree {
|
|
pub(super) fn new(name: &str) -> Tree {
|
|
let path = std::env::temp_dir()
|
|
.join(format!("lucisv_server_completion_{}_{name}", std::process::id()));
|
|
let _ = fs::remove_dir_all(&path);
|
|
fs::create_dir_all(&path).expect("temp dir");
|
|
Tree { path }
|
|
}
|
|
|
|
pub(super) fn write(&self, rel: &str, text: &str) -> PathBuf {
|
|
let path = self.path.join(rel);
|
|
fs::write(&path, text).expect("write");
|
|
path
|
|
}
|
|
}
|
|
|
|
impl Drop for Tree {
|
|
fn drop(&mut self) {
|
|
let _ = fs::remove_dir_all(&self.path);
|
|
}
|
|
}
|
|
|
|
/// A two-file workspace with `top.sv` open, and the cursor at `needle`'s
|
|
/// end. `sub.sv` declares [`SUB`].
|
|
pub(super) fn asking(name: &str, top: &str, needle: &str) -> (Tree, Workspace, Uri, Position) {
|
|
let tree = Tree::new(name);
|
|
tree.write("sub.sv", SUB);
|
|
opened(tree, top, needle)
|
|
}
|
|
|
|
/// The same, with whatever `tree` already holds and no `sub.sv` implied.
|
|
pub(super) fn opened(tree: Tree, top: &str, needle: &str) -> (Tree, Workspace, Uri, Position) {
|
|
opened_named(tree, "top.sv", top, needle)
|
|
}
|
|
|
|
/// The same again, with the buffer's file name spelled out — which is what
|
|
/// decides its dialect.
|
|
pub(super) fn opened_named(
|
|
tree: Tree,
|
|
file: &str,
|
|
top: &str,
|
|
needle: &str,
|
|
) -> (Tree, Workspace, Uri, Position) {
|
|
let path = tree.write(file, top);
|
|
let mut ws = Workspace::default();
|
|
ws.open_whole_workspace(vec![tree.path.clone()]);
|
|
let uri = path_to_uri(&path).expect("uri");
|
|
ws.set_document(uri.clone(), top.to_string());
|
|
let offset = (top.find(needle).expect("needle present") + needle.len()) as u32;
|
|
let doc = ws.document(&uri).expect("open");
|
|
let position = doc.positions().position(offset);
|
|
(tree, ws, uri, position)
|
|
}
|
|
|
|
pub(super) fn items(response: Option<CompletionResponse>) -> Vec<CompletionItem> {
|
|
match response {
|
|
Some(CompletionResponse::List(list)) => list.items,
|
|
Some(CompletionResponse::Array(items)) => items,
|
|
None => Vec::new(),
|
|
}
|
|
}
|
|
|
|
pub(super) fn inserted(item: &CompletionItem) -> String {
|
|
match item.text_edit.as_ref().expect("a text edit") {
|
|
CompletionTextEdit::Edit(edit) => edit.new_text.clone(),
|
|
CompletionTextEdit::InsertAndReplace(edit) => edit.new_text.clone(),
|
|
}
|
|
}
|
|
|
|
/// The tier an item was filed under, read off its `sortText`.
|
|
pub(super) fn tier(item: &CompletionItem) -> char {
|
|
item.sort_text.as_ref().and_then(|s| s.chars().next()).expect("every item is sorted")
|
|
}
|
|
|
|
/// Only the module skeletons — tier 0, the M4 items.
|
|
pub(super) fn skeletons(items: &[CompletionItem]) -> Vec<&CompletionItem> {
|
|
items.iter().filter(|item| tier(item) == TIER_MODULE).collect()
|
|
}
|
|
|
|
pub(super) fn find<'a>(items: &'a [CompletionItem], label: &str) -> Option<&'a CompletionItem> {
|
|
items.iter().find(|item| item.label == label)
|
|
}
|
|
|
|
pub(super) fn labels(items: &[CompletionItem]) -> Vec<&str> {
|
|
items.iter().map(|item| item.label.as_str()).collect()
|
|
}
|