Skip to content

Commit f449ef9

Browse files
authored
Ignore duplicate file change events in local workspace folders (intersystems-community#1539)
1 parent e0ce455 commit f449ef9

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/utils/documentIndex.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ export async function indexWorkspaceFolder(wsFolder: vscode.WorkspaceFolder): Pr
163163
// Limit FileSystemWatcher events that may produce a putDoc()
164164
// request to 50 concurrent calls to avoid hammering the server
165165
const restRateLimiter = new RateLimiter(50);
166+
// A cache of the last time each file was last changed
167+
const lastFileChangeTimes: Map<string, number> = new Map();
166168
// Index classes and routines that currently exist
167169
vscode.workspace
168170
.findFiles(new vscode.RelativePattern(wsFolder, "{**/*.cls,**/*.mac,**/*.int,**/*.inc}"))
@@ -187,8 +189,10 @@ export async function indexWorkspaceFolder(wsFolder: vscode.WorkspaceFolder): Pr
187189
return;
188190
}
189191
const uriString = uri.toString();
192+
const lastFileChangeTime = lastFileChangeTimes.get(uriString) ?? 0;
193+
lastFileChangeTimes.set(uriString, Date.now());
190194
if (openCustomEditors.includes(uriString)) {
191-
// This class is open in a graphical editor, so its name will not change
195+
// This class is open in a low-code editor, so its name will not change
192196
// and any updates to the class will be handled by that editor
193197
touchedByVSCode.delete(uriString);
194198
return;
@@ -201,6 +205,12 @@ export async function indexWorkspaceFolder(wsFolder: vscode.WorkspaceFolder): Pr
201205
touchedByVSCode.delete(uriString);
202206
return;
203207
}
208+
if (lastFileChangeTimes.get(uriString) - lastFileChangeTime < 300) {
209+
// This file change event came too quickly after the last one to be a
210+
// meaningful change triggered by the user, so consider it a duplicate
211+
touchedByVSCode.delete(uriString);
212+
return;
213+
}
204214
const api = new AtelierAPI(uri);
205215
const conf = vscode.workspace.getConfiguration("objectscript", wsFolder);
206216
const syncLocalChanges: string = conf.get("syncLocalChanges");

0 commit comments

Comments
 (0)