Skip to content

The IDE you know, rebuilt in Rust. IntelliJ IDEA–style keymap, tool windows and search-everywhere in a fast native app: editor, code insight, debugger, Git, terminal, database and HTTP clients for 60+ languages.

fix(project): refresh ignored state when rules change (#2423)

l0ng-ai49fc9e9257fd
diff --git a/crates/ide-core/src/event.rs b/crates/ide-core/src/event.rs
index 30f43857e..224cb6531 100644
--- a/crates/ide-core/src/event.rs
+++ b/crates/ide-core/src/event.rs
@@ -42,6 +42,10 @@ pub enum IdeEvent {
created: Vec<crate::IpcPath>,
modified: Vec<crate::IpcPath>,
removed: Vec<crate::IpcPath>,
+ /// Subtrees whose ignore rules changed, after the matchers were rebuilt.
+ #[serde(default)]
+ #[specta(optional)]
+ ignore_rules: Vec<crate::IpcPath>,
},
/// Excluded or ignored folders whose contents changed; they stay out of `FsChanged`.
ExcludedDirsChanged {
diff --git a/crates/ide-host/src/project.rs b/crates/ide-host/src/project.rs
index 20f76bdab..3e8a45ee2 100644
--- a/crates/ide-host/src/project.rs
+++ b/crates/ide-host/src/project.rs
@@ -412,6 +412,7 @@ impl Host {
Box::new(move |batch| {
let changed: Vec<PathBuf> = batch.created.iter().chain(&batch.modified).cloned().collect();
let (ignored, ignored_gone) = ignored_changes(batch);
+ index.ignore_rules_changed(&batch.ignore_rules);
index.update(&[&changed[..], &ignored].concat(), &[&batch.removed[..], &ignored_gone].concat());
kotlin_bridge.files_changed(changed.iter().chain(&batch.removed));
phpstan.files_removed(batch.removed.iter());
@@ -1309,6 +1310,7 @@ fn content_root_watcher(
Box::new(move |batch| {
let changed: Vec<PathBuf> = batch.created.iter().chain(&batch.modified).cloned().collect();
let (ignored, ignored_gone) = ignored_changes(batch);
+ index.ignore_rules_changed(&batch.ignore_rules);
index.update(&[&changed[..], &ignored].concat(), &[&batch.removed[..], &ignored_gone].concat());
// A workspace member's PHP language level follows its own composer.json.
if composer_changed(&root, changed.iter().chain(&batch.removed)) {
diff --git a/crates/ide-index/src/filter.rs b/crates/ide-index/src/filter.rs
index bae11d654..44f142490 100644
--- a/crates/ide-index/src/filter.rs
+++ b/crates/ide-index/src/filter.rs
@@ -138,6 +138,10 @@ impl PathFilter {
&self.config.0 == extra_roots && self.config.1 == excludes
}
+ pub(crate) fn reload(&self) -> Self {
+ Self::new(&self.root, &self.config.0, &self.config.1)
+ }
+
pub(crate) fn root(&self) -> &Path {
&self.root
}
diff --git a/crates/ide-index/src/lib.rs b/crates/ide-index/src/lib.rs
index 48ef77dcb..03082fed3 100644
--- a/crates/ide-index/src/lib.rs
+++ b/crates/ide-index/src/lib.rs
@@ -332,6 +332,28 @@ impl ProjectIndex {
}
}
+ /// Refreshes ignore matchers and indexed entries in the affected subtrees.
+ pub fn ignore_rules_changed(&self, dirs: &[PathBuf]) {
+ let filter = self.shared.filter();
+ let mut affected = Vec::new();
+ for dir in dirs {
+ let path = if dir.is_absolute() { dir.clone() } else { self.root.join(dir) };
+ let path = dunce::canonicalize(&path).unwrap_or(path);
+ for root in filter.roots() {
+ if path.starts_with(root) {
+ affected.push(path.clone());
+ break;
+ }
+ if root.starts_with(&path) {
+ affected.push(root.to_path_buf());
+ }
+ }
+ }
+ if !affected.is_empty() {
+ self.shared.enqueue(Job::IgnoreRules(affected));
+ }
+ }
+
/// Boost for "recent files" ranking.
/// Records a recently opened file; a virtual document's URI (library
/// class) is kept verbatim, like IDEA lists library classes in Recent Files.
diff --git a/crates/ide-index/src/tests.rs b/crates/ide-index/src/tests.rs
index 75ddbf33b..63952f15c 100644
--- a/crates/ide-index/src/tests.rs
+++ b/crates/ide-index/src/tests.rs
@@ -750,3 +750,66 @@ fn persisted_symbols_do_not_load_through_escaping_symlink_ancestors() {
assert!(symbols(&idx, "old_symbol", SymbolFilter::All).is_empty());
assert_eq!(initial.lock()[0], 0, "unsafe cached symbols must never be published");
}
+
+#[test]
+fn rule_changes_refresh_only_the_affected_index_subtree() {
+ for (rule, subtree) in [(".git/info/exclude", ""), ("sub/.gitignore", "sub"), ("sub/.ignore", "sub")] {
+ let fx = Fixture::new(&[
+ (".git/HEAD", "ref: refs/heads/main\n"),
+ ("sub/generated/file.ts", "export function generated() {}\n"),
+ ("sub/local.ts", "export function localOnly() {}\n"),
+ ("other/keep.ts", "export function keep() {}\n"),
+ ]);
+ fx.write(rule, "");
+ let idx = fx.open();
+ assert_eq!(files(&idx, "file.ts"), ["sub/generated/file.ts"]);
+ fx.write(rule, "generated/\nlocal.ts\n");
+ let dirs = [fx.root.join(subtree)];
+ idx.ignore_rules_changed(&dirs);
+ assert!(idx.wait_idle(WAIT));
+ assert!(files(&idx, "file.ts").is_empty(), "{rule}: ignored directory remained indexed");
+ assert_eq!(files(&idx, "local.ts"), ["sub/local.ts"]);
+ assert!(symbols(&idx, "localOnly", SymbolFilter::All).is_empty());
+ assert_eq!(files(&idx, "keep.ts"), ["other/keep.ts"]);
+
+ fx.write(rule, "");
+ idx.ignore_rules_changed(&dirs);
+ assert!(idx.wait_idle(WAIT));
+ assert_eq!(files(&idx, "file.ts"), ["sub/generated/file.ts"]);
+ assert_eq!(symbols(&idx, "localOnly", SymbolFilter::All), ["localOnly"]);
+ // The cached root matcher must also follow the rules for later watcher updates.
+ let fresh = fx.write("sub/generated/new.ts", "export function fresh() {}\n");
+ idx.update(&[fresh], &[]);
+ assert!(idx.wait_idle(WAIT));
+ assert_eq!(files(&idx, "new.ts"), ["sub/generated/new.ts"]);
+ }
+}
+
+#[test]
+fn repository_rule_changes_refresh_members_of_an_unindexed_container() {
+ let fx = Fixture::new(&[
+ (".git/HEAD", "ref: refs/heads/main\n"),
+ (".git/info/exclude", ""),
+ ("member/generated/item.txt", "x"),
+ ]);
+ let idx = ProjectIndex::open(
+ &fx.root,
+ &fx.cache,
+ IndexRoots { include_root: false, folders: vec![fx.root.join("member")] },
+ vec![],
+ Arc::new(LanguageRegistry::load(None).unwrap()),
+ Arc::new(Syntax::new()),
+ Arc::new(NullSink),
+ )
+ .unwrap();
+ assert!(idx.wait_idle(WAIT));
+ assert_eq!(files(&idx, "item.txt"), ["member/generated/item.txt"]);
+ fx.write(".git/info/exclude", "generated/\n");
+ idx.ignore_rules_changed(std::slice::from_ref(&fx.root));
+ assert!(idx.wait_idle(WAIT));
+ assert!(files(&idx, "item.txt").is_empty());
+ fx.write(".git/info/exclude", "");
+ idx.ignore_rules_changed(std::slice::from_ref(&fx.root));
+ assert!(idx.wait_idle(WAIT));
+ assert_eq!(files(&idx, "item.txt"), ["member/generated/item.txt"]);
+}
diff --git a/crates/ide-index/src/worker.rs b/crates/ide-index/src/worker.rs
index 79453206c..0e01e6e6d 100644
--- a/crates/ide-index/src/worker.rs
+++ b/crates/ide-index/src/worker.rs
@@ -26,6 +26,7 @@ pub(crate) enum Job {
SaveRecent,
/// The roots or excludes changed: scan again (unchanged files are kept).
Rescan,
+ IgnoreRules(Vec<PathBuf>),
/// File types changed: re-parse the indexed files whose language under the
/// previous registry differs from the current one.
Reparse(std::sync::Arc<LanguageRegistry>),
@@ -212,6 +213,10 @@ impl Shared {
}
fn full_scan(&self) {
+ self.scan(None);
+ }
+
+ fn scan(&self, dirs: Option<&[PathBuf]>) {
let started = Instant::now();
self.indexing.store(true, Ordering::SeqCst);
self.emit_state();
@@ -227,7 +232,11 @@ impl Shared {
let filter = self.filter();
let mut found = Vec::new();
- for root in filter.roots() {
+ let roots: Vec<&Path> = match dirs {
+ Some(dirs) => dirs.iter().map(PathBuf::as_path).collect(),
+ None => filter.roots().collect(),
+ };
+ for root in roots {
found.extend(filter.walk(root, &self.cancelled));
}
if self.is_cancelled() {
@@ -237,7 +246,12 @@ impl Shared {
let (todo, stale): (Vec<&Found>, Vec<PathBuf>) = {
let d = self.data.read();
let todo = found.iter().filter(|f| d.get(&f.path).is_none_or(|e| e.stale_for(f))).collect();
- let stale = d.paths().filter(|p| !seen.contains(p.as_path())).cloned().collect();
+ let stale = d
+ .paths()
+ .filter(|p| dirs.is_none_or(|dirs| dirs.iter().any(|dir| p.starts_with(dir))))
+ .filter(|p| !seen.contains(p.as_path()))
+ .cloned()
+ .collect();
(todo, stale)
};
if !stale.is_empty() {
@@ -381,6 +395,7 @@ impl Shared {
let mut removed: Vec<PathBuf> = Vec::new();
let mut save_recent = false;
let mut rescan = false;
+ let mut rule_dirs = Vec::new();
let mut reparse: Vec<std::sync::Arc<LanguageRegistry>> = Vec::new();
for job in jobs {
match job {
@@ -388,9 +403,29 @@ impl Shared {
Job::Removed(p) => removed.extend(p),
Job::SaveRecent => save_recent = true,
Job::Rescan => rescan = true,
+ Job::IgnoreRules(dirs) => rule_dirs.extend(dirs),
Job::Reparse(before) => reparse.push(before),
}
}
+ if !rule_dirs.is_empty() {
+ {
+ let mut filter = self.filter.write();
+ *filter = std::sync::Arc::new(filter.reload());
+ }
+ rule_dirs.sort();
+ rule_dirs.dedup();
+ let mut roots: Vec<PathBuf> = Vec::new();
+ for dir in rule_dirs {
+ if !roots.iter().any(|root| dir.starts_with(root)) {
+ roots.push(dir);
+ }
+ }
+ if !rescan {
+ self.scan(Some(&roots));
+ changed.retain(|p| !roots.iter().any(|root| p.starts_with(root)));
+ removed.retain(|p| !roots.iter().any(|root| p.starts_with(root)));
+ }
+ }
if rescan {
// The scan also picks up whatever `changed` / `removed` reported.
self.full_scan();
diff --git a/crates/ide-vfs/src/lib.rs b/crates/ide-vfs/src/lib.rs
index 55cc39ec0..ccede766f 100644
--- a/crates/ide-vfs/src/lib.rs
+++ b/crates/ide-vfs/src/lib.rs
@@ -342,6 +342,8 @@ pub struct FsBatch {
/// History, deployment or `fsChanged`), but the index lists them and open editors
/// follow them, like IDEA, where only ignored folders leave the project.
pub ignored: Vec<PathBuf>,
+ /// Subtrees whose ignore rules changed (including repository-level rules).
+ pub ignore_rules: Vec<PathBuf>,
}
impl FsBatch {
@@ -352,6 +354,7 @@ impl FsBatch {
&& self.vcs.is_empty()
&& self.excluded_dirs.is_empty()
&& self.ignored.is_empty()
+ && self.ignore_rules.is_empty()
}
}
diff --git a/crates/ide-vfs/src/watch.rs b/crates/ide-vfs/src/watch.rs
index 78f567069..17b32558b 100644
--- a/crates/ide-vfs/src/watch.rs
+++ b/crates/ide-vfs/src/watch.rs
@@ -89,11 +89,16 @@ impl Watcher {
// VCS-metadata-only batches (`batch.vcs`) carry no worktree paths:
// consumers that refresh on any `fsChanged` would reschedule purely
// from the backend's own `.git/index` write.
- if !(batch.created.is_empty() && batch.modified.is_empty() && batch.removed.is_empty()) {
+ if !(batch.created.is_empty()
+ && batch.modified.is_empty()
+ && batch.removed.is_empty()
+ && batch.ignore_rules.is_empty())
+ {
sink.emit(IdeEvent::FsChanged {
created: batch.created.iter().map(Into::into).collect(),
modified: batch.modified.iter().map(Into::into).collect(),
removed: batch.removed.iter().map(Into::into).collect(),
+ ignore_rules: batch.ignore_rules.iter().map(Into::into).collect(),
});
}
if !batch.excluded_dirs.is_empty() {
@@ -659,7 +664,10 @@ impl EventFilter {
// Rebuild ignore rules first, so files in the same batch are filtered
// by the new rules regardless of path order.
let mut rule_dirs: BTreeSet<PathBuf> = BTreeSet::new();
- for path in changes.keys() {
+ let rule_events = events
+ .clone()
+ .filter(|e| matches!(e.kind, EventKind::Create(_) | EventKind::Modify(_) | EventKind::Remove(_)));
+ for path in rule_events.clone().flat_map(|e| &e.paths) {
let name = path.file_name().and_then(|n| n.to_str());
if matches!(name, Some(".gitignore" | ".ignore"))
&& let Some(dir) = path.parent()
@@ -668,7 +676,7 @@ impl EventFilter {
rule_dirs.insert(dir.to_path_buf());
}
}
- if events.flat_map(|e| &e.paths).any(|p| p.ends_with(".git/info/exclude")) {
+ if rule_events.flat_map(|e| &e.paths).any(|p| p.ends_with(".git/info/exclude")) {
self.gitignore.reload_repo_level();
rule_dirs.insert(self.root.clone());
}
@@ -729,7 +737,9 @@ impl EventFilter {
}
}
batch.excluded_dirs = excluded_dirs.into_iter().collect();
- (batch, rule_dirs.into_iter().collect())
+ batch.ignore_rules = rule_dirs.into_iter().collect();
+ let rule_dirs = batch.ignore_rules.clone();
+ (batch, rule_dirs)
}
}
@@ -1047,6 +1057,41 @@ mod tests {
assert_eq!(rules, vec![root.clone()]);
}
+ #[test]
+ fn only_rule_file_mutations_invalidate_subtrees() {
+ let tmp = tempfile::tempdir().unwrap();
+ let root = dunce::canonicalize(tmp.path()).unwrap();
+ std::fs::create_dir_all(root.join(".git/info")).unwrap();
+ std::fs::create_dir(root.join("pkg")).unwrap();
+ let filter = EventFilter::new(root.clone(), &[]);
+ for (rel, dir) in [
+ (".git/info/exclude", root.clone()),
+ ("pkg/.gitignore", root.join("pkg")),
+ ("pkg/.ignore", root.join("pkg")),
+ ] {
+ let path = root.join(rel);
+ std::fs::write(&path, "").unwrap();
+ for kind in [EventKind::Any, EventKind::Other] {
+ assert!(filter.batch(&[ev(kind, vec![path.clone()])]).ignore_rules.is_empty());
+ }
+ for kind in [
+ EventKind::Create(CreateKind::File),
+ EventKind::Modify(ModifyKind::Data(DataChange::Content)),
+ EventKind::Remove(RemoveKind::File),
+ EventKind::Modify(ModifyKind::Name(RenameMode::Both)),
+ ] {
+ let paths = if matches!(kind, EventKind::Modify(ModifyKind::Name(_))) {
+ vec![path.clone(), path.with_extension("bak")]
+ } else {
+ vec![path.clone()]
+ };
+ let batch = filter.batch(&[ev(kind, paths)]);
+ assert_eq!(batch.ignore_rules.as_slice(), std::slice::from_ref(&dir), "{kind:?} on {rel}");
+ assert!(!batch.is_empty());
+ }
+ }
+ }
+
#[test]
fn access_events_do_not_reload_rules_or_report_changes() {
for access in [
diff --git a/crates/ide-vfs/tests/vfs.rs b/crates/ide-vfs/tests/vfs.rs
index 0a08f7326..87f769ed6 100644
--- a/crates/ide-vfs/tests/vfs.rs
+++ b/crates/ide-vfs/tests/vfs.rs
@@ -439,3 +439,34 @@ fn create_file_bytes_does_not_follow_existing_symlink() {
assert_eq!(error.kind, ide_core::error::ErrorKind::AlreadyExists);
assert!(!target.exists());
}
+
+#[test]
+fn rule_changes_notify_the_affected_subtree() {
+ for (rule, subtree) in [(".git/info/exclude", ""), ("sub/.gitignore", "sub"), ("sub/.ignore", "sub")] {
+ let (_t, r) = root();
+ write(&r.join(".git/HEAD"), "ref: refs/heads/main\n");
+ write(&r.join(rule), "");
+ write(&r.join("sub/generated/file.txt"), "x");
+ let batches: Arc<Mutex<Vec<FsBatch>>> = Arc::default();
+ let events: Arc<Mutex<Vec<IdeEvent>>> = Arc::default();
+ let sink: SharedSink = {
+ let events = events.clone();
+ Arc::new(move |event: IdeEvent| events.lock().push(event))
+ };
+ let watcher = {
+ let batches = batches.clone();
+ Watcher::start(&r, vec![], sink, Box::new(move |batch| batches.lock().push(batch.clone()))).unwrap()
+ };
+ std::thread::sleep(Duration::from_millis(300));
+ write(&r.join(rule), "generated/\n");
+ let expected = r.join(subtree);
+ assert!(wait_for(&batches, |batches| batches
+ .iter()
+ .any(|b| b.ignore_rules.as_slice() == std::slice::from_ref(&expected))));
+ assert!(events.lock().iter().any(|event| matches!(
+ event,
+ IdeEvent::FsChanged { ignore_rules, .. } if ignore_rules.as_slice() == [ide_core::IpcPath::from(expected.clone())]
+ )), "{rule}: {:?}", events.lock());
+ drop(watcher);
+ }
+}
diff --git a/src/bindings.ts b/src/bindings.ts
index 8a9c12096..b47be6824 100644
--- a/src/bindings.ts
+++ b/src/bindings.ts
@@ -4883,7 +4883,9 @@ export type IdeEvent =
/** A window entered or left full screen, itself or as a member of a full-screen window group. */
{ type: "windowFullscreenChanged" } | { type: "projectTrustChanged"; root: IpcPath; trusted: boolean } |
/** Files or directories changed on disk (after debouncing, ignore rules applied). */
-{ type: "fsChanged"; created: IpcPath[]; modified: IpcPath[]; removed: IpcPath[] } |
+{ type: "fsChanged"; created: IpcPath[]; modified: IpcPath[]; removed: IpcPath[];
+/** Subtrees whose ignore rules changed, after the matchers were rebuilt. */
+ignoreRules?: IpcPath[] } |
/** Excluded or ignored folders whose contents changed; they stay out of `FsChanged`. */
{ type: "excludedDirsChanged"; dirs: IpcPath[] } |
/**
diff --git a/src/features/project-tree/model.ts b/src/features/project-tree/model.ts
index ec9130021..677f7f51d 100644
--- a/src/features/project-tree/model.ts
+++ b/src/features/project-tree/model.ts
@@ -584,7 +584,12 @@ export interface RefreshPlan {
}
export function planRefresh(
- event: { created: readonly string[]; modified: readonly string[]; removed: readonly string[] },
+ event: {
+ created: readonly string[];
+ modified: readonly string[];
+ removed: readonly string[];
+ ignoreRules?: readonly string[];
+ },
loaded: ReadonlySet<string>,
): RefreshPlan {
const reload = new Set<string>();
@@ -605,6 +610,7 @@ export function planRefresh(
drop.delete(p);
}
}
+ for (const dir of loadedList) if (event.ignoreRules?.some((root) => isSameOrInside(dir, root))) reload.add(dir);
for (const d of drop) reload.delete(d);
// A reloaded parent may report the folder as present again; keep its descendants then.
return { reload: [...reload], drop: [...drop] };
diff --git a/src/features/project-tree/store.test.ts b/src/features/project-tree/store.test.ts
index ed72b8f5f..865cb6280 100644
--- a/src/features/project-tree/store.test.ts
+++ b/src/features/project-tree/store.test.ts
@@ -98,6 +98,46 @@ describe("refresh of excluded folders", () => {
});
});
+describe("refresh on ignore-rule changes", () => {
+ it("refreshes loaded descendants once, preserving selection and unrelated folders", async () => {
+ await fs.createFile("/p/docs/sub/note.md");
+ await expandAll();
+ setSelection(new Set(["/p/docs/guide.md"]), "/p/docs/guide.md");
+ const spy = vi.spyOn(fs, "readDir");
+ fs.ignored.add("/p/docs/sub");
+ const event = {
+ created: [],
+ modified: ["/p/docs/.gitignore"],
+ removed: [],
+ ignoreRules: ["/p/docs", "/p/docs/nested"],
+ };
+
+ await applyFsChange(event);
+
+ expect(spy.mock.calls.map(([dir]) => dir).sort()).toEqual(["/p/docs", "/p/docs/sub"]);
+ expect(
+ useProjectTree
+ .getState()
+ .listings.get("/p/docs")
+ ?.find((e) => e.name === "sub")?.ignored,
+ ).toBe(true);
+ expect(useProjectTree.getState().listings.get("/p/docs/sub")?.[0]?.ignored).toBe(true);
+ expect([...useProjectTree.getState().selected]).toEqual(["/p/docs/guide.md"]);
+ spy.mockClear();
+ fs.ignored.clear();
+ await applyFsChange({ ...event, modified: [], ignoreRules: [ROOT, "/p/docs"] });
+ expect(spy.mock.calls.map(([dir]) => dir).sort()).toEqual([...useProjectTree.getState().listings.keys()].sort());
+ expect(
+ useProjectTree
+ .getState()
+ .listings.get("/p/docs")
+ ?.find((e) => e.name === "sub")?.ignored,
+ ).toBe(false);
+ expect(useProjectTree.getState().listings.get("/p/docs/sub")?.[0]?.ignored).toBe(false);
+ spy.mockRestore();
+ });
+});
+
describe("refresh on fsChanged", () => {
it("reloads affected loaded folders and keeps expansion and selection", async () => {
await loadDir(ROOT);
diff --git a/src/features/project-tree/store.ts b/src/features/project-tree/store.ts
index ddec3bc44..758edb38c 100644
--- a/src/features/project-tree/store.ts
+++ b/src/features/project-tree/store.ts
@@ -475,7 +475,12 @@ export function loadDir(path: string, force = false): Promise<void> {
}
/** Applies a backend `fsChanged` event: reloads affected loaded folders only. */
-export async function applyFsChange(event: { created: string[]; modified: string[]; removed: string[] }) {
+export async function applyFsChange(event: {
+ created: string[];
+ modified: string[];
+ removed: string[];
+ ignoreRules?: string[];
+}) {
const s = get();
if (!s.root) return;
const plan = planRefresh(event, new Set(s.listings.keys()));
diff --git a/src/features/search/__tests__/dialogs.test.tsx b/src/features/search/__tests__/dialogs.test.tsx
index ad17e6beb..41adb2894 100644
--- a/src/features/search/__tests__/dialogs.test.tsx
+++ b/src/features/search/__tests__/dialogs.test.tsx
@@ -53,7 +53,7 @@ vi.mock("../find/windowStore", async (orig) => ({
}));
const contributions = await import("@/workbench/contributions");
-const { commands } = await import("@/platform/ipc");
+const { commands, emitLocalIdeEvent } = await import("@/platform/ipc");
const { RecentPopupsOverlay } = await import("../recent/RecentPopups");
const { cycleSwitcher, showRecentPopup, hideRecentPopup, useRecentPopup } = await import("../recent/store");
const { openLocation } = await import("../common/open");
@@ -110,6 +110,17 @@ describe("Search Everywhere dialog", () => {
dispose();
});
+ it("refreshes the current file query after index invalidation finishes", async () => {
+ render(<SearchEverywhereOverlay />);
+ act(() => showSearchEverywhere("files", { query: "order" }));
+ await tick();
+ expect(document.getElementById("se-results")!.textContent).toContain("OrderController");
+ findFiles = async () => [];
+ act(() => emitLocalIdeEvent({ type: "indexState", indexing: false, files: 0, symbols: 0 }));
+ await tick();
+ expect(document.getElementById("se-results")!.textContent).not.toContain("OrderController");
+ });
+
it("the preview toggle is remembered", async () => {
render(<SearchEverywhereOverlay />);
act(() => showSearchEverywhere("all"));
diff --git a/src/features/search/__tests__/findPopup.test.tsx b/src/features/search/__tests__/findPopup.test.tsx
index bd27e709e..0e83379c7 100644
--- a/src/features/search/__tests__/findPopup.test.tsx
+++ b/src/features/search/__tests__/findPopup.test.tsx
@@ -62,6 +62,7 @@ vi.mock("@/platform/ipc", async (orig) => ({
isTauri: () => true,
}));
+const { emitLocalIdeEvent } = await import("@/platform/ipc");
const { FindInFilesOverlay } = await import("../find/FindInFiles");
const {
findHistory,
@@ -111,6 +112,19 @@ afterEach(() => {
});
describe("Find in Files popup", () => {
+ it("reruns the current search once when ignore rules change", async () => {
+ render(<FindInFilesOverlay />);
+ act(() => showFindPopup(false, { query: "order" }));
+ await settle();
+ expect(screen.getByRole("listbox", { name: "Matches" })).toHaveTextContent("a.kt");
+ const run = vi.fn(async () => null);
+ search = run;
+ act(() => emitLocalIdeEvent({ type: "fsChanged", created: [], modified: [], removed: [], ignoreRules: ["/p"] }));
+ await settle();
+ expect(run).toHaveBeenCalledTimes(1);
+ expect(screen.queryByText("a.kt")).not.toBeInTheDocument();
+ });
+
it("⇧↓ extends the selection; ↵ in Replace mode replaces the selected rows", async () => {
render(<FindInFilesOverlay />);
act(() => showFindPopup(true, { query: "order" }));
diff --git a/src/features/search/everywhere/SearchEverywhere.tsx b/src/features/search/everywhere/SearchEverywhere.tsx
index d8e8d3370..a9f93fa8f 100644
--- a/src/features/search/everywhere/SearchEverywhere.tsx
+++ b/src/features/search/everywhere/SearchEverywhere.tsx
@@ -4,7 +4,7 @@ import { useFilePresentation } from "@/platform/filePresentation";
import { useEffect, useMemo, useRef, useState, type KeyboardEvent, type MouseEvent } from "react";
import clsx from "clsx";
import { actionToggled, executeAction, executeActionFrom, getAction } from "@/platform/actions";
-import type { ProjectFileSet } from "@/platform/ipc";
+import { onIdeEvent, type ProjectFileSet } from "@/platform/ipc";
import { tx as translate, useTx } from "@/platform/i18n";
import { formatBinding, hasPrimaryModifier, hostBinding, registerKeyClaim, shortcutLabel } from "@/platform/keymap";
import {
@@ -143,6 +143,16 @@ function SearchEverywhereDialog() {
useEffect(() => () => controller.dispose(), [controller]);
const [endpointVersion, setEndpointVersion] = useState(0);
+ const [filesVersion, setFilesVersion] = useState(0);
+ useEffect(
+ () =>
+ onIdeEvent("indexState", (e) => {
+ if (e.indexing) return;
+ controller.invalidateFiles();
+ setFilesVersion((v) => v + 1);
+ }),
+ [controller],
+ );
useEffect(
() =>
onEndpointsChanged(() => {
@@ -193,7 +203,7 @@ function SearchEverywhereDialog() {
includeDisabled: tab === "actions" ? includeNonProject : undefined,
extra,
});
- }, [controller, searchQuery, tab, includeNonProject, fileSet, filter, extra, endpointVersion]);
+ }, [controller, searchQuery, tab, includeNonProject, fileSet, filter, extra, endpointVersion, filesVersion]);
useEffect(() => {
inputRef.current?.select();
diff --git a/src/features/search/everywhere/controller.ts b/src/features/search/everywhere/controller.ts
index 9959660d4..71f7f55f5 100644
--- a/src/features/search/everywhere/controller.ts
+++ b/src/features/search/everywhere/controller.ts
@@ -115,6 +115,10 @@ export class SeController {
this.signatures.delete("endpoints");
}
+ invalidateFiles() {
+ for (const id of ["files", "classes", "symbols", "text"] as const) this.signatures.delete(id);
+ }
+
run(req: SeRequest) {
const gen = ++this.gen;
this.disposed = false;
diff --git a/src/features/search/find/FindInFiles.tsx b/src/features/search/find/FindInFiles.tsx
index 97ff2d598..572dae762 100644
--- a/src/features/search/find/FindInFiles.tsx
+++ b/src/features/search/find/FindInFiles.tsx
@@ -5,7 +5,7 @@ import { executeAction } from "@/platform/actions";
import { setContext } from "@/platform/context";
import { t, useTxTemplate, tx } from "@/platform/i18n";
import { formatBinding, hostBinding, shortcutLabel } from "@/platform/keymap";
-import { call, commands, isTauri, type SearchScope } from "@/platform/ipc";
+import { call, commands, isTauri, onIdeEvent, type SearchScope } from "@/platform/ipc";
import { useProject } from "@/platform/project";
import { useProjectModules } from "@/platform/projectRoots";
import { EDIT_SCOPES_ACTION, useCustomScopeList } from "@/platform/search";
@@ -235,6 +235,13 @@ function FindInFilesDialog() {
const stale = state.stale || (state.query ? JSON.stringify(state.query) !== queryKey : !!s.pattern);
const currentQuery = useRef(queryKey);
const [rerun, setRerun] = useState(0);
+ useEffect(
+ () =>
+ onIdeEvent("fsChanged", (e) => {
+ if (e.ignoreRules?.length) setRerun((v) => v + 1);
+ }),
+ [],
+ );
useLayoutEffect(() => {
currentQuery.current = queryKey;
session.invalidate();
diff --git a/src/features/search/index.ts b/src/features/search/index.ts
index 725549b5a..1efb2964a 100644
--- a/src/features/search/index.ts
+++ b/src/features/search/index.ts
@@ -36,7 +36,14 @@ import { installTracking, resetTracking } from "./common/tracking";
import { hideSearchEverywhere, showSearchEverywhere, useSearchEverywhere } from "./everywhere/store";
import { ScopesDialogOverlay, showScopesDialog } from "./find/ScopesDialog";
import { hideFindPopup, parseFindArg, runFindPopupCommand, showFindPopup, useFindPopup } from "./find/store";
-import { disposeFindWindow, openEditorResults, rerunActiveFindTab, useFindHeaderMenu } from "./find/windowStore";
+import {
+ disposeFindWindow,
+ openEditorResults,
+ rerunActiveFindTab,
+ rerunFindTab,
+ useFindHeaderMenu,
+ useFindWindow,
+} from "./find/windowStore";
import { cycleSwitcher, hideRecentPopup, showRecentPopup, useRecentPopup } from "./recent/store";
import { useFileStructurePopup } from "./structure/popupStore";
import { useOutline, useStructureOptions } from "./structure/store";
@@ -539,6 +546,8 @@ export function activate(): void | (() => void) {
useFindPopup.setState({ scopeTab: "project", directory: "" });
}),
onIdeEvent("fsChanged", (e) => {
+ if (e.ignoreRules?.length)
+ for (const tab of useFindWindow.getState().tabs) if (!tab.editorResults) rerunFindTab(tab.id);
if (!e.removed.length) return;
updateBookmarks((list) => e.removed.reduce<Bookmark[]>((acc, p) => renameBookmarks(acc, p, null), [...list]));
updateBookmarkData((d) => {
diff --git a/src/features/vcs/store.ts b/src/features/vcs/store.ts
index 3e64d3baa..024f3e533 100644
--- a/src/features/vcs/store.ts
+++ b/src/features/vcs/store.ts
@@ -301,7 +301,7 @@ export function installVcsStore(): () => void {
// on those alone rewrites `.git/index` and re-triggers this handler.
const offFs = onIdeEvent("fsChanged", (e) => {
const worktree = [...e.created, ...e.modified, ...e.removed].some((p) => !/(^|[/\\])\.git([/\\]|$)/.test(p));
- if (worktree) scheduleRefresh(250);
+ if (worktree || e.ignoreRules?.length) scheduleRefresh(250);
});
const offSettings = onWorkflowSettingsChange(
(s) => s.vcs.showDirtyDirectories,