Don't dirty a source file and its dependencies just because we receive a file system change event. This is especially important if the file is already open, in which case file system change events are ignored.

This commit is contained in:
Eric Traut 2020-04-27 23:22:27 -07:00
parent 76c0a97e5f
commit 0f7f21a978
4 changed files with 22 additions and 13 deletions

View File

@ -89,7 +89,7 @@ export class BackgroundAnalysisProgram {
updateOpenFileContents(path: string, version: number | null, contents: string) {
this.setFileOpened(path, version, contents);
this.markFilesDirty([path]);
this.markFilesDirty([path], true);
}
setFileClosed(filePath: string) {
@ -103,9 +103,9 @@ export class BackgroundAnalysisProgram {
this._program.markAllFilesDirty(evenIfContentsAreSame);
}
markFilesDirty(filePaths: string[]) {
this._backgroundAnalysis?.markFilesDirty(filePaths);
this._program.markFilesDirty(filePaths);
markFilesDirty(filePaths: string[], evenIfContentsAreSame: boolean) {
this._backgroundAnalysis?.markFilesDirty(filePaths, evenIfContentsAreSame);
this._program.markFilesDirty(filePaths, evenIfContentsAreSame);
}
setCompletionCallback(callback?: AnalysisCompleteCallback) {

View File

@ -244,16 +244,24 @@ export class Program {
}
}
markFilesDirty(filePaths: string[]) {
markFilesDirty(filePaths: string[], evenIfContentsAreSame: boolean) {
const markDirtyMap = new Map<string, boolean>();
filePaths.forEach((filePath) => {
const sourceFileInfo = this._sourceFileMap.get(filePath);
if (sourceFileInfo) {
sourceFileInfo.sourceFile.markDirty();
// If !evenIfContentsAreSame, see if the on-disk contents have
// changed. If the file is open, the on-disk contents don't matter
// because we'll receive updates directly from the client.
if (
evenIfContentsAreSame ||
(!sourceFileInfo.isOpenByClient && !sourceFileInfo.sourceFile.didContentsChangeOnDisk())
) {
sourceFileInfo.sourceFile.markDirty();
// Mark any files that depend on this file as dirty
// also. This will retrigger analysis of these other files.
this._markFileDirtyRecursive(sourceFileInfo, markDirtyMap);
// Mark any files that depend on this file as dirty
// also. This will retrigger analysis of these other files.
this._markFileDirtyRecursive(sourceFileInfo, markDirtyMap);
}
}
});

View File

@ -887,7 +887,7 @@ export class AnalyzerService {
}
if (event === 'change') {
this._backgroundAnalysisProgram.markFilesDirty([path]);
this._backgroundAnalysisProgram.markFilesDirty([path], false);
this._scheduleReanalysis(false);
} else {
this._scheduleReanalysis(true);

View File

@ -97,8 +97,8 @@ export class BackgroundAnalysisBase {
this._enqueueRequest({ requestType: 'markAllFilesDirty', data: evenIfContentsAreSame });
}
markFilesDirty(filePaths: string[]) {
this._enqueueRequest({ requestType: 'markFilesDirty', data: filePaths });
markFilesDirty(filePaths: string[], evenIfContentsAreSame: boolean) {
this._enqueueRequest({ requestType: 'markFilesDirty', data: { filePaths, evenIfContentsAreSame } });
}
startAnalysis(token: CancellationToken) {
@ -306,7 +306,8 @@ export class BackgroundAnalysisRunnerBase {
}
case 'markFilesDirty': {
this._program.markFilesDirty(msg.data);
const { filePaths, evenIfContentsAreSame } = msg.data;
this._program.markFilesDirty(filePaths, evenIfContentsAreSame);
break;
}