diff --git a/packages/pyright-internal/src/analyzer/program.ts b/packages/pyright-internal/src/analyzer/program.ts index b88414b24..40b1b8df9 100644 --- a/packages/pyright-internal/src/analyzer/program.ts +++ b/packages/pyright-internal/src/analyzer/program.ts @@ -262,12 +262,16 @@ export class Program { addTrackedFile(filePath: string, isThirdPartyImport = false, isInPyTypedPackage = false): SourceFile { let sourceFileInfo = this._getSourceFileInfoFromPath(filePath); + const importName = this._getImportNameForFile(filePath); + if (sourceFileInfo) { + // The module name may have changed based on updates to the + // search paths, so update it here. + sourceFileInfo.sourceFile.setModuleName(importName); sourceFileInfo.isTracked = true; return sourceFileInfo.sourceFile; } - const importName = this._getImportNameForFile(filePath); const sourceFile = new SourceFile( this._fs, filePath, diff --git a/packages/pyright-internal/src/analyzer/sourceFile.ts b/packages/pyright-internal/src/analyzer/sourceFile.ts index e449f9b33..211ba9971 100644 --- a/packages/pyright-internal/src/analyzer/sourceFile.ts +++ b/packages/pyright-internal/src/analyzer/sourceFile.ts @@ -97,7 +97,7 @@ export class SourceFile { private readonly _filePath: string; // Period-delimited import path for the module. - private readonly _moduleName: string; + private _moduleName: string; // True if file is a type-hint (.pyi) file versus a python // (.py) file. @@ -247,6 +247,14 @@ export class SourceFile { return this._filePath; } + getModuleName(): string { + return this._moduleName; + } + + setModuleName(name: string) { + this._moduleName = name; + } + getDiagnosticVersion(): number { return this._diagnosticVersion; }