Skip to content

Commit b249d11

Browse files
bschnurrheejaechangdebonterchiodoStellaHuang95
authored
pull-pylance-with-pyright-1.1.401-20250521-185403 (#10486)
Co-authored-by: Bill Schnurr <bschnurr@microsoft.com> Co-authored-by: HeeJae Chang <hechang@microsoft.com> Co-authored-by: Erik De Bonte <erikd@microsoft.com> Co-authored-by: Rich Chiodo <rchiodo@microsoft.com> Co-authored-by: Stella Huang <stellahuang@microsoft.com>
1 parent ae64f08 commit b249d11

21 files changed

Lines changed: 155 additions & 120 deletions

packages/pyright-internal/src/analyzer/program.ts

Lines changed: 52 additions & 59 deletions
Large diffs are not rendered by default.

packages/pyright-internal/src/analyzer/service.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,11 @@ export class AnalyzerService {
241241
const version = fileInfo.sourceFile.getClientVersion();
242242
if (version !== undefined) {
243243
service.setFileOpened(
244-
fileInfo.sourceFile.getUri(),
244+
fileInfo.uri,
245245
version,
246246
fileInfo.sourceFile.getOpenFileContents()!,
247-
fileInfo.sourceFile.getIPythonMode(),
248-
fileInfo.chainedSourceFile?.sourceFile.getUri()
247+
fileInfo.ipythonMode,
248+
fileInfo.chainedSourceFile?.uri
249249
);
250250
}
251251
}
@@ -311,15 +311,15 @@ export class AnalyzerService {
311311
}
312312

313313
getUserFiles() {
314-
return this._program.getUserFiles().map((i) => i.sourceFile.getUri());
314+
return this._program.getUserFiles().map((i) => i.uri);
315315
}
316316

317317
getOpenFiles() {
318-
return this._program.getOpened().map((i) => i.sourceFile.getUri());
318+
return this._program.getOpened().map((i) => i.uri);
319319
}
320320

321321
getOwnedFiles() {
322-
return this._program.getOwnedFiles().map((i) => i.sourceFile.getUri());
322+
return this._program.getOwnedFiles().map((i) => i.uri);
323323
}
324324

325325
setFileOpened(
@@ -1277,7 +1277,7 @@ export class AnalyzerService {
12771277
// files in file system but only exist in memory (ex, virtual workspace)
12781278
this._backgroundAnalysisProgram.program
12791279
.getOpened()
1280-
.map((o) => o.sourceFile.getUri())
1280+
.map((o) => o.uri)
12811281
.filter((f) => matchFileSpecs(this._program.configOptions, f))
12821282
.forEach((f) => fileMap.set(f.key, f));
12831283

packages/pyright-internal/src/analyzer/sourceFileInfo.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
*/
88

99
import { SourceFile } from './sourceFile';
10+
import * as extensibility from '../common/extensibility';
1011

1112
// Tracks information about each source file in a program,
1213
// including the reason it was added to the program and any
1314
// dependencies that it has on other files in the program.
14-
export class SourceFileInfo {
15+
export class SourceFileInfo implements extensibility.SourceFileInfo {
1516
private _writableData: WriteableData;
1617
private _preEditData?: WriteableData;
1718

@@ -62,6 +63,33 @@ export class SourceFileInfo {
6263
get isOpenByClient() {
6364
return this._writableData.isOpenByClient;
6465
}
66+
get uri() {
67+
return this.sourceFile.getUri();
68+
}
69+
70+
get contents() {
71+
return this.sourceFile.getFileContent() ?? '';
72+
}
73+
74+
get ipythonMode() {
75+
return this.sourceFile.getIPythonMode();
76+
}
77+
78+
get isStubFile() {
79+
return this.sourceFile.isStubFile();
80+
}
81+
82+
get isTypingStubFile() {
83+
return this.sourceFile.isTypingStubFile();
84+
}
85+
86+
get hasTypeAnnotations() {
87+
const parseResults = this.sourceFile.getParserOutput();
88+
if (parseResults) {
89+
return parseResults.hasTypeAnnotations;
90+
}
91+
return false;
92+
}
6593

6694
get imports(): readonly SourceFileInfo[] {
6795
return this._writableData.imports;
@@ -79,6 +107,10 @@ export class SourceFileInfo {
79107
return this._writableData.shadowedBy;
80108
}
81109

110+
get clientVersion() {
111+
return this.sourceFile.getClientVersion();
112+
}
113+
82114
set diagnosticsVersion(value: number | undefined) {
83115
this._cachePreEditState();
84116
this._writableData.diagnosticsVersion = value;

packages/pyright-internal/src/analyzer/sourceFileInfoUtils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ export function verifyNoCyclesInChainedFiles<T extends SourceFileInfo>(program:
4646
return;
4747
}
4848

49-
const set = new Set<string>([fileInfo.sourceFile.getUri().key]);
49+
const set = new Set<string>([fileInfo.uri.key]);
5050
while (nextChainedFile) {
51-
const path = nextChainedFile.sourceFile.getUri().key;
51+
const path = nextChainedFile.uri.key;
5252
if (set.has(path)) {
5353
// We found a cycle.
5454
fail(
@@ -98,11 +98,11 @@ export function createChainedByList<T extends SourceFileInfo>(program: ProgramVi
9898

9999
function _parseAllOpenCells(program: ProgramView): void {
100100
for (const file of program.getSourceFileInfoList()) {
101-
if (file.sourceFile.getIPythonMode() !== IPythonMode.CellDocs) {
101+
if (file.ipythonMode !== IPythonMode.CellDocs) {
102102
continue;
103103
}
104104

105-
program.getParserOutput(file.sourceFile.getUri());
105+
program.getParserOutput(file.uri);
106106
program.handleMemoryHighUsage();
107107
}
108108
}

packages/pyright-internal/src/analyzer/sourceMapper.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ export class SourceMapper {
738738
}
739739

740740
private _getBoundSourceFilesFromStubFile(stubFileUri: Uri, stubToShadow?: Uri, originated?: Uri): SourceFile[] {
741-
const paths = this._getSourcePathsFromStub(stubFileUri, originated ?? this._fromFile?.sourceFile.getUri());
741+
const paths = this._getSourcePathsFromStub(stubFileUri, originated ?? this._fromFile?.uri);
742742
return paths.map((fp) => this._fileBinder(stubToShadow ?? stubFileUri, fp)).filter(isDefined);
743743
}
744744

@@ -779,7 +779,7 @@ export class SourceMapper {
779779
stubFileUri,
780780
(p) => {
781781
const boundSourceInfo = this._boundSourceGetter(p);
782-
return boundSourceInfo ? boundSourceInfo.importedBy.map((info) => info.sourceFile.getUri()) : [];
782+
return boundSourceInfo ? boundSourceInfo.importedBy.map((info) => info.uri) : [];
783783
},
784784
this._cancelToken
785785
).filter((p) => this._isStubThatShouldBeMappedToImplementation(p));

packages/pyright-internal/src/common/extensibility.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,18 @@ export interface SourceFileInfo {
4848
// one can mess up program state by calling some methods on it directly.
4949
// For example, calling sourceFile.parse() directly will mess up
5050
// dependency graph maintained by the program.
51-
readonly sourceFile: SourceFile;
51+
readonly uri: Uri;
52+
readonly contents: string;
53+
readonly ipythonMode: IPythonMode;
5254

5355
// Information about the source file
5456
readonly isTypeshedFile: boolean;
5557
readonly isThirdPartyImport: boolean;
5658
readonly isThirdPartyPyTypedPresent: boolean;
59+
readonly isTypingStubFile: boolean;
60+
readonly hasTypeAnnotations: boolean;
61+
readonly diagnosticsVersion: number | undefined;
62+
readonly clientVersion: number | undefined;
5763

5864
readonly chainedSourceFile?: SourceFileInfo | undefined;
5965

@@ -82,6 +88,7 @@ export interface ProgramView {
8288
getParserOutput(fileUri: Uri): ParserOutput | undefined;
8389
getParseResults(fileUri: Uri): ParseFileResults | undefined;
8490
getSourceFileInfo(fileUri: Uri): SourceFileInfo | undefined;
91+
getModuleSymbolTable(fileUri: Uri): SymbolTable | undefined;
8592
getChainedUri(fileUri: Uri): Uri | undefined;
8693
getSourceMapper(fileUri: Uri, token: CancellationToken, mapCompiled?: boolean, preferStubs?: boolean): SourceMapper;
8794

packages/pyright-internal/src/common/workspaceEditUtils.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,23 +140,23 @@ export function applyWorkspaceEdit(program: EditableProgram, edits: WorkspaceEdi
140140

141141
export function applyDocumentChanges(program: EditableProgram, fileInfo: SourceFileInfo, edits: TextEdit[]) {
142142
if (!fileInfo.isOpenByClient) {
143-
const fileContent = fileInfo.sourceFile.getFileContent();
144-
program.setFileOpened(fileInfo.sourceFile.getUri(), 0, fileContent ?? '', {
143+
const fileContent = fileInfo.contents;
144+
program.setFileOpened(fileInfo.uri, 0, fileContent ?? '', {
145145
isTracked: fileInfo.isTracked,
146-
ipythonMode: fileInfo.sourceFile.getIPythonMode(),
147-
chainedFileUri: fileInfo.chainedSourceFile?.sourceFile.getUri(),
146+
ipythonMode: fileInfo.ipythonMode,
147+
chainedFileUri: fileInfo.chainedSourceFile?.uri,
148148
});
149149
}
150150

151-
const version = fileInfo.sourceFile.getClientVersion() ?? 0;
152-
const fileUri = fileInfo.sourceFile.getUri();
151+
const version = fileInfo.clientVersion ?? 0;
152+
const fileUri = fileInfo.uri;
153153
const filePath = fileUri.getFilePath();
154-
const sourceDoc = TextDocument.create(filePath, 'python', version, fileInfo.sourceFile.getOpenFileContents() ?? '');
154+
const sourceDoc = TextDocument.create(filePath, 'python', version, fileInfo.contents ?? '');
155155

156156
program.setFileOpened(fileUri, version + 1, TextDocument.applyEdits(sourceDoc, edits), {
157157
isTracked: fileInfo.isTracked,
158-
ipythonMode: fileInfo.sourceFile.getIPythonMode(),
159-
chainedFileUri: fileInfo.chainedSourceFile?.sourceFile.getUri(),
158+
ipythonMode: fileInfo.ipythonMode,
159+
chainedFileUri: fileInfo.chainedSourceFile?.uri,
160160
});
161161
}
162162

packages/pyright-internal/src/languageService/analyzerServiceExecutor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export class AnalyzerServiceExecutor {
8787
}
8888
}
8989

90-
function getEffectiveCommandLineOptions(
90+
export function getEffectiveCommandLineOptions(
9191
workspaceRootUri: Uri | undefined,
9292
serverSettings: ServerSettings,
9393
trackFiles: boolean,

packages/pyright-internal/src/languageService/autoImporter.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export type AutoImportResultMap = Map<string, AutoImportResult[]>;
116116

117117
// Build a map of all modules within this program and the module-
118118
// level scope that contains the symbol table for the module.
119-
export function buildModuleSymbolsMap(files: readonly SourceFileInfo[]): ModuleSymbolMap {
119+
export function buildModuleSymbolsMap(program: ProgramView, files: readonly SourceFileInfo[]): ModuleSymbolMap {
120120
const moduleSymbolMap = new Map<string, ModuleSymbolTable>();
121121

122122
files.forEach((file) => {
@@ -126,8 +126,8 @@ export function buildModuleSymbolsMap(files: readonly SourceFileInfo[]): ModuleS
126126
return;
127127
}
128128

129-
const uri = file.sourceFile.getUri();
130-
const symbolTable = file.sourceFile.getModuleSymbolTable();
129+
const uri = file.uri;
130+
const symbolTable = program.getModuleSymbolTable(uri);
131131
if (!symbolTable) {
132132
return;
133133
}

packages/pyright-internal/src/languageService/callHierarchyProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export class CallHierarchyProvider {
120120
: this._program.getSourceFileInfoList();
121121
for (const curSourceFileInfo of sourceFiles) {
122122
if (isUserCode(curSourceFileInfo) || curSourceFileInfo.isOpenByClient) {
123-
const filePath = curSourceFileInfo.sourceFile.getUri();
123+
const filePath = curSourceFileInfo.uri;
124124
const itemsToAdd = this._getIncomingCallsForDeclaration(filePath, symbolName, targetDecl);
125125

126126
if (itemsToAdd) {

0 commit comments

Comments
 (0)