Skip to content

Commit

Permalink
don't remove baselined errors from unopened files when running the wr…
Browse files Browse the repository at this point in the history
…itebaseline task
  • Loading branch information
DetachHead committed Aug 27, 2024
1 parent 2068078 commit ae3f4d4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
15 changes: 13 additions & 2 deletions packages/pyright-internal/src/baseline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,19 @@ export const writeBaselineFile = (rootDir: Uri, baselineData: BaselineFile) => {
writeFileSync(baselineFile.getPath(), JSON.stringify(baselineData, undefined, 4));
};

export const writeDiagnosticsToBaselineFile = async (rootDir: Uri, filesWithDiagnostics: FileDiagnostics[]) => {
const baselineData = diagnosticsToBaseline(rootDir, filesWithDiagnostics);
/**
* @param openFilesOnly whether or not the diagnostics were only reported on the open files. setting this to `true` prevents
* it from deleting baselined errors from files that weren't opened
*/
export const writeDiagnosticsToBaselineFile = async (
rootDir: Uri,
filesWithDiagnostics: FileDiagnostics[],
openFilesOnly: boolean
) => {
let baselineData = diagnosticsToBaseline(rootDir, filesWithDiagnostics);
if (openFilesOnly) {
baselineData = { files: { ...getBaselinedErrors(rootDir).files, ...baselineData.files } };
}
writeBaselineFile(rootDir, baselineData);
};

Expand Down
3 changes: 1 addition & 2 deletions packages/pyright-internal/src/commands/writeBaseline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export class WriteBaselineCommand implements ServerCommand {
this._ls.documentsWithDiagnostics[Object.keys(this._ls.documentsWithDiagnostics)[0]].fileUri
)
).rootUri!;
// TODO: this very likely will delete any baselined errors from files that aren't open. FIX BEFORE MERGE!!!!!
return writeDiagnosticsToBaselineFile(workspaceRoot, Object.values(this._ls.documentsWithDiagnostics));
return writeDiagnosticsToBaselineFile(workspaceRoot, Object.values(this._ls.documentsWithDiagnostics), true);
}
}
2 changes: 1 addition & 1 deletion packages/pyright-internal/src/pyright.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ async function runSingleThreaded(
? Uri.file(options.executionRoot ?? '', service.serviceProvider)
: options.executionRoot;
if (args.writebaseline) {
writeDiagnosticsToBaselineFile(rootDir, results.diagnostics);
writeDiagnosticsToBaselineFile(rootDir, results.diagnostics, false);
}
results.diagnostics = filterOutBaselinedDiagnostics(rootDir, results.diagnostics);
let errorCount = 0;
Expand Down

0 comments on commit ae3f4d4

Please sign in to comment.