diff --git a/.github/workflows/gpui.yml b/.github/workflows/gpui.yml index 701b7fd06..2f5eb6f8e 100644 --- a/.github/workflows/gpui.yml +++ b/.github/workflows/gpui.yml @@ -54,13 +54,28 @@ jobs: - name: Mac app-library runtime run: make _runtime_macos - - name: Cache GPUI host - uses: actions/cache@v6 + - name: Restore GPUI host + id: gpui-cache + uses: actions/cache/restore@v6 with: path: src/toolchain/hosts/gpui/target key: ${{ runner.os }}-gpui-host-${{ hashFiles('src/toolchain/hosts/gpui/Cargo.lock', 'src/toolchain/hosts/gpui/rust-toolchain*') }} restore-keys: ${{ runner.os }}-gpui-host- + - name: Build the host and every app archive + run: | + make _gpui-apps + OSPREY_GPUI_PREBUILT=1 bash src/toolchain/hosts/gpui/run.sh --build + + # Saved once the host is built, not in a post step, as on Linux: PR #413's cold build used the + # job's budget and its post-step save was lost to the timeout, so every rerun started cold again. + - name: Save GPUI host + if: steps.gpui-cache.outputs.cache-hit != 'true' + uses: actions/cache/save@v6 + with: + path: src/toolchain/hosts/gpui/target + key: ${{ steps.gpui-cache.outputs.cache-primary-key }} + - name: Every desktop app's self-test in a real window run: make _gpui-self-test GPUI_WINDOW= diff --git a/docs/plans/lsp-memory.md b/docs/plans/lsp-memory.md index d54807646..dbaa3aae6 100644 --- a/docs/plans/lsp-memory.md +++ b/docs/plans/lsp-memory.md @@ -30,10 +30,10 @@ Checked against the published v0.4.0 source on 2026-11-16, and confirmed on TMC ## Upgrade steps (after lspkit publishes) - [x] Agreed on TMC (2026-11-16). lspkit's repairs and heap proofs are green locally, still `0.0.0-dev`, and have no release ETA. After its `make test` passes and the release is published, it sends `osprey-lsp-memory` the version and any API breaks in the surfaces above. -- [ ] lspkit publishes the release with all five repairs. -- [ ] Bump `lspkit`, `lspkit-server` and `lsp-profiler` together in `src/toolchain/Cargo.toml` and refresh `Cargo.lock`. Keep `sysinfo` matched to the version `lsp-profiler` pins. -- [ ] Bump `@nimblesite/lsp-profiler-ui` in `src/toolchain/vscode-extension/package.json` if lspkit publishes a matching UI release. -- [ ] Fix any API breaks in `osprey-lsp`; no shims. +- [x] lspkit publishes the release with all five repairs (v0.6.0, 2026-11-18; it also drops humantime and chrono). +- [x] Bump `lspkit`, `lspkit-server` and `lsp-profiler` to 0.6.0 together in `src/toolchain/Cargo.toml` and refresh `Cargo.lock`. Keep `sysinfo` matched to the version `lsp-profiler` pins. +- [x] Bump `@nimblesite/lsp-profiler-ui` (to 0.6.0) in `src/toolchain/vscode-extension/package.json` if lspkit publishes a matching UI release. +- [x] Fix any API breaks in `osprey-lsp`; no shims. None: it builds unchanged and the 259 LSP and 21 profiler tests pass. - [ ] Keep Osprey's own guard: 32 unknown-method requests through the real server leave `in_flight: 0` (`Dispatcher` `Debug`). - [ ] `cargo test -p osprey-lsp`, then `make ci`, then one coordinated push. - [ ] Re-measure with `heap -s` after the idle sweep: live heap at or below 128 MB. @@ -42,3 +42,4 @@ Checked against the published v0.4.0 source on 2026-11-16, and confirmed on TMC ## Open, not yet fixed - [x] The server quit with `analysis backlog limit reached` when 256 messages were queued, and VS Code restarted it until it gave up. Now requests that don't fit get `ServerCancelled` (-32802) so the client retries, notifications wait for room, and the session never ends. Test: `a_request_flood_is_answered_and_never_ends_the_session`. In PR #411. +- [x] Idle CPU at 100% (#384). Every watched save and every tab close re-queued the whole repository sweep, and the cache keeps only 4 closed projects, so each save re-checked all 191 projects. A watched change or a close now re-checks only the projects it affects, plus newly discovered files, and an in-progress sweep is kept, not restarted. Test: `watched_changes_recheck_only_the_projects_they_affect` (8 projects; one save went from 8 analyses to 1). diff --git a/src/toolchain/Cargo.lock b/src/toolchain/Cargo.lock index e0a3c4e2f..115458950 100644 --- a/src/toolchain/Cargo.lock +++ b/src/toolchain/Cargo.lock @@ -418,12 +418,6 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" -[[package]] -name = "humantime" -version = "2.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15cdd26707701c53297e2fa6afb323d55fbc1d0810c3aec078ae3ef0424c3c15" - [[package]] name = "icu_collections" version = "2.4.0" @@ -689,12 +683,11 @@ checksum = "f9f8bd3e56ce4dfc153cf470fffbfa98c7620958b312ca5c3a4b8d5181fd13c6" [[package]] name = "lsp-profiler" -version = "0.5.0" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c994bb6d8f1b9871c1e47288ad986c5c4bf1b14a6e04c45776d26595501f4ba0" +checksum = "cb298f202dd03c38469fa71a50e8332853570610ffcb200a72f0117d7b2bbd40" dependencies = [ "async-trait", - "humantime", "inferno", "num-traits", "serde", @@ -736,31 +729,28 @@ dependencies = [ [[package]] name = "lspkit" -version = "0.5.0" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fca7d7fad6b009b01fef2706904f1960dd5b8e6fc74cc8210558fcde40cf5ce7" +checksum = "bb9daedaef6866d13f20ace87f4f815974b171c6b9aefb78dff86d5d76f9bb45" dependencies = [ "async-trait", "dashmap", "futures-core", - "rmp-serde", "ropey", "serde", "thiserror", "tokio", "tokio-util", "toml", - "tracing", ] [[package]] name = "lspkit-server" -version = "0.5.0" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1472ab3543a14ddb6a5f932f325bda13be4597c87641909117080993242231f2" +checksum = "f6d9f1e816e41bfc5b171b5f01f929467c88cbac2555c34df6010383e3608cd2" dependencies = [ "async-trait", - "futures-util", "lsp-types", "lspkit", "notify", @@ -1472,25 +1462,6 @@ dependencies = [ "bytemuck", ] -[[package]] -name = "rmp" -version = "0.8.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ba8be72d372b2c9b35542551678538b562e7cf86c3315773cae48dfbfe7790c" -dependencies = [ - "num-traits", -] - -[[package]] -name = "rmp-serde" -version = "1.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72f81bee8c8ef9b577d1681a70ebbc962c232461e397b22c208c43c04b67a155" -dependencies = [ - "rmp", - "serde", -] - [[package]] name = "ropey" version = "1.6.1" diff --git a/src/toolchain/Cargo.toml b/src/toolchain/Cargo.toml index 39dfb0a06..2f02a3f59 100644 --- a/src/toolchain/Cargo.toml +++ b/src/toolchain/Cargo.toml @@ -59,8 +59,8 @@ pulldown-cmark = { version = "0.13.6", default-features = false, features = ["ht # Language-server building blocks from the published lspkit crates. # [LSP-REUSE-LSPKIT] The LSP is wired in-process, so only the transport, VFS and # engine layers are pulled in (no tree-sitter feature). -lspkit = "0.5.0" -lspkit-server = "0.5.0" +lspkit = "0.6.0" +lspkit-server = "0.6.0" tokio = { version = "1", features = ["rt-multi-thread", "macros", "io-std", "io-util", "sync"] } async-trait = "0.1" futures-util = "0.3" @@ -68,7 +68,7 @@ serde = { version = "1", features = ["derive"] } serde_json = "1" # lspkit's shared CPU and memory profiler. The published crate ships its # generated wire model, so a build needs neither Node.js nor typeDiagram. -lsp-profiler = "0.5.0" +lsp-profiler = "0.6.0" # The same version lsp-profiler pins, so the graph carries one sysinfo. sysinfo = { version = "0.39.3", default-features = false, features = ["system", "user"] } tracing = "0.1" diff --git a/src/toolchain/crates/osprey-lsp/src/server.rs b/src/toolchain/crates/osprey-lsp/src/server.rs index 300b480bc..fb57a3f95 100644 --- a/src/toolchain/crates/osprey-lsp/src/server.rs +++ b/src/toolchain/crates/osprey-lsp/src/server.rs @@ -152,12 +152,12 @@ async fn notify( scope::lock(engine).opened(doc.as_str(), false); engine.project_cache.opened(doc.as_str(), false); scope::publish_siblings(engine, bus, &doc).await; - scope::refresh(engine, bus).await; + scope::rescope(engine, bus, &[doc]).await; } } "workspace/didChangeWatchedFiles" => { forget_deleted(engine, ¶ms); - scope::refresh(engine, bus).await; + scope::rescope(engine, bus, &watched(¶ms)).await; } "$/cancelRequest" => { if let Some(id) = cancel_id(¶ms) { @@ -174,6 +174,17 @@ const DELETED: u64 = 3; /// A file deleted on disk leaves the project even while its tab stays open, so /// the refresh clears its diagnostics; an edit to that buffer reopens it. /// Implements [LSP-DIAGNOSTICS-SCOPE]. +/// The documents a `didChangeWatchedFiles` notification names. +fn watched(params: &Value) -> Vec { + let changes = params.get("changes").and_then(Value::as_array); + changes + .into_iter() + .flatten() + .filter_map(|change| change.get("uri").and_then(Value::as_str)) + .map(DocumentUri::new) + .collect() +} + fn forget_deleted(engine: &OspreyEngine, params: &Value) { let changes = params.get("changes").and_then(Value::as_array); let deleted = changes.into_iter().flatten().filter_map(|change| { diff --git a/src/toolchain/crates/osprey-lsp/src/server/scope.rs b/src/toolchain/crates/osprey-lsp/src/server/scope.rs index b44667a11..ad1fb07a2 100644 --- a/src/toolchain/crates/osprey-lsp/src/server/scope.rs +++ b/src/toolchain/crates/osprey-lsp/src/server/scope.rs @@ -2,16 +2,19 @@ //! less the files `osprey.diagnostics.exclude` names [LSP-DIAGNOSTICS-EXCLUDE]. use super::{publish, OspreyEngine}; -use crate::workspace::{file_path, uri_of}; +use crate::workspace::file_path; +use files::{discover, repository, resolve_root, unignored}; use lspkit::vfs::DocumentUri; use lspkit::EngineApi; use lspkit_server::diagnostics::DiagnosticsBatch; use lspkit_server::DiagnosticsBus; use serde_json::Value; -use std::collections::{BTreeSet, HashSet, VecDeque}; +use std::collections::{BTreeSet, VecDeque}; use std::path::{Path, PathBuf}; use std::sync::{MutexGuard, PoisonError}; +mod files; + #[derive(Debug, Default)] pub(crate) struct Scope { folders: Vec, @@ -245,127 +248,28 @@ fn wildcard(pattern: &[u8], name: &[u8]) -> bool { } } -fn repository(folder: &Path) -> PathBuf { - folder - .ancestors() - .find(|path| path.join(".git").exists()) - .unwrap_or(folder) - .to_path_buf() -} - -fn resolve_root(root: &str, folders: &[PathBuf]) -> Vec { - if let Some(path) = file_path(root) { - return vec![path]; - } - let path = Path::new(root); - if path.is_absolute() { - return vec![path.to_path_buf()]; - } - folders.iter().map(|folder| folder.join(path)).collect() -} - -/// The files `git` lists under `root`: tracked ones plus untracked files no -/// ignore rule matches — the same set the CLI's program gate reads with -/// `git ls-files` ([CI-PROGRAMS-COMPILE]). `None` when `root` is outside any -/// git work tree or git cannot answer, so a plain folder keeps every file. -fn unignored(root: &Path) -> Option> { - let listed = std::process::Command::new("git") - .arg("-C") - .arg(root) - .args([ - "ls-files", - "--cached", - "--others", - "--exclude-standard", - "-z", - ]) - .output() - .ok()?; - listed.status.success().then(|| { - listed - .stdout - .split(|&byte| byte == 0) - .filter(|path| !path.is_empty()) - .map(|path| root.join(String::from_utf8_lossy(path).into_owned())) - .collect() - }) -} - -fn discover(root: &Path, unignored: Option<&HashSet>, documents: &mut BTreeSet) { - let entries = match std::fs::read_dir(root) { - Ok(entries) => entries, - Err(error) => { - eprintln!("osprey lsp: cannot scan {}: {error}", root.display()); - return; - } - }; - for entry in entries { - match entry { - Ok(entry) => visit(&entry, unignored, documents), - Err(error) => eprintln!("osprey lsp: cannot read {}: {error}", root.display()), - } - } -} - -fn visit( - entry: &std::fs::DirEntry, - unignored: Option<&HashSet>, - documents: &mut BTreeSet, -) { - let path = entry.path(); - let kind = match entry.file_type() { - Ok(kind) => kind, - Err(error) => { - eprintln!("osprey lsp: cannot inspect {}: {error}", path.display()); - return; - } - }; - if kind.is_dir() && !excluded(&path) { - discover(&path, unignored, documents); - } - if kind.is_file() && source_file(&path) && unignored.is_none_or(|files| files.contains(&path)) { - if let Some(uri) = uri_of(&path) { - let _ = documents.insert(uri); - } - } -} - -fn excluded(path: &Path) -> bool { - path.file_name() - .and_then(|name| name.to_str()) - .is_some_and(|name| { - name.starts_with('.') - || matches!( - name, - "target" | "node_modules" | "build" | "dist" | "__pycache__" - ) - }) -} - -fn source_file(path: &Path) -> bool { - match path.extension().and_then(|extension| extension.to_str()) { - Some("osp" | "ospml") => true, - Some("py") => python_file(path), - _ => false, - } +/// Clear documents that left the scope, re-check the open ones now, and queue +/// every closed one for the sweep the work queue runs between requests. +pub(super) async fn refresh(engine: &OspreyEngine, bus: &DiagnosticsBus) { + rescan(engine, bus, None).await; } -fn python_file(path: &Path) -> bool { - // CPython tools are not Osprey. A marker or manifest must opt in. - if std::fs::read_to_string(path) - .is_ok_and(|text| osprey_syntax::flavor_marker(&text) == Some("python")) - { - return true; - } - crate::workspace::project_root(path).is_some_and(|root| { - osprey_project::discover(&root) - .is_ok_and(|(_, files)| files.iter().any(|file| file == path)) - }) +/// After a watched change or a tab close, re-check only new documents and those +/// `changed` can affect: restarting the whole sweep on every save kept an idle +/// server at 100% CPU (#384). +pub(super) async fn rescope(engine: &OspreyEngine, bus: &DiagnosticsBus, changed: &[DocumentUri]) { + let affected = changed + .iter() + .flat_map(|doc| siblings(engine, doc).into_iter().chain([doc.clone()])) + .map(|doc| doc.as_str().to_string()) + .collect(); + rescan(engine, bus, Some(affected)).await; } -/// Clear documents that left the scope, re-check the open ones now, and queue -/// every closed one for the sweep the work queue runs between requests. -pub(super) async fn refresh(engine: &OspreyEngine, bus: &DiagnosticsBus) { +/// Clear what left the scope, publish the open documents to re-check now, and +/// queue the closed ones: every document, or with `affected` only those and +/// the newly discovered, keeping the sweep already queued. +async fn rescan(engine: &OspreyEngine, bus: &DiagnosticsBus, affected: Option>) { let (open, removed) = { let mut scope = lock(engine); let documents = scope.documents(); @@ -374,11 +278,25 @@ pub(super) async fn refresh(engine: &OspreyEngine, bus: &DiagnosticsBus) { .difference(&documents) .cloned() .collect::>(); + let recheck = |uri: &&String| { + affected + .as_ref() + .is_none_or(|set| set.contains(*uri) || !scope.published.contains(*uri)) + }; let (open, closed) = documents .iter() + .filter(recheck) .cloned() .partition::, _>(|uri| scope.open.contains(uri)); - scope.pending = closed.into(); + if affected.is_none() { + scope.pending.clear(); + } + scope.pending.retain(|uri| documents.contains(uri)); + for uri in closed { + if !scope.pending.contains(&uri) { + scope.pending.push_back(uri); + } + } scope.published = documents; (open, removed) }; diff --git a/src/toolchain/crates/osprey-lsp/src/server/scope/files.rs b/src/toolchain/crates/osprey-lsp/src/server/scope/files.rs new file mode 100644 index 000000000..44d88785a --- /dev/null +++ b/src/toolchain/crates/osprey-lsp/src/server/scope/files.rs @@ -0,0 +1,127 @@ +//! The source files a diagnostics scope covers on disk [LSP-DIAGNOSTICS-SCOPE]. + +use crate::workspace::{file_path, uri_of}; +use std::collections::{BTreeSet, HashSet}; +use std::path::{Path, PathBuf}; + +pub(super) fn repository(folder: &Path) -> PathBuf { + folder + .ancestors() + .find(|path| path.join(".git").exists()) + .unwrap_or(folder) + .to_path_buf() +} + +pub(super) fn resolve_root(root: &str, folders: &[PathBuf]) -> Vec { + if let Some(path) = file_path(root) { + return vec![path]; + } + let path = Path::new(root); + if path.is_absolute() { + return vec![path.to_path_buf()]; + } + folders.iter().map(|folder| folder.join(path)).collect() +} + +/// The files `git` lists under `root`: tracked ones plus untracked files no +/// ignore rule matches — the same set the CLI's program gate reads with +/// `git ls-files` ([CI-PROGRAMS-COMPILE]). `None` when `root` is outside any +/// git work tree or git cannot answer, so a plain folder keeps every file. +pub(super) fn unignored(root: &Path) -> Option> { + let listed = std::process::Command::new("git") + .arg("-C") + .arg(root) + .args([ + "ls-files", + "--cached", + "--others", + "--exclude-standard", + "-z", + ]) + .output() + .ok()?; + listed.status.success().then(|| { + listed + .stdout + .split(|&byte| byte == 0) + .filter(|path| !path.is_empty()) + .map(|path| root.join(String::from_utf8_lossy(path).into_owned())) + .collect() + }) +} + +pub(super) fn discover( + root: &Path, + unignored: Option<&HashSet>, + documents: &mut BTreeSet, +) { + let entries = match std::fs::read_dir(root) { + Ok(entries) => entries, + Err(error) => { + eprintln!("osprey lsp: cannot scan {}: {error}", root.display()); + return; + } + }; + for entry in entries { + match entry { + Ok(entry) => visit(&entry, unignored, documents), + Err(error) => eprintln!("osprey lsp: cannot read {}: {error}", root.display()), + } + } +} + +fn visit( + entry: &std::fs::DirEntry, + unignored: Option<&HashSet>, + documents: &mut BTreeSet, +) { + let path = entry.path(); + let kind = match entry.file_type() { + Ok(kind) => kind, + Err(error) => { + eprintln!("osprey lsp: cannot inspect {}: {error}", path.display()); + return; + } + }; + if kind.is_dir() && !excluded(&path) { + discover(&path, unignored, documents); + } + if kind.is_file() && source_file(&path) && unignored.is_none_or(|files| files.contains(&path)) { + if let Some(uri) = uri_of(&path) { + let _ = documents.insert(uri); + } + } +} + +fn excluded(path: &Path) -> bool { + path.file_name() + .and_then(|name| name.to_str()) + .is_some_and(|name| { + name.starts_with('.') + || matches!( + name, + "target" | "node_modules" | "build" | "dist" | "__pycache__" + ) + }) +} + +fn source_file(path: &Path) -> bool { + match path.extension().and_then(|extension| extension.to_str()) { + Some("osp" | "ospml") => true, + Some("py") => python_file(path), + _ => false, + } +} + +fn python_file(path: &Path) -> bool { + // CPython tools are not Osprey. A marker or manifest must opt in. + if std::fs::read_to_string(path) + .is_ok_and(|text| osprey_syntax::flavor_marker(&text) == Some("python")) + { + return true; + } + crate::workspace::project_root(path).is_some_and(|root| { + osprey_project::discover(&root) + .is_ok_and(|(_, files)| files.iter().any(|file| file == path)) + }) +} diff --git a/src/toolchain/crates/osprey-lsp/src/server/tests/features.rs b/src/toolchain/crates/osprey-lsp/src/server/tests/features.rs index 161230107..916b461e5 100644 --- a/src/toolchain/crates/osprey-lsp/src/server/tests/features.rs +++ b/src/toolchain/crates/osprey-lsp/src/server/tests/features.rs @@ -243,3 +243,134 @@ async fn symbols_completion_and_signature_help() { assert!(mid_labels.contains(&"perimeter"), "{mid_labels:?}"); h.shutdown_and_exit().await; } + +/// A watched save, a tab close, a new file and an unrelated file each re-check +/// only the projects they can affect, never the whole repository again: an +/// agent saving files kept an idle server at 100% CPU (#384). +/// Implements [LSP-DIAGNOSTICS-SCOPE]. +#[tokio::test] +async fn watched_changes_recheck_only_the_projects_they_affect( +) -> Result<(), Box> { + const PROJECTS: usize = 8; + const WARNED: &str = "double : int -> int\ndouble x = x * 2\n"; + let root = std::env::temp_dir().join(format!("osprey sweep cpu {}", std::process::id())); + let mut mains = Vec::new(); + for index in 0..PROJECTS { + let project = root.join(format!("p{index}")); + std::fs::create_dir_all(project.join("src"))?; + std::fs::write(project.join("osprey.toml"), "[project]\nsource_roots = [\"src\"]\ndefault_namespace = \"p\"\nentry = \"src/main.ospml\"\n")?; + let main = project.join("src/main.ospml"); + std::fs::write(&main, WARNED)?; + mains.push((main.clone(), sweep_uri(&main)?)); + } + let mut h = Harness::start(); + let folder = sweep_uri(&root)?; + let _ = h + .request(600, "initialize", with_progress(json!({"rootUri": folder}))) + .await; + h.notify("initialized", json!({})).await; + let reports = settled(&mut h, 601).await; + for (_, main) in &mains { + assert!( + reports.iter().any(|p| p["uri"] == *main), + "first sweep checks {main}: {reports:?}" + ); + } + let mut analyses = h.engine.project_cache.analyses(); + assert!( + analyses >= PROJECTS, + "every project analysed once: {analyses}" + ); + + let [(saved_path, saved_uri), (_, closed_uri), (_, grown_uri), ..] = mains.as_slice() else { + return Err("eight projects".into()); + }; + std::fs::write(saved_path, "double x = x * 2\n")?; + let saved = json!({"changes":[{"uri":saved_uri,"type":2}]}); + let reports = rechecked(&mut h, 602, saved, &mut analyses, 1, "a save").await; + assert!( + reports + .iter() + .any(|p| p["uri"] == *saved_uri && p["diagnostics"] == json!([])), + "the save clears its warning: {reports:?}" + ); + only_published(&reports, &[saved_uri], "a save"); + + let _ = h.open_at(closed_uri, WARNED).await; + analyses = h.engine.project_cache.analyses(); + h.notify("textDocument/didClose", text_doc(closed_uri)) + .await; + let reports = settled(&mut h, 603).await; + let closed = h.engine.project_cache.analyses() - analyses; + assert!(closed <= 1, "a tab close re-checked {closed} projects"); + analyses += closed; + only_published(&reports, &[closed_uri], "a tab close"); + + let extra = root.join("p2/src/extra.ospml"); + std::fs::write(&extra, "triple : int -> int\ntriple x = x * 3\n")?; + let extra_uri = sweep_uri(&extra)?; + let created = json!({"changes":[{"uri":extra_uri,"type":1}]}); + let reports = rechecked(&mut h, 604, created, &mut analyses, 1, "a new file").await; + assert!( + reports.iter().any(|p| p["uri"] == extra_uri + && p.pointer("/diagnostics/0/code") == Some(&json!("redundant-annotation"))), + "the new file is checked: {reports:?}" + ); + only_published(&reports, &[&extra_uri, grown_uri], "a new file"); + + let tool = root.join("tool.ts"); + std::fs::write(&tool, "export const x = 1;\n")?; + let unrelated = json!({"changes":[{"uri":sweep_uri(&tool)?,"type":2}]}); + let reports = rechecked( + &mut h, + 605, + unrelated, + &mut analyses, + 0, + "an unrelated file", + ) + .await; + only_published(&reports, &[], "an unrelated file"); + h.shutdown_and_exit().await; + std::fs::remove_dir_all(root)?; + Ok(()) +} + +fn sweep_uri(path: &std::path::Path) -> Result> { + Ok(crate::workspace::uri_of(path).ok_or("a file URI")?) +} + +/// Send a watched-files `change` and settle, asserting it analysed exactly +/// `expected` projects; `analyses` advances to the new total. +async fn rechecked( + h: &mut Harness, + id: i64, + change: Value, + analyses: &mut usize, + expected: usize, + what: &str, +) -> Vec { + h.notify("workspace/didChangeWatchedFiles", change).await; + let reports = settled(h, id).await; + let now = h.engine.project_cache.analyses(); + assert_eq!( + now - *analyses, + expected, + "{what} re-checked {} projects", + now - *analyses + ); + *analyses = now; + reports +} + +/// No document outside `expected` was republished. +fn only_published(reports: &[Value], expected: &[&String], what: &str) { + let stray = reports + .iter() + .filter(|p| !expected.iter().any(|uri| p["uri"] == **uri)) + .collect::>(); + assert!( + stray.is_empty(), + "{what} republished other documents: {stray:?}" + ); +} diff --git a/src/toolchain/vscode-extension/package-lock.json b/src/toolchain/vscode-extension/package-lock.json index 029329034..c05211a1c 100644 --- a/src/toolchain/vscode-extension/package-lock.json +++ b/src/toolchain/vscode-extension/package-lock.json @@ -8,7 +8,7 @@ "name": "osprey", "version": "0.0.0-dev", "dependencies": { - "@nimblesite/lsp-profiler-ui": "^0.4.0", + "@nimblesite/lsp-profiler-ui": "^0.6.0", "@nimblesite/shipwright-vscode": "^0.11.0", "@preact/signals-core": "^1.14.4", "@vscode/codicons": "^0.0.46-24", @@ -518,9 +518,9 @@ } }, "node_modules/@nimblesite/lsp-profiler-ui": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/@nimblesite/lsp-profiler-ui/-/lsp-profiler-ui-0.4.0.tgz", - "integrity": "sha512-oXsM/IGGeuA0rZTIk2t1C+WYwFZ9955qTlK96j0NDMkSJ4/WVCG6FeVZkAqjuzCYdLKFOaXLlfnzppblqITnAA==", + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/@nimblesite/lsp-profiler-ui/-/lsp-profiler-ui-0.6.0.tgz", + "integrity": "sha512-wg0IPM0fspsY4Ln7n2FuLNQokeEwfZChDZGgIAahXuXyy/6HHVqOry9G2u7dfPKNnDzy/Z16+E7WC24v2pDSbA==", "license": "MIT", "dependencies": { "@preact/signals-core": "^1.14.4" diff --git a/src/toolchain/vscode-extension/package.json b/src/toolchain/vscode-extension/package.json index 583e1df33..351c31c32 100644 --- a/src/toolchain/vscode-extension/package.json +++ b/src/toolchain/vscode-extension/package.json @@ -863,7 +863,7 @@ ] }, "dependencies": { - "@nimblesite/lsp-profiler-ui": "^0.4.0", + "@nimblesite/lsp-profiler-ui": "^0.6.0", "@nimblesite/shipwright-vscode": "^0.11.0", "@preact/signals-core": "^1.14.4", "@vscode/codicons": "^0.0.46-24",