Skip to content

Commit

Permalink
don't sort diagnostics because it was making a bunch of tests fail. i…
Browse files Browse the repository at this point in the history
… assume they're expecting a specific order
  • Loading branch information
DetachHead committed Sep 29, 2024
1 parent 32b8d31 commit 3db8dd8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
4 changes: 2 additions & 2 deletions packages/pyright-internal/src/analyzer/sourceFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import { SourceMapper } from './sourceMapper';
import { SymbolTable } from './symbol';
import { TestWalker } from './testWalker';
import { TypeEvaluator } from './typeEvaluatorTypes';
import { sortDiagnosticsAndMatchBaseline } from '../baseline';
import { matchBaselinedDiagnostics } from '../baseline';

// Limit the number of import cycles tracked per source file.
const _maxImportCyclesPerFile = 4;
Expand Down Expand Up @@ -1247,7 +1247,7 @@ export class SourceFile {
// Now add in the "unnecessary type ignore" diagnostics.
diagList = diagList.concat(unnecessaryTypeIgnoreDiags);

diagList = sortDiagnosticsAndMatchBaseline(this.fileSystem, configOptions.projectRoot, this._uri, diagList);
diagList = matchBaselinedDiagnostics(this.fileSystem, configOptions.projectRoot, this._uri, diagList);

// If we're not returning any diagnostics, filter out all of
// the errors and warnings, leaving only the unreachable code
Expand Down
13 changes: 10 additions & 3 deletions packages/pyright-internal/src/baseline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,21 @@ export const getBaselinedErrorsForFile = (fs: ReadOnlyFileSystem, rootDir: Uri,
return result ?? [];
};

export const sortDiagnosticsAndMatchBaseline = (
export const matchBaselinedDiagnostics = (
fs: ReadOnlyFileSystem,
rootDir: Uri,
file: Uri,
diagnostics: Diagnostic[]
): Diagnostic[] => {
diagnostics.sort(compareDiagnostics);
const diff = diffArrays(getBaselinedErrorsForFile(fs, rootDir, file), diagnostics, {
const baselinedDiagnostics = getBaselinedErrorsForFile(fs, rootDir, file);
if (baselinedDiagnostics.length) {
// don't bother sorting if there's no baselined diagnostics to compare against, as they get sorted
// later anyway
diagnostics = [...diagnostics].sort(compareDiagnostics);
} else {
return diagnostics;
}
const diff = diffArrays(baselinedDiagnostics, diagnostics, {
comparator: (baselinedDiagnostic, diagnostic) =>
baselinedDiagnostic.code === diagnostic.getRule() &&
baselinedDiagnostic.range.startColumn === diagnostic.range.start.character &&
Expand Down
16 changes: 9 additions & 7 deletions packages/pyright-internal/src/pyright.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { CommandLineOptions as PyrightCommandLineOptions } from './common/comman
import { ConsoleInterface, LogLevel, StandardConsole, StderrConsole } from './common/console';
import { fail } from './common/debug';
import { createDeferred } from './common/deferred';
import { Diagnostic, DiagnosticCategory } from './common/diagnostic';
import { compareDiagnostics, Diagnostic, DiagnosticCategory } from './common/diagnostic';
import { FileDiagnostics } from './common/diagnosticSink';
import { FullAccessHost } from './common/fullAccessHost';
import { combinePaths, normalizePath } from './common/pathUtils';
Expand Down Expand Up @@ -1199,7 +1199,7 @@ function reportDiagnosticsAsJsonWithoutLogging(
};

fileDiagnostics.forEach((fileDiag) => {
fileDiag.diagnostics.forEach((diag) => {
fileDiag.diagnostics.sort(compareDiagnostics).forEach((diag) => {
if (
diag.category === DiagnosticCategory.Error ||
diag.category === DiagnosticCategory.Warning ||
Expand Down Expand Up @@ -1308,11 +1308,13 @@ function reportDiagnosticsAsText(

fileDiagnostics.forEach((fileDiagnostics) => {
// Don't report unused code or deprecated diagnostics.
const fileErrorsAndWarnings = fileDiagnostics.diagnostics.filter(
(diag) =>
!isHintDiagnostic(diag) &&
isDiagnosticIncluded(convertDiagnosticCategoryToSeverity(diag.category), minSeverityLevel)
);
const fileErrorsAndWarnings = fileDiagnostics.diagnostics
.filter(
(diag) =>
!isHintDiagnostic(diag) &&
isDiagnosticIncluded(convertDiagnosticCategoryToSeverity(diag.category), minSeverityLevel)
)
.sort(compareDiagnostics);

if (fileErrorsAndWarnings.length > 0) {
console.info(`${fileDiagnostics.fileUri.toUserVisibleString()}`);
Expand Down

0 comments on commit 3db8dd8

Please sign in to comment.