@@ -169,7 +169,7 @@ export async function indexWorkspaceFolder(wsFolder: vscode.WorkspaceFolder): Pr
169
169
// request to 50 concurrent calls to avoid hammering the server
170
170
const restRateLimiter = new RateLimiter ( 50 ) ;
171
171
// A cache of the last time each file was last changed
172
- const lastFileChangeTimes : Map < string , number > = new Map ( ) ;
172
+ const lastChangeMtimes : Map < string , number > = new Map ( ) ;
173
173
// Index classes and routines that currently exist
174
174
vscode . workspace
175
175
. findFiles ( new vscode . RelativePattern ( wsFolder , "{**/*.cls,**/*.mac,**/*.int,**/*.inc}" ) )
@@ -178,7 +178,7 @@ export async function indexWorkspaceFolder(wsFolder: vscode.WorkspaceFolder): Pr
178
178
const watcher = vscode . workspace . createFileSystemWatcher ( new vscode . RelativePattern ( wsFolder , "**/*" ) ) ;
179
179
const debouncedCompile = generateCompileFn ( ) ;
180
180
const debouncedDelete = generateDeleteFn ( wsFolder . uri ) ;
181
- const updateIndexAndSyncChanges = async ( uri : vscode . Uri ) : Promise < void > => {
181
+ const updateIndexAndSyncChanges = async ( uri : vscode . Uri , created = false ) : Promise < void > => {
182
182
if ( uri . scheme != wsFolder . uri . scheme ) {
183
183
// We don't care about virtual files that might be
184
184
// part of the workspace folder, like "git" files
@@ -194,8 +194,22 @@ export async function indexWorkspaceFolder(wsFolder: vscode.WorkspaceFolder): Pr
194
194
return ;
195
195
}
196
196
const uriString = uri . toString ( ) ;
197
- const lastFileChangeTime = lastFileChangeTimes . get ( uriString ) ?? 0 ;
198
- lastFileChangeTimes . set ( uriString , Date . now ( ) ) ;
197
+ if ( ! created ) {
198
+ const stat = await vscode . workspace . fs . stat ( uri ) . then ( undefined , ( ) => { } ) ;
199
+ if ( ! stat ) {
200
+ // If we couldn't get the file's metadata then something is very wrong
201
+ touchedByVSCode . delete ( uriString ) ;
202
+ return ;
203
+ }
204
+ const lastChangeMtime = lastChangeMtimes . get ( uriString ) ?? 0 ;
205
+ lastChangeMtimes . set ( uriString , stat . mtime ) ;
206
+ if ( stat . mtime == lastChangeMtime ) {
207
+ // This file change event was triggered on the same version
208
+ // of the file as the last event, so ignore this one
209
+ touchedByVSCode . delete ( uriString ) ;
210
+ return ;
211
+ }
212
+ }
199
213
if ( openLowCodeEditors . has ( uriString ) ) {
200
214
// This class is open in a low-code editor, so its name will not change
201
215
// and any updates to the class will be handled by that editor
@@ -210,12 +224,6 @@ export async function indexWorkspaceFolder(wsFolder: vscode.WorkspaceFolder): Pr
210
224
touchedByVSCode . delete ( uriString ) ;
211
225
return ;
212
226
}
213
- if ( lastFileChangeTimes . get ( uriString ) - lastFileChangeTime < 300 ) {
214
- // This file change event came too quickly after the last one to be a
215
- // meaningful change triggered by the user, so consider it a duplicate
216
- touchedByVSCode . delete ( uriString ) ;
217
- return ;
218
- }
219
227
const api = new AtelierAPI ( uri ) ;
220
228
const conf = vscode . workspace . getConfiguration ( "objectscript" , wsFolder ) ;
221
229
const syncLocalChanges : string = conf . get ( "syncLocalChanges" ) ;
@@ -244,7 +252,7 @@ export async function indexWorkspaceFolder(wsFolder: vscode.WorkspaceFolder): Pr
244
252
}
245
253
} ;
246
254
watcher . onDidChange ( ( uri ) => restRateLimiter . call ( ( ) => updateIndexAndSyncChanges ( uri ) ) ) ;
247
- watcher . onDidCreate ( ( uri ) => restRateLimiter . call ( ( ) => updateIndexAndSyncChanges ( uri ) ) ) ;
255
+ watcher . onDidCreate ( ( uri ) => restRateLimiter . call ( ( ) => updateIndexAndSyncChanges ( uri , true ) ) ) ;
248
256
watcher . onDidDelete ( ( uri ) => {
249
257
if ( uri . scheme != wsFolder . uri . scheme ) {
250
258
// We don't care about virtual files that might be
0 commit comments