mirror of
https://github.com/microsoft/pyright.git
synced 2024-09-19 04:07:36 +03:00
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:
parent
76c0a97e5f
commit
0f7f21a978
@ -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) {
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user