дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-05 17:47:08 +02:00
Plugin navigation indexing sent 8 files per IPC call, invalidated each batch first and slept 20 ms between batches, and one invalid document failed its whole batch. The frontend now sends 128-file batches (active editors first) without the separate invalidation; the host loads them, calls the plugin in chunks of 16 so interactive requests interleave, skips and evicts invalid or oversized documents one by one, and does not store documents without edges, so they no longer take graph slots. A full graph still skips uncovered files before running the plugin. Discovery stays at one graph's 20,000 files, so the covers-N-of-M notice stays true. Sparse 20k files: 780 ms → 373 ms indexing, same navigation results. Co-authored-by: RuyimgByCN <[email protected]>
512 рядки
23 KiB
Rust
512 рядки
23 KiB
Rust
//! Generic document-indexer contract through a minimal real WASM fixture.
|
|
use ide_core::{Pos, Range, SymbolKind};
|
|
use ide_host::plugins::navigation::Snapshot;
|
|
use ide_host::plugins::{Consent, PluginHost};
|
|
use ide_language::SymbolTag;
|
|
use ide_plugin::{Invocation, Limits};
|
|
use std::{
|
|
path::{Path, PathBuf},
|
|
sync::Arc,
|
|
};
|
|
|
|
struct Fixture {
|
|
_tmp: tempfile::TempDir,
|
|
root: PathBuf,
|
|
host: PluginHost,
|
|
}
|
|
impl Fixture {
|
|
fn new() -> Self {
|
|
Self::with_manifest(|_| {})
|
|
}
|
|
fn with_manifest(edit: impl FnOnce(&Path)) -> Self {
|
|
let tmp = tempfile::tempdir().unwrap();
|
|
let root = dunce::canonicalize(tmp.path()).unwrap();
|
|
let host = PluginHost::new(root.join("plugins"), Arc::new(|_: Option<&str>, _| {}), Limits::default()).unwrap();
|
|
host.set_project_policy(Arc::new(|_| true));
|
|
let fixture = Path::new(env!("CARGO_MANIFEST_DIR")).join("../ide-plugin/tests/fixtures/indexer");
|
|
let package = tempfile::tempdir().unwrap();
|
|
let pkg = package.path();
|
|
std::fs::create_dir_all(pkg.join("dist")).unwrap();
|
|
for file in ["plugin.toml", "dist/plugin.wasm"] {
|
|
std::fs::copy(fixture.join(file), pkg.join(file)).unwrap();
|
|
}
|
|
edit(pkg);
|
|
host.install_from_dir(pkg, &Consent::all()).unwrap();
|
|
Self { _tmp: tmp, root, host }
|
|
}
|
|
fn index(&self, path: &str, text: &str, symbols: &[SymbolTag], version: Option<u32>, scope: &str) -> PathBuf {
|
|
let path = self.root.join(path);
|
|
std::fs::create_dir_all(path.parent().unwrap()).unwrap();
|
|
std::fs::write(&path, text).unwrap();
|
|
self.host
|
|
.index_navigation(
|
|
&self.root,
|
|
Snapshot { path: &path, version, text, symbols, scope },
|
|
Invocation { workspace_root: Some(self.root.clone()), ..Default::default() },
|
|
)
|
|
.unwrap();
|
|
path
|
|
}
|
|
}
|
|
fn method() -> SymbolTag {
|
|
SymbolTag {
|
|
name: "item".into(),
|
|
kind: SymbolKind::Method,
|
|
container: None,
|
|
range: Range::new(Pos::new(0, 4), Pos::new(0, 8)),
|
|
definition: true,
|
|
bases: Vec::new(),
|
|
}
|
|
}
|
|
const SOURCE: &str = "def source:item\nref mapping:item\n";
|
|
const MAPPING: &str = "def mapping:item\nref source:item\n";
|
|
fn reference_pos() -> Pos {
|
|
Pos::new(1, 5)
|
|
}
|
|
|
|
#[test]
|
|
fn bidirectional_navigation_versions_and_incremental_deletion() {
|
|
let f = Fixture::new();
|
|
let source = f.index("src/source.idx", SOURCE, &[method()], Some(1), "app");
|
|
let mapping = f.index("resources/mapping.idx", MAPPING, &[], Some(1), "app");
|
|
let result = f.host.navigation_at(&f.root, &mapping, 1, reference_pos(), None, |_| None).unwrap();
|
|
assert_eq!(result.targets[0].path.0, source);
|
|
assert_eq!(result.range.end.col - result.range.start.col, 11);
|
|
let reverse = f.host.navigation_at(&f.root, &source, 1, reference_pos(), None, |_| None).unwrap();
|
|
assert_eq!(reverse.targets[0].path.0, mapping);
|
|
assert!(f.host.navigation_at(&f.root, &mapping, 2, reference_pos(), None, |_| None).is_none());
|
|
assert!(f.host.navigation_at(&f.root, &mapping, 1, reference_pos(), None, |_| Some(2)).is_none());
|
|
f.host.invalidate_navigation(&f.root, Some(&[source]));
|
|
assert!(f.host.navigation_at(&f.root, &mapping, 1, reference_pos(), None, |_| None).is_none());
|
|
}
|
|
|
|
#[test]
|
|
fn module_candidates_reload_disable_and_project_isolation() {
|
|
let f = Fixture::new();
|
|
let first = f.index("a/source.idx", SOURCE, &[method()], Some(1), "a");
|
|
f.index("b/source.idx", SOURCE, &[method()], Some(1), "b");
|
|
let mapping = f.index("a/mapping.idx", MAPPING, &[], Some(1), "a");
|
|
let result = f.host.navigation_at(&f.root, &mapping, 1, reference_pos(), None, |_| None).unwrap();
|
|
assert_eq!(result.targets.len(), 1);
|
|
assert_eq!(result.targets[0].path.0, first);
|
|
let other = f.index("c/mapping.idx", MAPPING, &[], Some(1), "c");
|
|
assert_eq!(f.host.navigation_at(&f.root, &other, 1, reference_pos(), None, |_| None).unwrap().targets.len(), 2);
|
|
assert!(
|
|
f.host.navigation_at(&f.root.join("other-project"), &mapping, 1, reference_pos(), None, |_| None).is_none()
|
|
);
|
|
f.host.set_enabled("test.indexer", false).unwrap();
|
|
assert!(f.host.navigation_at(&f.root, &mapping, 1, reference_pos(), None, |_| None).is_none());
|
|
f.host.set_enabled("test.indexer", true).unwrap();
|
|
assert!(f.host.navigation_at(&f.root, &mapping, 1, reference_pos(), None, |_| None).is_none());
|
|
f.host.reload("test.indexer").unwrap();
|
|
assert!(f.host.navigation_at(&f.root, &mapping, 1, reference_pos(), None, |_| None).is_none());
|
|
}
|
|
|
|
#[test]
|
|
fn warmed_clicks_never_read_or_parse_files() {
|
|
let f = Fixture::new();
|
|
let source = f.index("source.idx", SOURCE, &[method()], Some(1), "");
|
|
let mapping = f.index("mapping.idx", MAPPING, &[], Some(1), "");
|
|
// Files become unreadable; the watcher invalidates separately. Resolution
|
|
// must remain purely in-memory, with no disk reads or component execution.
|
|
std::fs::remove_file(&source).unwrap();
|
|
std::fs::remove_file(&mapping).unwrap();
|
|
let calls = f.host.info_of("test.indexer").unwrap().stats.calls;
|
|
for _ in 0..10_000 {
|
|
assert_eq!(
|
|
f.host.navigation_at(&f.root, &mapping, 1, reference_pos(), None, |_| None).unwrap().targets.len(),
|
|
1
|
|
);
|
|
}
|
|
assert_eq!(f.host.info_of("test.indexer").unwrap().stats.calls, calls, "warm navigation must not execute Wasm");
|
|
f.host.invalidate_navigation(&f.root, None);
|
|
assert!(f.host.navigation_at(&f.root, &mapping, 1, reference_pos(), None, |_| None).is_none());
|
|
}
|
|
|
|
#[test]
|
|
fn permissions_and_paths_are_checked_before_indexing() {
|
|
let f = Fixture::new();
|
|
let external = tempfile::NamedTempFile::new().unwrap();
|
|
assert!(
|
|
f.host
|
|
.index_navigation(
|
|
&f.root,
|
|
Snapshot { path: external.path(), version: None, text: "", symbols: &[], scope: "" },
|
|
Invocation::default()
|
|
)
|
|
.is_err()
|
|
);
|
|
f.host.set_project_policy(Arc::new(|_| false));
|
|
assert!(f.host.navigation_extensions(&f.root).is_empty());
|
|
assert!(
|
|
f.host
|
|
.index_navigation(
|
|
&f.root,
|
|
Snapshot { path: &f.root.join("x.idx"), version: None, text: MAPPING, symbols: &[], scope: "" },
|
|
Invocation::default()
|
|
)
|
|
.is_err()
|
|
);
|
|
}
|
|
|
|
#[cfg(windows)]
|
|
#[test]
|
|
fn verbatim_snapshots_use_the_hosts_plain_document_identity() {
|
|
let f = Fixture::new();
|
|
let source = f.index("source.idx", SOURCE, &[method()], Some(1), "app");
|
|
let mapping = f.index("mapping.idx", MAPPING, &[], Some(1), "app");
|
|
let verbatim = std::fs::canonicalize(&source).unwrap();
|
|
assert_ne!(source, verbatim);
|
|
f.host
|
|
.index_navigation(
|
|
&f.root,
|
|
Snapshot { path: &verbatim, version: Some(2), text: SOURCE, symbols: &[method()], scope: "app" },
|
|
Invocation { workspace_root: Some(f.root.clone()), ..Default::default() },
|
|
)
|
|
.unwrap();
|
|
let result = f.host.navigation_at(&f.root, &mapping, 1, reference_pos(), None, |_| None).unwrap();
|
|
assert_eq!(result.targets.len(), 1, "a different prefix must replace the same document snapshot");
|
|
assert_eq!(result.targets[0].path.0, source);
|
|
assert!(f.host.indexed_symbol_at(&f.root, &source, Pos::new(0, 4), None).is_some());
|
|
}
|
|
|
|
#[cfg(unix)]
|
|
#[test]
|
|
fn snapshot_paths_still_reject_symlink_aliases_and_escapes() {
|
|
let f = Fixture::new();
|
|
let path = f.index("source.idx", SOURCE, &[method()], Some(1), "app");
|
|
let outside = tempfile::NamedTempFile::new().unwrap();
|
|
for (target, name) in [(path.as_path(), "alias.idx"), (outside.path(), "escape.idx")] {
|
|
let alias = f.root.join(name);
|
|
std::os::unix::fs::symlink(target, &alias).unwrap();
|
|
assert!(
|
|
f.host
|
|
.index_navigation(
|
|
&f.root,
|
|
Snapshot { path: &alias, version: None, text: SOURCE, symbols: &[], scope: "app" },
|
|
Invocation::default(),
|
|
)
|
|
.is_err()
|
|
);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn indexed_refactorings_drop_graphs_after_permission_revocation_or_lost_trust() {
|
|
let f = Fixture::new();
|
|
let path = f.index("source.idx", "def item\nref item\n", &[], Some(1), "app");
|
|
let pos = Pos::new(0, 4);
|
|
assert!(f.host.indexed_symbol_at(&f.root, &path, pos, None).is_some());
|
|
f.host.set_project_policy(Arc::new(|_| false));
|
|
assert!(f.host.indexed_symbol_at(&f.root, &path, pos, None).is_none());
|
|
f.host.set_project_policy(Arc::new(|_| true));
|
|
f.host.set_capability("test.indexer", "project.read", false).unwrap();
|
|
assert!(f.host.indexed_symbol_at(&f.root, &path, pos, None).is_none());
|
|
f.host.set_capability("test.indexer", "project.read", true).unwrap();
|
|
assert!(f.host.indexed_symbol_at(&f.root, &path, pos, None).is_none(), "regrant requires fresh snapshots");
|
|
}
|
|
|
|
#[test]
|
|
fn syntax_symbols_aliases_and_utf16_ranges_cross_the_wasm_boundary() {
|
|
let f = Fixture::new();
|
|
let symbol = method();
|
|
let definition = f.index("source.idx", "def item\nsymbols parent#\n", &[symbol], Some(1), "app");
|
|
f.index("child.idx", "alias child# parent#\n", &[], Some(1), "app");
|
|
let mapping = f.index("mapping.idx", "ref child#item\n", &[], Some(1), "app");
|
|
let result = f.host.navigation_at(&f.root, &mapping, 1, Pos::new(0, 6), None, |_| None).unwrap();
|
|
assert_eq!(result.targets[0].path.0, definition);
|
|
assert_eq!(result.targets[0].range, method().range);
|
|
f.index("unicode.idx", "def 😀\n", &[], Some(1), "app");
|
|
let unicode = f.index("unicode-ref.idx", "ref 😀\n", &[], Some(1), "app");
|
|
let result = f.host.navigation_at(&f.root, &unicode, 1, Pos::new(0, 5), None, |_| None).unwrap();
|
|
assert_eq!(result.range, Range::new(Pos::new(0, 4), Pos::new(0, 6)));
|
|
}
|
|
|
|
#[test]
|
|
fn two_windows_of_same_root_keep_unsaved_snapshots_isolated() {
|
|
let f = Fixture::new();
|
|
let source = f.index("source.idx", SOURCE, &[method()], Some(1), "");
|
|
let mapping = f.index("mapping.idx", MAPPING, &[], Some(1), "");
|
|
for client in ["one", "two"] {
|
|
let mut symbol = method();
|
|
if client == "two" {
|
|
symbol.range = Range::new(Pos::new(0, 5), Pos::new(0, 9));
|
|
}
|
|
for (path, text, symbols) in [(&source, "symbols source:\n", vec![symbol]), (&mapping, MAPPING, vec![])] {
|
|
f.host
|
|
.index_navigation(
|
|
&f.root,
|
|
Snapshot { path, version: Some(1), text, symbols: &symbols, scope: "" },
|
|
Invocation {
|
|
command_chain: Vec::new(),
|
|
client: Some(client.into()),
|
|
workspace_root: Some(f.root.clone()),
|
|
editor: None,
|
|
selected_paths: Vec::new(),
|
|
global_settings: false,
|
|
},
|
|
)
|
|
.unwrap();
|
|
}
|
|
}
|
|
assert_eq!(
|
|
f.host.navigation_at(&f.root, &mapping, 1, reference_pos(), Some("one"), |_| None).unwrap().targets[0]
|
|
.range
|
|
.start
|
|
.col,
|
|
4
|
|
);
|
|
assert_eq!(
|
|
f.host.navigation_at(&f.root, &mapping, 1, reference_pos(), Some("two"), |_| None).unwrap().targets[0]
|
|
.range
|
|
.start
|
|
.col,
|
|
5
|
|
);
|
|
f.host.invalidate_client_navigation(&f.root, Some("one"), None);
|
|
assert!(f.host.navigation_at(&f.root, &mapping, 1, reference_pos(), Some("one"), |_| None).is_none());
|
|
assert!(f.host.navigation_at(&f.root, &mapping, 1, reference_pos(), Some("two"), |_| None).is_some());
|
|
}
|
|
|
|
#[test]
|
|
fn markers_and_disable_follow_graph_state() {
|
|
let f = Fixture::new();
|
|
let tags = vec![];
|
|
let source = f.index("source.idx", SOURCE, &tags, Some(1), "app");
|
|
assert!(f.host.navigation_markers(&f.root, std::slice::from_ref(&source), None, |_| None).is_empty());
|
|
let mapping = f.index("mapping.idx", MAPPING, &[], Some(1), "app");
|
|
let entries = f.host.navigation_markers(&f.root, &[source.clone(), mapping.clone()], None, |_| None);
|
|
let source_markers = entries.iter().find(|e| e.path == source).unwrap();
|
|
assert_eq!(source_markers.markers.len(), 1);
|
|
assert_eq!(source_markers.markers[0].targets[0].path.0, mapping);
|
|
let mapping_markers = entries.iter().find(|e| e.path == mapping).unwrap();
|
|
assert_eq!(mapping_markers.markers.len(), 1);
|
|
assert_eq!(mapping_markers.markers[0].targets[0].path.0, source);
|
|
assert!(f.host.navigation_markers(&f.root, std::slice::from_ref(&source), None, |_| Some(2)).is_empty());
|
|
f.host.invalidate_navigation(&f.root, Some(&[mapping]));
|
|
assert!(f.host.navigation_markers(&f.root, std::slice::from_ref(&source), None, |_| None).is_empty());
|
|
f.host.set_enabled("test.indexer", false).unwrap();
|
|
assert!(f.host.navigation_markers(&f.root, &[source], None, |_| None).is_empty());
|
|
}
|
|
|
|
#[test]
|
|
fn marker_icons_map_indexed_markers_by_longest_key_prefix() {
|
|
let f = Fixture::with_manifest(|pkg| {
|
|
let manifest = std::fs::read_to_string(pkg.join("plugin.toml")).unwrap().replace("^1.2", "^1.3");
|
|
std::fs::create_dir_all(pkg.join("icons")).unwrap();
|
|
std::fs::write(
|
|
pkg.join("icons/marker.svg"),
|
|
r#"<svg viewBox="0 0 16 16"><rect width="16" height="16"/></svg>"#,
|
|
)
|
|
.unwrap();
|
|
std::fs::write(
|
|
pkg.join("plugin.toml"),
|
|
format!(
|
|
r#"{manifest}
|
|
[[contributes.markerIcons]]
|
|
id = "mapping"
|
|
icon = "icons/marker.svg"
|
|
markers = ["mapping:"]
|
|
|
|
[[contributes.markerIcons]]
|
|
id = "mapping-item"
|
|
icon = "icons/marker.svg"
|
|
markers = ["other:", "mapping:item"]
|
|
tooltip = "Mapped item"
|
|
"#
|
|
),
|
|
)
|
|
.unwrap();
|
|
});
|
|
let source = f.index("source.idx", "def source:item\nref mapping:item\nref mapping:other\n", &[], Some(1), "app");
|
|
let mapping = f.index("mapping.idx", "def mapping:item\ndef mapping:other\nref source:item\n", &[], Some(1), "app");
|
|
let entries = f.host.navigation_markers(&f.root, &[source.clone(), mapping.clone()], None, |_| None);
|
|
let icons = |path: &PathBuf| {
|
|
let entry = entries.iter().find(|e| &e.path == path).unwrap();
|
|
assert!(entry.markers.iter().all(|m| m.plugin_id == "test.indexer"));
|
|
entry.markers.iter().map(|m| m.icon.as_deref()).collect::<Vec<_>>()
|
|
};
|
|
assert_eq!(icons(&source), [Some("mapping-item"), Some("mapping")]);
|
|
assert_eq!(icons(&mapping), [None]);
|
|
}
|
|
|
|
#[test]
|
|
fn invalid_ranges_and_oversized_documents_never_publish() {
|
|
let f = Fixture::new();
|
|
let path = f.root.join("invalid.idx");
|
|
std::fs::write(&path, "invalid key\n").unwrap();
|
|
for text in ["invalid key\n".to_owned(), "x".repeat(ide_host::plugins::navigation::MAX_DOCUMENT_BYTES + 1)] {
|
|
assert!(
|
|
f.host
|
|
.index_navigation(
|
|
&f.root,
|
|
Snapshot { path: &path, version: Some(1), text: &text, symbols: &[], scope: "" },
|
|
Invocation { workspace_root: Some(f.root.clone()), ..Default::default() },
|
|
)
|
|
.is_err()
|
|
);
|
|
}
|
|
assert!(f.host.navigation_markers(&f.root, &[path], None, |_| None).is_empty());
|
|
}
|
|
|
|
#[test]
|
|
fn usages_from_definitions_and_references_follow_aliases_module_scope_and_client() {
|
|
let f = Fixture::new();
|
|
let definition = f.index("a/source.idx", "def item\nsymbols parent#\n", &[method()], Some(1), "a");
|
|
f.index("a/child.idx", "alias child# parent#\n", &[], None, "a");
|
|
let reference = f.index("a/use.idx", "ref child#item\n", &[], Some(1), "a");
|
|
let other = f.index("b/source.idx", "def item\nsymbols parent#\n", &[method()], Some(1), "b");
|
|
let external = f.index("c/use.idx", "ref child#item\n", &[], Some(1), "c");
|
|
let unrelated = f.index("b/use.idx", "ref child#item\n", &[], Some(1), "b");
|
|
for (path, pos) in [(&definition, Pos::new(0, 4)), (&reference, Pos::new(0, 6))] {
|
|
let symbol = f.host.indexed_symbol_at(&f.root, path, pos, None).unwrap();
|
|
assert!(symbol.files.iter().any(|f| f.path == definition));
|
|
assert!(symbol.files.iter().any(|f| f.path == reference));
|
|
assert!(!symbol.files.iter().any(|f| f.path == other), "prefer same-module definitions and their uses");
|
|
assert!(symbol.files.iter().any(|f| f.path == external), "external reference resolves to this definition");
|
|
assert!(!symbol.files.iter().any(|f| f.path == unrelated), "reference resolves to its own module");
|
|
assert_eq!(symbol.files.iter().map(|f| f.ranges.len()).sum::<usize>(), 3);
|
|
}
|
|
assert!(f.host.indexed_symbol_at(&f.root, &definition, Pos::new(0, 0), None).is_none());
|
|
assert!(f.host.indexed_symbol_at(&f.root, &definition, Pos::new(0, 4), Some("other-window")).is_none());
|
|
f.host.set_project_policy(Arc::new(|_| false));
|
|
assert!(f.host.indexed_symbol_at(&f.root, &definition, Pos::new(0, 4), None).is_none());
|
|
}
|
|
|
|
#[test]
|
|
fn cross_module_reference_and_definition_have_the_same_rename_anchors() {
|
|
let f = Fixture::new();
|
|
let definition = f.index("a/source.idx", "def item\nsymbols parent#\n", &[method()], Some(1), "a");
|
|
f.index("a/alias.idx", "alias child# parent#\n", &[], None, "a");
|
|
let external = f.index("b/use.idx", "ref item\n", &[], Some(1), "b");
|
|
let alias = f.index("c/use.idx", "ref child#item\n", &[], Some(1), "c");
|
|
for path in [&definition, &external, &alias] {
|
|
let symbol = f.host.indexed_symbol_at(&f.root, path, Pos::new(0, 4), None).unwrap();
|
|
let paths: Vec<_> = symbol.files.iter().map(|f| f.path.clone()).collect();
|
|
assert_eq!(paths, vec![definition.clone(), external.clone(), alias.clone()]);
|
|
assert_eq!(symbol.files.iter().map(|f| f.ranges.len()).sum::<usize>(), 3);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn a_full_graph_keeps_updating_its_files_and_skips_others_without_running_the_plugin() {
|
|
use ide_host::plugins::navigation::MAX_FILES;
|
|
let f = Fixture::new();
|
|
let source = f.index("source.idx", SOURCE, &[method()], Some(1), "");
|
|
for i in 1..MAX_FILES {
|
|
let p = f.root.join(format!("filler/{i}.idx"));
|
|
let txt = format!("def filler:{i}\n");
|
|
std::fs::create_dir_all(p.parent().unwrap()).unwrap();
|
|
std::fs::write(&p, &txt).unwrap();
|
|
f.host
|
|
.index_navigation(
|
|
&f.root,
|
|
Snapshot { path: &p, version: None, text: &txt, symbols: &[], scope: "" },
|
|
Invocation { workspace_root: Some(f.root.clone()), ..Default::default() },
|
|
)
|
|
.unwrap();
|
|
}
|
|
let calls = f.host.info_of("test.indexer").unwrap().stats.calls;
|
|
let mapping = f.index("mapping.idx", MAPPING, &[], Some(1), "");
|
|
assert_eq!(f.host.info_of("test.indexer").unwrap().stats.calls, calls, "a file the graph can't take is skipped");
|
|
assert!(f.host.navigation_at(&f.root, &mapping, 1, reference_pos(), None, |_| None).is_none());
|
|
f.index("source.idx", SOURCE, &[method()], Some(2), "");
|
|
assert_eq!(f.host.info_of("test.indexer").unwrap().stats.calls, calls + 1, "covered files still update");
|
|
assert!(f.host.navigation_at(&f.root, &source, 2, Pos::new(1, 5), None, |_| None).is_none());
|
|
|
|
// Batch indexing on the same full graph also skips uncovered files before invoking WASM.
|
|
let calls_before_batch = f.host.info_of("test.indexer").unwrap().stats.calls;
|
|
std::fs::write(&source, SOURCE).unwrap();
|
|
f.host
|
|
.index_navigation_batch(
|
|
&f.root,
|
|
&[
|
|
Snapshot { path: &mapping, version: Some(2), text: MAPPING, symbols: &[], scope: "" },
|
|
Snapshot { path: &source, version: Some(3), text: SOURCE, symbols: &[], scope: "" },
|
|
],
|
|
Invocation { workspace_root: Some(f.root.clone()), ..Default::default() },
|
|
None,
|
|
)
|
|
.unwrap();
|
|
assert_eq!(
|
|
f.host.info_of("test.indexer").unwrap().stats.calls,
|
|
calls_before_batch + 1,
|
|
"batch only invokes WASM for the already-covered file"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn empty_edges_do_not_consume_graph_slots_and_batch_isolates_invalid_documents() {
|
|
let f = Fixture::new();
|
|
let source = f.index("src/source.idx", SOURCE, &[method()], Some(1), "app");
|
|
let mapping = f.index("resources/mapping.idx", MAPPING, &[], Some(1), "app");
|
|
assert!(f.host.navigation_at(&f.root, &mapping, 1, reference_pos(), None, |_| None).is_some());
|
|
|
|
// Re-indexing `source` with empty content evicts its previous anchors cleanly.
|
|
std::fs::write(&source, "").unwrap();
|
|
f.host
|
|
.index_navigation(
|
|
&f.root,
|
|
Snapshot { path: &source, version: Some(2), text: "", symbols: &[], scope: "app" },
|
|
Invocation { workspace_root: Some(f.root.clone()), ..Default::default() },
|
|
)
|
|
.unwrap();
|
|
assert!(f.host.navigation_at(&f.root, &mapping, 1, reference_pos(), None, |_| None).is_none());
|
|
assert!(f.host.navigation_markers(&f.root, std::slice::from_ref(&mapping), None, |_| None).is_empty());
|
|
|
|
// Mixed batch containing 200 empty files, one invalid document, and two valid connected files:
|
|
// the invalid document is skipped/evicted while valid documents still commit cleanly.
|
|
let mut empty_paths = Vec::with_capacity(200);
|
|
for i in 0..200 {
|
|
let p = f.root.join(format!("empty/E{i}.idx"));
|
|
std::fs::create_dir_all(p.parent().unwrap()).unwrap();
|
|
std::fs::write(&p, "// nothing\n").unwrap();
|
|
empty_paths.push(p);
|
|
}
|
|
let bad = f.root.join("batch/bad.idx");
|
|
let connected_a = f.root.join("batch/source.idx");
|
|
let connected_b = f.root.join("batch/mapping.idx");
|
|
std::fs::create_dir_all(bad.parent().unwrap()).unwrap();
|
|
std::fs::write(&bad, "invalid key\n").unwrap();
|
|
std::fs::write(&connected_a, SOURCE).unwrap();
|
|
std::fs::write(&connected_b, MAPPING).unwrap();
|
|
|
|
let mut snapshots: Vec<Snapshot<'_>> = empty_paths
|
|
.iter()
|
|
.map(|p| Snapshot { path: p, version: None, text: "// nothing\n", symbols: &[], scope: "app" })
|
|
.collect();
|
|
snapshots.push(Snapshot { path: &bad, version: Some(1), text: "invalid key\n", symbols: &[], scope: "app" });
|
|
snapshots.push(Snapshot { path: &connected_a, version: Some(1), text: SOURCE, symbols: &[], scope: "app" });
|
|
snapshots.push(Snapshot { path: &connected_b, version: Some(1), text: MAPPING, symbols: &[], scope: "app" });
|
|
|
|
let summary = f
|
|
.host
|
|
.index_navigation_batch(
|
|
&f.root,
|
|
&snapshots,
|
|
Invocation { workspace_root: Some(f.root.clone()), ..Default::default() },
|
|
None,
|
|
)
|
|
.unwrap();
|
|
assert_eq!(summary.skipped_invalid, 1);
|
|
|
|
let res = f.host.navigation_at(&f.root, &connected_b, 1, reference_pos(), None, |_| None).unwrap();
|
|
assert_eq!(res.targets[0].path.0, connected_a);
|
|
let markers = f.host.navigation_markers(&f.root, &[connected_a.clone(), connected_b.clone()], None, |_| None);
|
|
assert_eq!(markers.len(), 2);
|
|
|
|
// Pre-cancelled batch aborts without publishing or modifying entries.
|
|
let cancelled_file = f.root.join("batch/cancelled.idx");
|
|
std::fs::write(&cancelled_file, SOURCE).unwrap();
|
|
let token = ide_core::CancellationToken::new();
|
|
token.cancel();
|
|
let cancelled_res = f.host.index_navigation_batch(
|
|
&f.root,
|
|
&[Snapshot { path: &cancelled_file, version: Some(1), text: SOURCE, symbols: &[], scope: "app" }],
|
|
Invocation { workspace_root: Some(f.root.clone()), ..Default::default() },
|
|
Some(&token),
|
|
);
|
|
assert!(cancelled_res.is_err());
|
|
assert!(f.host.navigation_markers(&f.root, &[cancelled_file], None, |_| None).is_empty());
|
|
}
|