fix(editor): synchronize external file changes on focus (#564)

Open files only reloaded from file watcher events, so a change the watcher skipped stayed stale in its tab: excluded and git-ignored folders, files outside the project, and missed events.

- Re-check open documents against disk when the window gains focus, off the UI thread and debounced. Clean documents reload, dirty ones keep the existing warning, and unchanged ones cost one metadata call.
- Refresh the project tree and Git status on the same focus event.
- Add "Synchronize external changes when switching to the IDE window" under System Settings, on by default.

Fixes #563
Цей коміт міститься в:
l0ng-ai authored and GitHub committed 2026-10-31 20:12:00 +08:00
1 джерело 4796265b5c
коміт 17e3cd2b39
18 files changed
+510

No files matched your search

+5
Переглянути файл
@@ -147,6 +147,11 @@ describe("settings staging", () => {
});
describe("validateSettings", () => {
it("defaults focus synchronization on and preserves an explicit opt-out", () => {
expect(validateSettings({ files: {} }).files.syncOnFocus).toBe(true);
expect(validateSettings({ files: { syncOnFocus: false } }).files.syncOnFocus).toBe(false);
});
it("fills defaults for missing or malformed values", () => {
expect(validateSettings(undefined)).toEqual(DEFAULT_SETTINGS);
expect(validateSettings("garbage")).toEqual(DEFAULT_SETTINGS);
+3
Переглянути файл
@@ -62,6 +62,7 @@ export interface ValidSettings extends WorkflowSettings {
keymap: string;
files: {
autoSave: boolean;
syncOnFocus: boolean;
exclude: string[];
ignoredNames: string[];
trimTrailingWhitespace: boolean;
@@ -134,6 +135,7 @@ export const DEFAULT_SETTINGS: ValidSettings = {
keymap: "intellij-macos",
files: {
autoSave: true,
syncOnFocus: true,
exclude: ["**/.git", "**/node_modules", "**/target"],
ignoredNames: [...DEFAULT_IGNORED_NAMES],
trimTrailingWhitespace: true,
@@ -233,6 +235,7 @@ export function validateSettings(raw: Settings | unknown): ValidSettings {
keymap: str(root.keymap, d.keymap),
files: {
autoSave: bool(f.autoSave, d.files.autoSave),
syncOnFocus: bool(f.syncOnFocus, d.files.syncOnFocus),
exclude: Array.isArray(f.exclude)
? f.exclude.filter((x): x is string => typeof x === "string" && !!x.trim())
: [...d.files.exclude],
+5
Переглянути файл
@@ -588,6 +588,11 @@ export const BEHAVIOR_PAGES: PageSpec[] = [
key: "files.autoSave",
label: "Save files when switching to a different application or a built-in terminal",
},
{
kind: "toggle",
key: "files.syncOnFocus",
label: "Synchronize external changes when switching to the IDE window",
},
],
},
{