Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle errors reading & writing the baseline file and report config / baseline errors more reliably #947

Merged
merged 10 commits into from
Dec 15, 2024
Merged
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,7 @@
},
// package.json file copied into the pypi package
// this is a top-level folder but the ** is still needed due to https://github.com/microsoft/vscode/issues/92114
"npm.exclude": "**/basedpyright/*"
"npm.exclude": "**/basedpyright/*",
"git.blame.editorDecoration.enabled": true,
"git.blame.statusBarItem.enabled": true
}
3 changes: 0 additions & 3 deletions packages/pyright-internal/src/analyzer/analysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export interface AnalysisResults {
checkingOnlyOpenFiles: boolean;
requiringAnalysisCount: RequiringAnalysisCount;
fatalErrorOccurred: boolean;
configParseErrors: string[];
elapsedTime: number;
error?: Error | undefined;
reason: 'analysis' | 'tracking';
Expand Down Expand Up @@ -75,7 +74,6 @@ export function analyzeProgram(
requiringAnalysisCount: requiringAnalysisCount,
checkingOnlyOpenFiles: program.isCheckingOnlyOpenFiles(),
fatalErrorOccurred: false,
configParseErrors: [],
elapsedTime,
reason: 'analysis',
});
Expand All @@ -94,7 +92,6 @@ export function analyzeProgram(
requiringAnalysisCount: { files: 0, cells: 0 },
checkingOnlyOpenFiles: true,
fatalErrorOccurred: true,
configParseErrors: [],
elapsedTime: 0,
error: debug.getSerializableError(e),
reason: 'analysis',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,6 @@ export class BackgroundAnalysisProgram {
requiringAnalysisCount: this._program.getFilesToAnalyzeCount(),
checkingOnlyOpenFiles: this._program.isCheckingOnlyOpenFiles(),
fatalErrorOccurred: false,
configParseErrors: [],
elapsedTime: 0,
reason: 'tracking',
});
Expand Down
10 changes: 10 additions & 0 deletions packages/pyright-internal/src/analyzer/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import { createTypeEvaluatorWithTracker } from './typeEvaluatorWithTracker';
import { PrintTypeFlags } from './typePrinter';
import { TypeStubWriter } from './typeStubWriter';
import { Type } from './types';
import { BaselineHandler } from '../baseline';

const _maxImportDepth = 256;

Expand Down Expand Up @@ -137,6 +138,8 @@ export class Program {
private _editModeTracker = new EditModeTracker();
private _sourceFileFactory: ISourceFileFactory;

baselineHandler: BaselineHandler;

constructor(
initialImportResolver: ImportResolver,
initialConfigOptions: ConfigOptions,
Expand All @@ -151,6 +154,7 @@ export class Program {
this._configOptions = initialConfigOptions;

this._sourceFileFactory = serviceProvider.sourceFileFactory();
this.baselineHandler = new BaselineHandler(this.fileSystem, this._configOptions, this._console);

this._cacheManager = serviceProvider.tryGet(ServiceKeys.cacheManager) ?? new CacheManager();
this._cacheManager.registerCacheOwner(this);
Expand Down Expand Up @@ -257,6 +261,7 @@ export class Program {
setConfigOptions(configOptions: ConfigOptions) {
this._configOptions = configOptions;
this._importResolver.setConfigOptions(configOptions);
this.baselineHandler.configOptions = configOptions;

// Create a new evaluator with the updated config options.
this._createNewEvaluator();
Expand Down Expand Up @@ -351,6 +356,7 @@ export class Program {
importName,
isThirdPartyImport,
isInPyTypedPackage,
this.baselineHandler,
this._editModeTracker,
this._console,
this._logTracker
Expand Down Expand Up @@ -379,6 +385,7 @@ export class Program {
moduleImportInfo.moduleName,
/* isThirdPartyImport */ false,
moduleImportInfo.isThirdPartyPyTypedPresent,
this.baselineHandler,
this._editModeTracker,
this._console,
this._logTracker,
Expand Down Expand Up @@ -623,6 +630,7 @@ export class Program {
// to the smaller value to maintain responsiveness.
analyze(maxTime?: MaxAnalysisTime, token: CancellationToken = CancellationToken.None): boolean {
return this._runEvaluatorWithCancellationToken(token, () => {
this.baselineHandler.invalidateCache();
const elapsedTime = new Duration();

const openFiles = this._sourceFileList.filter(
Expand Down Expand Up @@ -1477,6 +1485,7 @@ export class Program {
moduleImportInfo.moduleName,
importInfo.isThirdPartyImport,
importInfo.isPyTypedPresent,
this.baselineHandler,
this._editModeTracker,
this._console,
this._logTracker
Expand Down Expand Up @@ -1619,6 +1628,7 @@ export class Program {
moduleImportInfo.moduleName,
/* isThirdPartyImport */ false,
/* isInPyTypedPackage */ false,
this.baselineHandler,
this._editModeTracker,
this._console,
this._logTracker
Expand Down
2 changes: 2 additions & 0 deletions packages/pyright-internal/src/analyzer/programTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*
* Various interfaces/types used in
*/
import { BaselineHandler } from '../baseline';
import { ConsoleInterface } from '../common/console';
import { LogTracker } from '../common/logTracker';
import { ServiceProvider } from '../common/serviceProvider';
Expand All @@ -18,6 +19,7 @@ export interface ISourceFileFactory {
moduleName: string,
isThirdPartyImport: boolean,
isThirdPartyPyTypedPresent: boolean,
baselineHandler: BaselineHandler,
editMode: SourceFileEditMode,
console?: ConsoleInterface,
logTracker?: LogTracker,
Expand Down
Loading
Loading