use super::*; use ide_core::{IdeEvent, NullSink}; use std::sync::atomic::Ordering; const WAIT: Duration = Duration::from_secs(30); struct Fixture { _dir: tempfile::TempDir, root: PathBuf, cache: PathBuf, } impl Fixture { fn new(files: &[(&str, &str)]) -> Self { let dir = tempfile::tempdir().unwrap(); let root = dir.path().join("proj"); std::fs::create_dir_all(&root).unwrap(); let root = dunce::canonicalize(root).unwrap(); let cache = dir.path().join("cache"); let f = Self { _dir: dir, root, cache }; for (rel, text) in files { f.write(rel, text); } f } fn write(&self, rel: &str, text: &str) -> PathBuf { let p = self.root.join(rel); std::fs::create_dir_all(p.parent().unwrap()).unwrap(); std::fs::write(&p, text).unwrap(); p } fn open_with(&self, sink: SharedSink) -> Arc { let languages = Arc::new(LanguageRegistry::load(None).unwrap()); let syntax = Arc::new(Syntax::new()); let idx = ProjectIndex::open( &self.root, &self.cache, Vec::new(), vec!["**/node_modules".into(), "**/target".into()], languages, syntax, sink, ) .unwrap(); assert!(idx.wait_idle(WAIT), "indexing did not finish"); idx } fn open(&self) -> Arc { self.open_with(Arc::new(NullSink)) } } fn files(idx: &ProjectIndex, q: &str) -> Vec { idx.find_files(q, 20).into_iter().map(|m| m.rel_path).collect() } fn symbols(idx: &ProjectIndex, q: &str, filter: SymbolFilter) -> Vec { idx.find_symbols(q, filter, 20).into_iter().map(|m| m.name).collect() } fn sample() -> Fixture { Fixture::new(&[ ("src/main.rs", "fn main() {}\nstruct Config { port: u16 }\nimpl Config { fn load() -> Self { todo!() } }\n"), ("src/order/OrderController.java", "class OrderController {\n void save() {}\n void cancel() {}\n}\n"), ("src/order/Order.java", "class Order { int id; }\n"), ("src/other/OtherCollection.ts", "export class OtherCollection {\n add(x: number) {}\n}\n"), ("src/ui/Button.tsx", "export function Button() { return