From fb5003a940cd660b3e1ce4ed3be7d42d7ed63d51 Mon Sep 17 00:00:00 2001 From: Brett Saviano Date: Mon, 28 Apr 2025 08:04:44 -0400 Subject: [PATCH] Ignore duplicate file change events in local workspace folders --- src/utils/documentIndex.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/utils/documentIndex.ts b/src/utils/documentIndex.ts index 8cdcf476..6a5a40e1 100644 --- a/src/utils/documentIndex.ts +++ b/src/utils/documentIndex.ts @@ -163,6 +163,8 @@ export async function indexWorkspaceFolder(wsFolder: vscode.WorkspaceFolder): Pr // Limit FileSystemWatcher events that may produce a putDoc() // request to 50 concurrent calls to avoid hammering the server const restRateLimiter = new RateLimiter(50); + // A cache of the last time each file was last changed + const lastFileChangeTimes: Map = new Map(); // Index classes and routines that currently exist vscode.workspace .findFiles(new vscode.RelativePattern(wsFolder, "{**/*.cls,**/*.mac,**/*.int,**/*.inc}")) @@ -187,8 +189,10 @@ export async function indexWorkspaceFolder(wsFolder: vscode.WorkspaceFolder): Pr return; } const uriString = uri.toString(); + const lastFileChangeTime = lastFileChangeTimes.get(uriString) ?? 0; + lastFileChangeTimes.set(uriString, Date.now()); if (openCustomEditors.includes(uriString)) { - // This class is open in a graphical editor, so its name will not change + // This class is open in a low-code editor, so its name will not change // and any updates to the class will be handled by that editor touchedByVSCode.delete(uriString); return; @@ -201,6 +205,12 @@ export async function indexWorkspaceFolder(wsFolder: vscode.WorkspaceFolder): Pr touchedByVSCode.delete(uriString); return; } + if (lastFileChangeTimes.get(uriString) - lastFileChangeTime < 300) { + // This file change event came too quickly after the last one to be a + // meaningful change triggered by the user, so consider it a duplicate + touchedByVSCode.delete(uriString); + return; + } const api = new AtelierAPI(uri); const conf = vscode.workspace.getConfiguration("objectscript", wsFolder); const syncLocalChanges: string = conf.get("syncLocalChanges");