Skip to content

Commit

Permalink
hopefully better way to detect whether analysis is fully completed wh…
Browse files Browse the repository at this point in the history
…en determining whether to update the baseline file
  • Loading branch information
DetachHead committed Sep 27, 2024
1 parent af48825 commit 54ee1a1
Showing 1 changed file with 19 additions and 25 deletions.
44 changes: 19 additions & 25 deletions packages/pyright-internal/src/languageServerBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1276,7 +1276,13 @@ export abstract class LanguageServerBase implements LanguageServerInterface, Dis
);

// if any baselined diagnostics disappeared, update the baseline for the effected files
if (results.reason === 'analysis') {
if (
results.reason === 'analysis' &&
// if there are still any files requirign analysis, don't update the baseline file as it could
// incorrectly delete diagnostics that are still present
!results.requiringAnalysisCount.files &&
!results.requiringAnalysisCount.cells
) {
const filesRequiringBaselineUpdate = new Map<Workspace, FileDiagnostics[]>();
for (const [fileUri, savedFileInfo] of this.savedFilesForBaselineUpdate.entries()) {
// can't use result.diagnostics because we need the diagnostics from the previous analysis since
Expand All @@ -1285,33 +1291,21 @@ export abstract class LanguageServerBase implements LanguageServerInterface, Dis
if (!fileDiagnostics || fileDiagnostics.reason !== 'analysis') {
continue;
}
const sourceFile = savedFileInfo.workspace.service.getSourceFile(fileUri);
const baselineInfo = getBaselinedErrorsForFile(this.fs, savedFileInfo.workspace.rootUri!, fileUri);
if (
sourceFile &&
// if checking is still required, we shouldn't write the baseline because there may be errors that are still
// present but haven't appeared yet. we don't want to remove anything from the baseline file until we're
// certain there are no unbaselined diagnostics left
(!sourceFile.isCheckingRequired() ||
// when using background analysis isCheckingRequired is always true for some reason so we can't rely on
// that.
savedFileInfo.workspace.service.backgroundAnalysisProgram.backgroundAnalysis)
// no baseline file exists or no baselined errors exist for this file
!baselineInfo.length ||
// there are diagnostics that haven't been baselined, so we don't want to write them
// because the user will have to either fix the diagnostics or explicitly write them to the
// baseline themselves
fileDiagnostics.diagnostics.some((diagnostic) => !diagnostic.baselineStatus)
) {
const baselineInfo = getBaselinedErrorsForFile(this.fs, savedFileInfo.workspace.rootUri!, fileUri);
if (
// no baseline file exists or no baselined errors exist for this file
!baselineInfo.length ||
// there are diagnostics that haven't been baselined, so we don't want to write them
// because the user will have to either fix the diagnostics or explicitly write them to the
// baseline themselves
fileDiagnostics.diagnostics.some((diagnostic) => !diagnostic.baselineStatus)
) {
continue;
}
if (!filesRequiringBaselineUpdate.has(savedFileInfo.workspace)) {
filesRequiringBaselineUpdate.set(savedFileInfo.workspace, []);
}
filesRequiringBaselineUpdate.get(savedFileInfo.workspace)!.push(fileDiagnostics);
continue;
}
if (!filesRequiringBaselineUpdate.has(savedFileInfo.workspace)) {
filesRequiringBaselineUpdate.set(savedFileInfo.workspace, []);
}
filesRequiringBaselineUpdate.get(savedFileInfo.workspace)!.push(fileDiagnostics);
}
for (const [workspace, files] of filesRequiringBaselineUpdate.entries()) {
writeDiagnosticsToBaselineFile(this.fs, workspace.rootUri!, files, true);
Expand Down

0 comments on commit 54ee1a1

Please sign in to comment.