Skip to content

Commit 4fe2ec1

Browse files
authored
Dev/seanmcm/fix blank config with file watcher limit (#1709)
Fix blank config in the status bar (and browse engine stuck initializing) when the file watcher limit is hit.
1 parent 83a9cb2 commit 4fe2ec1

File tree

2 files changed

+39
-30
lines changed

2 files changed

+39
-30
lines changed

Extension/src/LanguageServer/configurations.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -346,13 +346,18 @@ export class CppProperties {
346346
filePaths.add(c.compileCommands);
347347
}
348348
});
349-
filePaths.forEach((path: string) => {
350-
this.compileCommandFileWatchers.push(fs.watch(path, (event: string, filename: string) => {
351-
if (event !== "rename") {
352-
this.onCompileCommandsChanged(path);
353-
}
354-
}));
355-
});
349+
try {
350+
filePaths.forEach((path: string) => {
351+
this.compileCommandFileWatchers.push(fs.watch(path, (event: string, filename: string) => {
352+
if (event !== "rename") {
353+
this.onCompileCommandsChanged(path);
354+
}
355+
}));
356+
});
357+
} catch (e) {
358+
// The file watcher limit is hit.
359+
// TODO: Check if the compile commands file has a higher timestamp during the interval timer.
360+
}
356361
}
357362

358363
public handleConfigurationEditCommand(onSuccess: (document: vscode.TextDocument) => void): void {

Extension/src/LanguageServer/extension.ts

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -384,29 +384,33 @@ function reportMacCrashes(): void {
384384
}
385385

386386
// vscode.workspace.createFileSystemWatcher only works in workspace folders.
387-
fs.watch(crashFolder, (event, filename) => {
388-
if (event !== "rename") {
389-
return;
390-
}
391-
if (filename === prevCrashFile) {
392-
return;
393-
}
394-
prevCrashFile = filename;
395-
if (!filename.startsWith("Microsoft.VSCode.CPP.")) {
396-
return;
397-
}
398-
// Wait 5 seconds to allow time for the crash log to finish being written.
399-
setTimeout(() => {
400-
fs.readFile(path.resolve(crashFolder, filename), 'utf8', (err, data) => {
401-
if (err) {
402-
// Try again?
403-
fs.readFile(path.resolve(crashFolder, filename), 'utf8', handleCrashFileRead);
404-
return;
405-
}
406-
handleCrashFileRead(err, data);
407-
});
408-
}, 5000);
409-
});
387+
try {
388+
fs.watch(crashFolder, (event, filename) => {
389+
if (event !== "rename") {
390+
return;
391+
}
392+
if (filename === prevCrashFile) {
393+
return;
394+
}
395+
prevCrashFile = filename;
396+
if (!filename.startsWith("Microsoft.VSCode.CPP.")) {
397+
return;
398+
}
399+
// Wait 5 seconds to allow time for the crash log to finish being written.
400+
setTimeout(() => {
401+
fs.readFile(path.resolve(crashFolder, filename), 'utf8', (err, data) => {
402+
if (err) {
403+
// Try again?
404+
fs.readFile(path.resolve(crashFolder, filename), 'utf8', handleCrashFileRead);
405+
return;
406+
}
407+
handleCrashFileRead(err, data);
408+
});
409+
}, 5000);
410+
});
411+
} catch (e) {
412+
// The file watcher limit is hit (may not be possible on Mac, but just in case).
413+
}
410414
});
411415
}
412416
}

0 commit comments

Comments
 (0)