@zzzen/pyright-internal 1.2.0-dev.20230430 → 1.2.0-dev.20230507

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (160) hide show
  1. package/dist/analyzer/backgroundAnalysisProgram.d.ts +3 -0
  2. package/dist/analyzer/backgroundAnalysisProgram.js +12 -0
  3. package/dist/analyzer/backgroundAnalysisProgram.js.map +1 -1
  4. package/dist/analyzer/checker.d.ts +1 -0
  5. package/dist/analyzer/checker.js +52 -4
  6. package/dist/analyzer/checker.js.map +1 -1
  7. package/dist/analyzer/constructors.d.ts +6 -0
  8. package/dist/analyzer/constructors.js +456 -0
  9. package/dist/analyzer/constructors.js.map +1 -0
  10. package/dist/analyzer/dataClasses.js +84 -0
  11. package/dist/analyzer/dataClasses.js.map +1 -1
  12. package/dist/analyzer/enums.js +54 -8
  13. package/dist/analyzer/enums.js.map +1 -1
  14. package/dist/analyzer/importStatementUtils.d.ts +2 -2
  15. package/dist/analyzer/importStatementUtils.js.map +1 -1
  16. package/dist/analyzer/namedTuples.js +1 -1
  17. package/dist/analyzer/namedTuples.js.map +1 -1
  18. package/dist/analyzer/operations.d.ts +16 -0
  19. package/dist/analyzer/operations.js +749 -0
  20. package/dist/analyzer/operations.js.map +1 -0
  21. package/dist/analyzer/parseTreeUtils.d.ts +4 -2
  22. package/dist/analyzer/parseTreeUtils.js +32 -1
  23. package/dist/analyzer/parseTreeUtils.js.map +1 -1
  24. package/dist/analyzer/patternMatching.js +16 -0
  25. package/dist/analyzer/patternMatching.js.map +1 -1
  26. package/dist/analyzer/program.d.ts +5 -17
  27. package/dist/analyzer/program.js +46 -493
  28. package/dist/analyzer/program.js.map +1 -1
  29. package/dist/analyzer/service.d.ts +3 -11
  30. package/dist/analyzer/service.js +16 -12
  31. package/dist/analyzer/service.js.map +1 -1
  32. package/dist/analyzer/sourceFile.d.ts +10 -33
  33. package/dist/analyzer/sourceFile.js +225 -181
  34. package/dist/analyzer/sourceFile.js.map +1 -1
  35. package/dist/analyzer/sourceFileInfoUtils.d.ts +3 -9
  36. package/dist/analyzer/sourceFileInfoUtils.js.map +1 -1
  37. package/dist/analyzer/typeEvaluator.js +100 -1285
  38. package/dist/analyzer/typeEvaluator.js.map +1 -1
  39. package/dist/analyzer/typeEvaluatorTypes.d.ts +38 -7
  40. package/dist/analyzer/typeEvaluatorTypes.js +33 -1
  41. package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
  42. package/dist/analyzer/typeGuards.js +2 -8
  43. package/dist/analyzer/typeGuards.js.map +1 -1
  44. package/dist/analyzer/typeUtils.d.ts +2 -0
  45. package/dist/analyzer/typeUtils.js +33 -3
  46. package/dist/analyzer/typeUtils.js.map +1 -1
  47. package/dist/analyzer/typeVarContext.d.ts +5 -5
  48. package/dist/analyzer/typeVarContext.js +7 -0
  49. package/dist/analyzer/typeVarContext.js.map +1 -1
  50. package/dist/analyzer/typedDicts.js +2 -2
  51. package/dist/analyzer/typedDicts.js.map +1 -1
  52. package/dist/analyzer/types.d.ts +4 -2
  53. package/dist/analyzer/types.js +7 -0
  54. package/dist/analyzer/types.js.map +1 -1
  55. package/dist/common/extensibility.d.ts +2 -1
  56. package/dist/common/extensibility.js.map +1 -1
  57. package/dist/common/pathUtils.d.ts +11 -11
  58. package/dist/common/pathUtils.js.map +1 -1
  59. package/dist/common/workspaceEditUtils.d.ts +5 -5
  60. package/dist/common/workspaceEditUtils.js.map +1 -1
  61. package/dist/languageServerBase.d.ts +1 -2
  62. package/dist/languageServerBase.js +8 -13
  63. package/dist/languageServerBase.js.map +1 -1
  64. package/dist/languageService/callHierarchyProvider.d.ts +1 -1
  65. package/dist/languageService/callHierarchyProvider.js +5 -5
  66. package/dist/languageService/callHierarchyProvider.js.map +1 -1
  67. package/dist/languageService/completionProvider.d.ts +10 -13
  68. package/dist/languageService/completionProvider.js +21 -10
  69. package/dist/languageService/completionProvider.js.map +1 -1
  70. package/dist/languageService/documentHighlightProvider.js +1 -1
  71. package/dist/languageService/documentHighlightProvider.js.map +1 -1
  72. package/dist/languageService/documentSymbolCollector.d.ts +6 -7
  73. package/dist/languageService/documentSymbolCollector.js +17 -8
  74. package/dist/languageService/documentSymbolCollector.js.map +1 -1
  75. package/dist/languageService/hoverProvider.d.ts +4 -3
  76. package/dist/languageService/hoverProvider.js +29 -35
  77. package/dist/languageService/hoverProvider.js.map +1 -1
  78. package/dist/languageService/referencesProvider.d.ts +7 -12
  79. package/dist/languageService/referencesProvider.js +25 -17
  80. package/dist/languageService/referencesProvider.js.map +1 -1
  81. package/dist/languageService/renameProvider.d.ts +17 -0
  82. package/dist/languageService/renameProvider.js +143 -0
  83. package/dist/languageService/renameProvider.js.map +1 -0
  84. package/dist/localization/localize.d.ts +17 -14
  85. package/dist/localization/localize.js +4 -6
  86. package/dist/localization/localize.js.map +1 -1
  87. package/dist/localization/package.nls.en-us.json +5 -6
  88. package/dist/tests/documentSymbolCollector.test.js +3 -3
  89. package/dist/tests/documentSymbolCollector.test.js.map +1 -1
  90. package/dist/tests/fourslash/fourslash.d.ts +4 -4
  91. package/dist/tests/fourslash/missingTypeStub.codeAction.fourslash.js +1 -1
  92. package/dist/tests/fourslash/missingTypeStub.codeAction.fourslash.js.map +1 -1
  93. package/dist/tests/harness/fourslash/testState.d.ts +3 -3
  94. package/dist/tests/harness/fourslash/testState.js +14 -14
  95. package/dist/tests/harness/fourslash/testState.js.map +1 -1
  96. package/dist/tests/sourceFile.test.js +1 -1
  97. package/dist/tests/sourceFile.test.js.map +1 -1
  98. package/dist/tests/testStateUtils.d.ts +2 -2
  99. package/dist/tests/testStateUtils.js +38 -8
  100. package/dist/tests/testStateUtils.js.map +1 -1
  101. package/dist/tests/typeEvaluator2.test.js +1 -1
  102. package/dist/tests/typeEvaluator3.test.js +1 -1
  103. package/dist/tests/typeEvaluator4.test.js +9 -1
  104. package/dist/tests/typeEvaluator4.test.js.map +1 -1
  105. package/dist/tests/typeEvaluator5.test.js +4 -0
  106. package/dist/tests/typeEvaluator5.test.js.map +1 -1
  107. package/dist/tests/workspaceEditUtils.test.js +84 -0
  108. package/dist/tests/workspaceEditUtils.test.js.map +1 -1
  109. package/package.json +4 -4
  110. package/dist/languageService/indentationUtils.d.ts +0 -16
  111. package/dist/languageService/indentationUtils.js +0 -727
  112. package/dist/languageService/indentationUtils.js.map +0 -1
  113. package/dist/languageService/insertionPointUtils.d.ts +0 -9
  114. package/dist/languageService/insertionPointUtils.js +0 -132
  115. package/dist/languageService/insertionPointUtils.js.map +0 -1
  116. package/dist/languageService/renameModuleProvider.d.ts +0 -65
  117. package/dist/languageService/renameModuleProvider.js +0 -939
  118. package/dist/languageService/renameModuleProvider.js.map +0 -1
  119. package/dist/tests/indentationUtils.ptvs.test.d.ts +0 -1
  120. package/dist/tests/indentationUtils.ptvs.test.js +0 -324
  121. package/dist/tests/indentationUtils.ptvs.test.js.map +0 -1
  122. package/dist/tests/indentationUtils.reindent.test.d.ts +0 -1
  123. package/dist/tests/indentationUtils.reindent.test.js +0 -372
  124. package/dist/tests/indentationUtils.reindent.test.js.map +0 -1
  125. package/dist/tests/indentationUtils.test.d.ts +0 -1
  126. package/dist/tests/indentationUtils.test.js +0 -502
  127. package/dist/tests/indentationUtils.test.js.map +0 -1
  128. package/dist/tests/insertionPointUtils.test.d.ts +0 -1
  129. package/dist/tests/insertionPointUtils.test.js +0 -154
  130. package/dist/tests/insertionPointUtils.test.js.map +0 -1
  131. package/dist/tests/moveSymbol.importAdder.test.d.ts +0 -1
  132. package/dist/tests/moveSymbol.importAdder.test.js +0 -298
  133. package/dist/tests/moveSymbol.importAdder.test.js.map +0 -1
  134. package/dist/tests/moveSymbol.insertion.test.d.ts +0 -1
  135. package/dist/tests/moveSymbol.insertion.test.js +0 -537
  136. package/dist/tests/moveSymbol.insertion.test.js.map +0 -1
  137. package/dist/tests/moveSymbol.misc.test.d.ts +0 -1
  138. package/dist/tests/moveSymbol.misc.test.js +0 -169
  139. package/dist/tests/moveSymbol.misc.test.js.map +0 -1
  140. package/dist/tests/moveSymbol.updateReference.test.d.ts +0 -1
  141. package/dist/tests/moveSymbol.updateReference.test.js +0 -1071
  142. package/dist/tests/moveSymbol.updateReference.test.js.map +0 -1
  143. package/dist/tests/renameModule.folder.test.d.ts +0 -1
  144. package/dist/tests/renameModule.folder.test.js +0 -229
  145. package/dist/tests/renameModule.folder.test.js.map +0 -1
  146. package/dist/tests/renameModule.fromImports.test.d.ts +0 -1
  147. package/dist/tests/renameModule.fromImports.test.js +0 -790
  148. package/dist/tests/renameModule.fromImports.test.js.map +0 -1
  149. package/dist/tests/renameModule.imports.test.d.ts +0 -1
  150. package/dist/tests/renameModule.imports.test.js +0 -380
  151. package/dist/tests/renameModule.imports.test.js.map +0 -1
  152. package/dist/tests/renameModule.misc.test.d.ts +0 -1
  153. package/dist/tests/renameModule.misc.test.js +0 -615
  154. package/dist/tests/renameModule.misc.test.js.map +0 -1
  155. package/dist/tests/renameModule.relativePath.test.d.ts +0 -1
  156. package/dist/tests/renameModule.relativePath.test.js +0 -231
  157. package/dist/tests/renameModule.relativePath.test.js.map +0 -1
  158. package/dist/tests/renameModuleTestUtils.d.ts +0 -4
  159. package/dist/tests/renameModuleTestUtils.js +0 -76
  160. package/dist/tests/renameModuleTestUtils.js.map +0 -1
@@ -31,6 +31,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
31
31
  exports.Program = exports.MaxWorkspaceIndexFileCount = void 0;
32
32
  const vscode_languageserver_1 = require("vscode-languageserver");
33
33
  const vscode_languageserver_types_1 = require("vscode-languageserver-types");
34
+ const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
34
35
  const cancellationUtils_1 = require("../common/cancellationUtils");
35
36
  const collectionUtils_1 = require("../common/collectionUtils");
36
37
  const configOptions_1 = require("../common/configOptions");
@@ -42,23 +43,13 @@ const logTracker_1 = require("../common/logTracker");
42
43
  const pathUtils_1 = require("../common/pathUtils");
43
44
  const positionUtils_1 = require("../common/positionUtils");
44
45
  const stringUtils_1 = require("../common/stringUtils");
45
- const textEditTracker_1 = require("../common/textEditTracker");
46
46
  const textRange_1 = require("../common/textRange");
47
- const textRangeCollection_1 = require("../common/textRangeCollection");
48
47
  const timing_1 = require("../common/timing");
49
- const workspaceEditUtils_1 = require("../common/workspaceEditUtils");
50
48
  const autoImporter_1 = require("../languageService/autoImporter");
51
49
  const completionProvider_1 = require("../languageService/completionProvider");
52
- const documentSymbolCollector_1 = require("../languageService/documentSymbolCollector");
53
- const importAdder_1 = require("../languageService/importAdder");
54
- const indentationUtils_1 = require("../languageService/indentationUtils");
55
- const insertionPointUtils_1 = require("../languageService/insertionPointUtils");
56
- const referencesProvider_1 = require("../languageService/referencesProvider");
57
- const renameModuleProvider_1 = require("../languageService/renameModuleProvider");
58
50
  const AnalyzerNodeInfo = __importStar(require("./analyzerNodeInfo"));
59
51
  const cacheManager_1 = require("./cacheManager");
60
52
  const circularDependency_1 = require("./circularDependency");
61
- const declaration_1 = require("./declaration");
62
53
  const parseTreeUtils_1 = require("./parseTreeUtils");
63
54
  const scopeUtils_1 = require("./scopeUtils");
64
55
  const sourceFile_1 = require("./sourceFile");
@@ -82,6 +73,7 @@ class Program {
82
73
  this._sourceFileList = [];
83
74
  this._sourceFileMap = new Map();
84
75
  this._parsedFileCount = 0;
76
+ this._isEditMode = false;
85
77
  this._lookUpImport = (filePathOrModule, options) => {
86
78
  var _a;
87
79
  let sourceFileInfo;
@@ -171,6 +163,41 @@ class Program {
171
163
  dispose() {
172
164
  this._cacheManager.unregisterCacheOwner(this);
173
165
  }
166
+ enterEditMode() {
167
+ // Keep track of edit mode so we can apply it to new source files.
168
+ this._isEditMode = true;
169
+ // Tell all source files we're in edit mode.
170
+ this._sourceFileList.forEach((sourceFile) => {
171
+ sourceFile.sourceFile.enterEditMode();
172
+ });
173
+ }
174
+ exitEditMode() {
175
+ // Tell all source files we're no longer in edit mode. Gather
176
+ // up all of their edits.
177
+ const edits = [];
178
+ this._sourceFileList.forEach((sourceFile) => {
179
+ const newContents = sourceFile.sourceFile.exitEditMode();
180
+ if (newContents) {
181
+ // This means this source file was modified. We need to recompute its imports after
182
+ // we put it back to how it was.
183
+ this._updateSourceFileImports(sourceFile, this.configOptions);
184
+ // Create a text document so we can compute the edits.
185
+ const textDocument = vscode_languageserver_textdocument_1.TextDocument.create(sourceFile.sourceFile.getFilePath(), 'python', 1, sourceFile.sourceFile.getFileContent() || '');
186
+ // Add an edit action to the list.
187
+ edits.push({
188
+ filePath: sourceFile.sourceFile.getFilePath(),
189
+ range: {
190
+ start: { line: 0, character: 0 },
191
+ end: { line: textDocument.lineCount, character: 0 },
192
+ },
193
+ replacementText: newContents,
194
+ });
195
+ }
196
+ });
197
+ // Stop applying edit mode to new source files.
198
+ this._isEditMode = false;
199
+ return edits;
200
+ }
174
201
  setConfigOptions(configOptions) {
175
202
  this._configOptions = configOptions;
176
203
  this._importResolver.setConfigOptions(configOptions);
@@ -242,7 +269,7 @@ class Program {
242
269
  sourceFileInfo.isTracked = true;
243
270
  return sourceFileInfo.sourceFile;
244
271
  }
245
- const sourceFile = new sourceFile_1.SourceFile(this.fileSystem, filePath, importName, isThirdPartyImport, isInPyTypedPackage, this._console, this._logTracker);
272
+ const sourceFile = new sourceFile_1.SourceFile(this.fileSystem, filePath, importName, isThirdPartyImport, isInPyTypedPackage, this._isEditMode, this._console, this._logTracker);
246
273
  sourceFileInfo = {
247
274
  sourceFile,
248
275
  isTracked: true,
@@ -266,7 +293,7 @@ class Program {
266
293
  const importName = this._getImportNameForFile(filePath);
267
294
  const sourceFile = new sourceFile_1.SourceFile(this.fileSystem, filePath, importName,
268
295
  /* isThirdPartyImport */ false,
269
- /* isInPyTypedPackage */ false, this._console, this._logTracker, options === null || options === void 0 ? void 0 : options.realFilePath, (_a = options === null || options === void 0 ? void 0 : options.ipythonMode) !== null && _a !== void 0 ? _a : sourceFile_1.IPythonMode.None);
296
+ /* isInPyTypedPackage */ false, this._isEditMode, this._console, this._logTracker, options === null || options === void 0 ? void 0 : options.realFilePath, (_a = options === null || options === void 0 ? void 0 : options.ipythonMode) !== null && _a !== void 0 ? _a : sourceFile_1.IPythonMode.None);
270
297
  const chainedFilePath = options === null || options === void 0 ? void 0 : options.chainedFilePath;
271
298
  sourceFileInfo = {
272
299
  sourceFile,
@@ -862,14 +889,11 @@ class Program {
862
889
  if (!sourceFileInfo) {
863
890
  return undefined;
864
891
  }
865
- let sourceMapper;
866
892
  const completionResult = this._logTracker.log(`completion at ${filePath}:${position.line}:${position.character}`, (ls) => {
867
893
  var _a;
868
894
  const result = this._runEvaluatorWithCancellationToken(token, () => {
869
895
  this._bindFile(sourceFileInfo);
870
- const execEnv = this._configOptions.findExecEnvironment(filePath);
871
- sourceMapper = this._createSourceMapper(execEnv, token, sourceFileInfo, /* mapCompiled */ true);
872
- return sourceFileInfo.sourceFile.getCompletionsForPosition(position, workspacePath, this._configOptions, this._importResolver, this._lookUpImport, this._evaluator, options, sourceMapper, nameMap, libraryMap, () => this._buildModuleSymbolsMap(sourceFileInfo, libraryMap, options.includeUserSymbolsInAutoImport, token), token);
896
+ return sourceFileInfo.sourceFile.getCompletionsForPosition(this, position, workspacePath, this._lookUpImport, options, nameMap, libraryMap, () => this._buildModuleSymbolsMap(sourceFileInfo, libraryMap, options.includeUserSymbolsInAutoImport, token), token);
873
897
  });
874
898
  ls.add(`found ${(_a = result === null || result === void 0 ? void 0 : result.completionMap.size) !== null && _a !== void 0 ? _a : 'null'} items`);
875
899
  return result;
@@ -882,6 +906,9 @@ class Program {
882
906
  };
883
907
  const parseResults = sourceFileInfo.sourceFile.getParseResults();
884
908
  if ((parseResults === null || parseResults === void 0 ? void 0 : parseResults.parseTree) && (parseResults === null || parseResults === void 0 ? void 0 : parseResults.text)) {
909
+ const execEnv = this._configOptions.findExecEnvironment(filePath);
910
+ const sourceMapper = this._createSourceMapper(execEnv, token, sourceFileInfo,
911
+ /* mapCompiled */ true);
885
912
  const offset = (0, positionUtils_1.convertPositionToOffset)(position, parseResults.tokenizerOutput.lines);
886
913
  if (offset !== undefined && sourceMapper) {
887
914
  await Promise.all(extensibility_1.Extensions.getProgramExtensions(parseResults.parseTree).map((e) => {
@@ -899,284 +926,8 @@ class Program {
899
926
  return;
900
927
  }
901
928
  this._bindFile(sourceFileInfo);
902
- const execEnv = this._configOptions.findExecEnvironment(filePath);
903
- sourceFileInfo.sourceFile.resolveCompletionItem(this._configOptions, this._importResolver, this._lookUpImport, this._evaluator, options, this._createSourceMapper(execEnv, token, sourceFileInfo, /* mapCompiled */ true), nameMap, libraryMap, () => this._buildModuleSymbolsMap(sourceFileInfo, libraryMap, options.includeUserSymbolsInAutoImport, token), completionItem, token);
904
- });
905
- }
906
- renameModule(path, newPath, token) {
907
- return this._runEvaluatorWithCancellationToken(token, () => {
908
- if ((0, pathUtils_1.isFile)(this.fileSystem, path)) {
909
- const fileInfo = this.getSourceFileInfo(path);
910
- if (!fileInfo) {
911
- return undefined;
912
- }
913
- }
914
- const renameModuleProvider = renameModuleProvider_1.RenameModuleProvider.createForModule(this._importResolver, this._configOptions, this._evaluator, path, newPath, token);
915
- if (!renameModuleProvider) {
916
- return undefined;
917
- }
918
- this._processModuleReferences(renameModuleProvider, renameModuleProvider.lastModuleName, path);
919
- return { edits: renameModuleProvider.getEdits(), fileOperations: [] };
920
- });
921
- }
922
- moveSymbolAtPosition(filePath, newFilePath, position, options, token) {
923
- return this._runEvaluatorWithCancellationToken(token, () => {
924
- var _a, _b;
925
- const sourceFileExt = (0, pathUtils_1.getFileExtension)(filePath);
926
- const destFileExt = (0, pathUtils_1.getFileExtension)(newFilePath);
927
- if (sourceFileExt.toLowerCase() !== destFileExt.toLowerCase()) {
928
- // Don't allow moving a symbol from py to pyi or vice versa.
929
- return undefined;
930
- }
931
- const fileInfo = this.getSourceFileInfo(filePath);
932
- if (!fileInfo) {
933
- return undefined;
934
- }
935
- const newFileInfo = this.getBoundSourceFileInfo(newFilePath);
936
- if (fileInfo === newFileInfo) {
937
- // Can't move symbol to the same file.
938
- return undefined;
939
- }
940
- this._bindFile(fileInfo);
941
- const parseResults = fileInfo.sourceFile.getParseResults();
942
- if (!parseResults) {
943
- return undefined;
944
- }
945
- const offset = (0, positionUtils_1.convertPositionToOffset)(position, parseResults.tokenizerOutput.lines);
946
- if (offset === undefined) {
947
- return undefined;
948
- }
949
- const node = (0, parseTreeUtils_1.findNodeByOffset)(parseResults.parseTree, offset);
950
- if (node === undefined) {
951
- return undefined;
952
- }
953
- // If this isn't a name node, there are no references to be found.
954
- if (node.nodeType !== 38 /* Name */ ||
955
- !renameModuleProvider_1.RenameModuleProvider.canMoveSymbol(this._configOptions, this._evaluator, node)) {
956
- return undefined;
957
- }
958
- // We will try to
959
- // 1. Find symbol to move.
960
- // 2. Update all references to the symbol to new location.
961
- // 3. Remove the existing symbol.
962
- // 4. Insert the symbol to the destination module.
963
- // 5. Insert imports required for the symbol moved to the destination module.
964
- // 6. Remove import no longer needed from the original module.
965
- //
966
- // Here all changes are done to edits, no features in LS will apply changes to
967
- // program directly. All modification is done through LSP by a edit request so
968
- // things like undo or edit stacks UI works.
969
- // 1. Find symbol to move.
970
- const execEnv = this._configOptions.findExecEnvironment(filePath);
971
- const declarations = documentSymbolCollector_1.DocumentSymbolCollector.getDeclarationsForNode(node, this._evaluator,
972
- /* resolveLocalNames */ false, documentSymbolCollector_1.DocumentSymbolCollectorUseCase.Rename, token, this._createSourceMapper(execEnv, token, fileInfo));
973
- const renameModuleProvider = renameModuleProvider_1.RenameModuleProvider.createForSymbol(this._importResolver, this._configOptions, this._evaluator, filePath, newFilePath, declarations, token);
974
- if (!renameModuleProvider) {
975
- return undefined;
976
- }
977
- // 2. Update affected references.
978
- this._processModuleReferences(renameModuleProvider, node.value, filePath);
979
- // 3. Remove existing symbols.
980
- const sourceDecl = renameModuleProvider.declarations.find((d) => d.node && (0, pathUtils_1.getFileExtension)(d.path) === sourceFileExt);
981
- if (!sourceDecl) {
982
- // Can't find symbol we can move.
983
- return undefined;
984
- }
985
- const symbolRange = renameModuleProvider_1.RenameModuleProvider.getSymbolTextRange(parseResults, sourceDecl);
986
- const importAdder = new importAdder_1.ImportAdder(this._configOptions, this._importResolver, this._evaluator);
987
- const collectedImports = importAdder.collectImportsForSymbolsUsed(parseResults, symbolRange, token);
988
- let insertionPoint = 0;
989
- let insertionIndentation = 0;
990
- const newFileParseResults = newFileInfo === null || newFileInfo === void 0 ? void 0 : newFileInfo.sourceFile.getParseResults();
991
- if (newFileParseResults) {
992
- const insertBefore = renameModuleProvider.tryGetFirstSymbolUsage(newFileParseResults);
993
- insertionPoint = (0, insertionPointUtils_1.getInsertionPointForSymbolUnderModule)(this._evaluator, newFileParseResults, node.value, {
994
- symbolDeclToIgnore: sourceDecl.path,
995
- insertBefore,
996
- });
997
- if (insertionPoint === undefined) {
998
- // No place to insert the symbol.
999
- return undefined;
1000
- }
1001
- insertionIndentation = (0, indentationUtils_1.getModuleStatementIndentation)(newFileParseResults);
1002
- }
1003
- const reindentResult = (0, indentationUtils_1.reindentSpan)(parseResults, symbolRange, insertionIndentation);
1004
- const fullRange = renameModuleProvider_1.RenameModuleProvider.getSymbolFullStatementTextRange(parseResults, sourceDecl);
1005
- renameModuleProvider.textEditTracker.addEdit(filePath, (0, positionUtils_1.convertTextRangeToRange)(textRange_1.TextRange.combine([reindentResult.originalSpan, fullRange]), parseResults.tokenizerOutput.lines), '');
1006
- // 4. Add the symbol to the destination file.
1007
- const fileOperations = [];
1008
- let codeSnippetToInsert = reindentResult.text;
1009
- if (newFileParseResults) {
1010
- const range = (0, positionUtils_1.convertTextRangeToRange)({ start: insertionPoint, length: 0 }, newFileParseResults.tokenizerOutput.lines);
1011
- // If we are adding at the end of line (ex, end of a file),
1012
- // add new lines.
1013
- const newLinesToAdd = _getNumberOfBlankLinesToInsert(newFileParseResults, sourceDecl, range.end);
1014
- codeSnippetToInsert = '\n'.repeat(newLinesToAdd) + codeSnippetToInsert;
1015
- renameModuleProvider.textEditTracker.addEdit(newFilePath, range, codeSnippetToInsert);
1016
- }
1017
- else {
1018
- fileOperations.push({ kind: 'create', filePath: newFilePath });
1019
- renameModuleProvider.textEditTracker.addEdit(newFilePath, (0, textRange_1.getEmptyRange)(), codeSnippetToInsert);
1020
- }
1021
- // 5. Insert imports required for the symbol moved to the destination module.
1022
- //
1023
- // Since step 5 and 6 can create nested edits, we clone the program and apply all changes to re-calculate
1024
- // edits we need to apply to the destination file. The same workflow as `fix all` but done in program level
1025
- // not service level.
1026
- const cloned = this.clone();
1027
- let edits = renameModuleProvider.getEdits();
1028
- const textAfterSymbolAdded = (0, workspaceEditUtils_1.applyTextEditsToString)(edits.filter((v) => v.filePath === newFilePath), (_a = newFileParseResults === null || newFileParseResults === void 0 ? void 0 : newFileParseResults.tokenizerOutput.lines) !== null && _a !== void 0 ? _a : new textRangeCollection_1.TextRangeCollection([]), (_b = newFileInfo === null || newFileInfo === void 0 ? void 0 : newFileInfo.sourceFile.getFileContent()) !== null && _b !== void 0 ? _b : '');
1029
- _updateFileContent(cloned, newFilePath, textAfterSymbolAdded);
1030
- const textAfterImportsAdded = _tryGetTextAfterImportsAdded(cloned, newFilePath, collectedImports, insertionPoint, token);
1031
- edits = _updateFileEditActions(edits, newFilePath, newFileParseResults, textAfterSymbolAdded, textAfterImportsAdded);
1032
- // 6. Remove imports no longer required from original module.
1033
- const textAfterSymbolRemoved = (0, workspaceEditUtils_1.applyTextEditsToString)(edits.filter((v) => v.filePath === filePath), parseResults.tokenizerOutput.lines, fileInfo.sourceFile.getFileContent());
1034
- _updateFileContent(cloned, filePath, textAfterSymbolRemoved);
1035
- const textAfterUnusedImportsRemoved = _tryGetTextAfterUnusedImportsRemoved(cloned, filePath, collectedImports, 0, token);
1036
- edits = _updateFileEditActions(edits, filePath, parseResults, textAfterSymbolRemoved, textAfterUnusedImportsRemoved);
1037
- cloned.dispose();
1038
- return {
1039
- edits,
1040
- fileOperations,
1041
- };
1042
- function _updateFileEditActions(edits, filePath, parseResults, oldText, newText) {
1043
- if (newText === undefined || oldText === newText) {
1044
- return edits;
1045
- }
1046
- // There were nested edits. Replace whole file.
1047
- edits = edits.filter((v) => v.filePath !== filePath);
1048
- edits.push({
1049
- filePath,
1050
- range: parseResults
1051
- ? (0, positionUtils_1.convertTextRangeToRange)(parseResults.parseTree, parseResults.tokenizerOutput.lines)
1052
- : (0, textRange_1.getEmptyRange)(),
1053
- replacementText: newText,
1054
- });
1055
- return edits;
1056
- }
1057
- function _tryGetTextAfterImportsAdded(cloned, filePath, importData, insertionPoint, token) {
1058
- const sourceFile = cloned.getBoundSourceFile(filePath);
1059
- const parseResults = sourceFile === null || sourceFile === void 0 ? void 0 : sourceFile.getParseResults();
1060
- if (!parseResults) {
1061
- return undefined;
1062
- }
1063
- const insertAddEdits = importAdder.applyImports(importData, filePath, parseResults, insertionPoint, options.importFormat, token);
1064
- return (0, workspaceEditUtils_1.applyTextEditsToString)(insertAddEdits, parseResults.tokenizerOutput.lines, sourceFile.getFileContent());
1065
- }
1066
- function _tryGetTextAfterUnusedImportsRemoved(cloned, filePath, importData, attempt, token) {
1067
- var _a;
1068
- (0, cancellationUtils_1.throwIfCancellationRequested)(token);
1069
- cloned.analyzeFile(filePath, token);
1070
- const sourceFile = cloned.getBoundSourceFile(filePath);
1071
- const parseResults = sourceFile === null || sourceFile === void 0 ? void 0 : sourceFile.getParseResults();
1072
- if (!parseResults) {
1073
- return undefined;
1074
- }
1075
- const tracker = new textEditTracker_1.TextEditTracker();
1076
- for (const diagnostic of cloned
1077
- .getDiagnosticsForRange(filePath, (0, positionUtils_1.convertTextRangeToRange)(parseResults.parseTree, parseResults.tokenizerOutput.lines))
1078
- .filter((d) => {
1079
- var _a;
1080
- return d.category === 3 /* UnusedCode */ &&
1081
- ((_a = d.getActions()) === null || _a === void 0 ? void 0 : _a.some((a) => a.action === "pyright.unusedImport" /* unusedImport */));
1082
- })) {
1083
- const nameNode = (0, parseTreeUtils_1.findNodeByPosition)(parseResults.parseTree, diagnostic.range.start, parseResults.tokenizerOutput.lines);
1084
- if ((nameNode === null || nameNode === void 0 ? void 0 : nameNode.nodeType) !== 38 /* Name */) {
1085
- continue;
1086
- }
1087
- // decl is synthesized. there is no node associated with the decl.
1088
- // ex) import a or import a.b
1089
- const dottedName1 = ((_a = nameNode.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 37 /* ModuleName */ ? nameNode.parent.nameParts : [nameNode];
1090
- for (const [decl, names] of importData.declarations) {
1091
- if (decl.node) {
1092
- if (textRange_1.TextRange.containsRange(decl.node, nameNode)) {
1093
- tracker.removeNodes({ node: nameNode, parseResults: parseResults });
1094
- break;
1095
- }
1096
- }
1097
- const dottedName2 = (0, parseTreeUtils_1.getDottedName)((0, parseTreeUtils_1.getDottedNameWithGivenNodeAsLastName)(names[0]));
1098
- if (dottedName2 && (0, collectionUtils_1.arrayEquals)(dottedName1, dottedName2, (e1, e2) => e1.value === e2.value)) {
1099
- tracker.removeNodes({ node: nameNode, parseResults: parseResults });
1100
- break;
1101
- }
1102
- }
1103
- }
1104
- const oldText = sourceFile.getFileContent();
1105
- const newText = (0, workspaceEditUtils_1.applyTextEditsToString)(tracker.getEdits(token).filter((v) => v.filePath === filePath), parseResults.tokenizerOutput.lines, oldText);
1106
- // We will attempt to remove unused imports multiple times since removing 1 unused import
1107
- // could make another import unused. This is due to how we calculate which import is not used.
1108
- // ex) import os, os.path, os.path.xxx
1109
- // `os.path` and `os.path.xxx` will be marked as used due to `import os`.
1110
- // once `os` is removed `os.path` will be marked as unused and so on.
1111
- // We will attempt to remove those chained unused imports up to 10 chain.
1112
- if (attempt > 10 || oldText === newText) {
1113
- return newText;
1114
- }
1115
- _updateFileContent(cloned, filePath, newText);
1116
- return _tryGetTextAfterUnusedImportsRemoved(cloned, filePath, importData, attempt + 1, token);
1117
- }
929
+ sourceFileInfo.sourceFile.resolveCompletionItem(this, this._lookUpImport, options, nameMap, libraryMap, () => this._buildModuleSymbolsMap(sourceFileInfo, libraryMap, options.includeUserSymbolsInAutoImport, token), completionItem, token);
1118
930
  });
1119
- function _updateFileContent(cloned, filePath, text) {
1120
- var _a, _b;
1121
- const info = cloned.getSourceFileInfo(filePath);
1122
- const version = info ? ((_a = info.sourceFile.getClientVersion()) !== null && _a !== void 0 ? _a : 0) + 1 : 0;
1123
- const chainedFilePath = info ? (_b = info.chainedSourceFile) === null || _b === void 0 ? void 0 : _b.sourceFile.getFilePath() : undefined;
1124
- const ipythonMode = info ? info.sourceFile.getIPythonMode() : sourceFile_1.IPythonMode.None;
1125
- const isTracked = info ? info.isTracked : true;
1126
- const realFilePath = info ? info.sourceFile.getRealFilePath() : filePath;
1127
- cloned.setFileOpened(filePath, version, text, {
1128
- chainedFilePath,
1129
- ipythonMode,
1130
- isTracked,
1131
- realFilePath,
1132
- });
1133
- }
1134
- function _getNumberOfBlankLinesToInsert(parseResults, decl, position) {
1135
- if (position.line === 0 && position.character === 0) {
1136
- return 0;
1137
- }
1138
- let previousStatement;
1139
- const offset = (0, positionUtils_1.convertPositionToOffset)(position, parseResults.tokenizerOutput.lines);
1140
- if (offset && parseResults.parseTree.statements.length > 0) {
1141
- previousStatement = parseResults.parseTree.statements.reduce((prev, curr) => offset < curr.start ? prev : curr);
1142
- }
1143
- // This basically try to add some blank lines after the last line with text.
1144
- let linesToAdd = 0;
1145
- if (previousStatement) {
1146
- if ((0, declaration_1.isVariableDeclaration)(decl)) {
1147
- switch (previousStatement.nodeType) {
1148
- case 47 /* StatementList */:
1149
- // Small statement such as call, assignment, etc.
1150
- linesToAdd = 0;
1151
- break;
1152
- case 10 /* Class */:
1153
- case 28 /* Function */:
1154
- linesToAdd = 2;
1155
- break;
1156
- default:
1157
- // any other statement such as if, while, etc. we will add 1 blank line.
1158
- linesToAdd = 1;
1159
- }
1160
- }
1161
- else {
1162
- linesToAdd = 2;
1163
- }
1164
- }
1165
- // If the position is not at the beginning of the line, we need to add 1 more '\n'
1166
- // to start from blank line.
1167
- linesToAdd += position.character !== 0 ? 1 : 0;
1168
- // If there are already blank lines, we only add the difference.
1169
- const desiredBlankLines = linesToAdd;
1170
- const startingLine = position.character !== 0 ? position.line : position.line - 1;
1171
- for (let i = 0; i < desiredBlankLines; i++) {
1172
- const currentLine = startingLine - i;
1173
- if (currentLine < 0 || !(0, parseTreeUtils_1.isBlankLine)(parseResults, currentLine)) {
1174
- break;
1175
- }
1176
- linesToAdd--;
1177
- }
1178
- return linesToAdd;
1179
- }
1180
931
  }
1181
932
  clone() {
1182
933
  var _a, _b;
@@ -1200,123 +951,6 @@ class Program {
1200
951
  }
1201
952
  return program;
1202
953
  }
1203
- canRenameSymbolAtPosition(filePath, position, isDefaultWorkspace, allowModuleRename, token) {
1204
- return this._runEvaluatorWithCancellationToken(token, () => {
1205
- const sourceFileInfo = this.getSourceFileInfo(filePath);
1206
- if (!sourceFileInfo) {
1207
- return undefined;
1208
- }
1209
- this._bindFile(sourceFileInfo);
1210
- const referencesResult = this._getReferenceResult(sourceFileInfo, filePath, position, allowModuleRename, token);
1211
- if (!referencesResult) {
1212
- return undefined;
1213
- }
1214
- if (referencesResult.containsOnlyImportDecls &&
1215
- !this._supportRenameModule(referencesResult.declarations, isDefaultWorkspace)) {
1216
- return undefined;
1217
- }
1218
- const renameMode = this._getRenameSymbolMode(sourceFileInfo, referencesResult, isDefaultWorkspace);
1219
- if (renameMode === 'none') {
1220
- return undefined;
1221
- }
1222
- // Return the range of the symbol.
1223
- const parseResult = sourceFileInfo.sourceFile.getParseResults();
1224
- return {
1225
- range: (0, positionUtils_1.convertTextRangeToRange)(referencesResult.nodeAtOffset, parseResult.tokenizerOutput.lines),
1226
- declarations: referencesResult.declarations,
1227
- };
1228
- });
1229
- }
1230
- renameSymbolAtPosition(filePath, position, newName, isDefaultWorkspace, allowModuleRename, token) {
1231
- return this._runEvaluatorWithCancellationToken(token, () => {
1232
- var _a;
1233
- const sourceFileInfo = this.getSourceFileInfo(filePath);
1234
- if (!sourceFileInfo) {
1235
- return undefined;
1236
- }
1237
- this._bindFile(sourceFileInfo);
1238
- const referencesResult = this._getReferenceResult(sourceFileInfo, filePath, position, allowModuleRename, token);
1239
- if (!referencesResult) {
1240
- return undefined;
1241
- }
1242
- if (referencesResult.containsOnlyImportDecls) {
1243
- // All decls must be on a user file.
1244
- if (!this._supportRenameModule(referencesResult.declarations, isDefaultWorkspace)) {
1245
- return undefined;
1246
- }
1247
- const moduleInfo = renameModuleProvider_1.RenameModuleProvider.getRenameModulePathInfo(renameModuleProvider_1.RenameModuleProvider.getRenameModulePath(referencesResult.declarations), newName);
1248
- if (!moduleInfo) {
1249
- // Can't figure out module to rename.
1250
- return undefined;
1251
- }
1252
- const editActions = this.renameModule(moduleInfo.filePath, moduleInfo.newFilePath, token);
1253
- // Add file system rename.
1254
- editActions === null || editActions === void 0 ? void 0 : editActions.fileOperations.push({
1255
- kind: 'rename',
1256
- oldFilePath: moduleInfo.filePath,
1257
- newFilePath: moduleInfo.newFilePath,
1258
- });
1259
- if ((0, sourceMapper_1.isStubFile)(moduleInfo.filePath)) {
1260
- const matchingFiles = this._importResolver.getSourceFilesFromStub(moduleInfo.filePath, this._configOptions.findExecEnvironment(filePath),
1261
- /* mapCompiled */ false);
1262
- for (const matchingFile of matchingFiles) {
1263
- const matchingFileInfo = renameModuleProvider_1.RenameModuleProvider.getRenameModulePathInfo(matchingFile, newName);
1264
- if (matchingFileInfo) {
1265
- editActions === null || editActions === void 0 ? void 0 : editActions.fileOperations.push({
1266
- kind: 'rename',
1267
- oldFilePath: matchingFileInfo.filePath,
1268
- newFilePath: matchingFileInfo.newFilePath,
1269
- });
1270
- }
1271
- }
1272
- }
1273
- return editActions;
1274
- }
1275
- const referenceProvider = new referencesProvider_1.ReferencesProvider(this, token);
1276
- const renameMode = this._getRenameSymbolMode(sourceFileInfo, referencesResult, isDefaultWorkspace);
1277
- switch (renameMode) {
1278
- case 'singleFileMode':
1279
- referenceProvider.addReferencesToResult(sourceFileInfo.sourceFile.getFilePath(),
1280
- /* includeDeclaration */ true, referencesResult);
1281
- break;
1282
- case 'multiFileMode': {
1283
- for (const curSourceFileInfo of this._sourceFileList) {
1284
- // Make sure we only add user code to the references to prevent us
1285
- // from accidentally changing third party library or type stub.
1286
- if ((0, sourceFileInfoUtils_1.isUserCode)(curSourceFileInfo)) {
1287
- // Make sure searching symbol name exists in the file.
1288
- const content = (_a = curSourceFileInfo.sourceFile.getFileContent()) !== null && _a !== void 0 ? _a : '';
1289
- if (!referencesResult.symbolNames.some((s) => content.search(s) >= 0)) {
1290
- continue;
1291
- }
1292
- this._bindFile(curSourceFileInfo, content);
1293
- referenceProvider.addReferencesToResult(curSourceFileInfo.sourceFile.getFilePath(),
1294
- /* includeDeclaration */ true, referencesResult);
1295
- }
1296
- // This operation can consume significant memory, so check
1297
- // for situations where we need to discard the type cache.
1298
- this._handleMemoryHighUsage();
1299
- }
1300
- break;
1301
- }
1302
- case 'none':
1303
- // Rename is not allowed.
1304
- // ex) rename symbols from libraries.
1305
- return undefined;
1306
- default:
1307
- (0, debug_1.assertNever)(renameMode);
1308
- }
1309
- const edits = [];
1310
- referencesResult.locations.forEach((loc) => {
1311
- edits.push({
1312
- filePath: loc.path,
1313
- range: loc.range,
1314
- replacementText: newName,
1315
- });
1316
- });
1317
- return { edits, fileOperations: [] };
1318
- });
1319
- }
1320
954
  // Returns a value from 0 to 1 (or more) indicating how "full" the cache is
1321
955
  // relative to some predetermined high-water mark. We'll compute this value
1322
956
  // based on two easy-to-compute metrics: the number of entries in the type
@@ -1337,87 +971,6 @@ class Program {
1337
971
  test_createSourceMapper(execEnv, from) {
1338
972
  return this._createSourceMapper(execEnv, vscode_languageserver_1.CancellationToken.None, /* from */ from, /* mapCompiled */ false);
1339
973
  }
1340
- _getRenameSymbolMode(sourceFileInfo, referencesResult, isDefaultWorkspace) {
1341
- // We have 2 different cases
1342
- // Single file mode.
1343
- // 1. rename on default workspace (ex, standalone file mode).
1344
- // 2. rename local symbols.
1345
- // 3. rename symbols defined in the non user open file.
1346
- //
1347
- // and Multi file mode.
1348
- // 1. rename public symbols defined in user files on regular workspace (ex, open folder mode).
1349
- const userFile = (0, sourceFileInfoUtils_1.isUserCode)(sourceFileInfo);
1350
- if (isDefaultWorkspace ||
1351
- (userFile && !referencesResult.requiresGlobalSearch) ||
1352
- (!userFile &&
1353
- sourceFileInfo.isOpenByClient &&
1354
- referencesResult.declarations.every((d) => this.getSourceFileInfo(d.path) === sourceFileInfo))) {
1355
- return 'singleFileMode';
1356
- }
1357
- if (referencesResult.declarations.every((d) => (0, sourceFileInfoUtils_1.isUserCode)(this.getSourceFileInfo(d.path)))) {
1358
- return 'multiFileMode';
1359
- }
1360
- // Rename is not allowed.
1361
- // ex) rename symbols from libraries.
1362
- return 'none';
1363
- }
1364
- _supportRenameModule(declarations, isDefaultWorkspace) {
1365
- // Rename module is not supported for standalone file and all decls must be on a user file.
1366
- return !isDefaultWorkspace && declarations.every((d) => (0, sourceFileInfoUtils_1.isUserCode)(this.getSourceFileInfo(d.path)));
1367
- }
1368
- _getReferenceResult(sourceFileInfo, filePath, position, allowModuleRename, token) {
1369
- const execEnv = this._configOptions.findExecEnvironment(filePath);
1370
- const referencesResult = this._getDeclarationForPosition(sourceFileInfo, position, documentSymbolCollector_1.DocumentSymbolCollectorUseCase.Rename, this._createSourceMapper(execEnv, token), token);
1371
- if (!referencesResult) {
1372
- return undefined;
1373
- }
1374
- if (allowModuleRename && referencesResult.containsOnlyImportDecls) {
1375
- return referencesResult;
1376
- }
1377
- if (referencesResult.nonImportDeclarations.length === 0) {
1378
- // There is no symbol we can rename.
1379
- return undefined;
1380
- }
1381
- // Use declarations that doesn't contain import decls.
1382
- return new referencesProvider_1.ReferencesResult(referencesResult.requiresGlobalSearch, referencesResult.nodeAtOffset, referencesResult.symbolNames, referencesResult.nonImportDeclarations, referencesResult.useCase);
1383
- }
1384
- _getDeclarationForPosition(sourceFileInfo, position, useCase, sourceMapper, token, reporter) {
1385
- // If we have no completed analysis job, there's nothing to do.
1386
- const parseResults = sourceFileInfo.sourceFile.getParseResults();
1387
- if (!parseResults) {
1388
- return undefined;
1389
- }
1390
- return referencesProvider_1.ReferencesProvider.getDeclarationForPosition(sourceMapper, parseResults, sourceFileInfo.sourceFile.getFilePath(), position, this._evaluator, reporter, useCase, token, Array.from((0, sourceFileInfoUtils_1.collectImportedByFiles)(sourceFileInfo)).map((fileInfo) => fileInfo.sourceFile));
1391
- }
1392
- _processModuleReferences(renameModuleProvider, filteringText, currentFilePath) {
1393
- var _a;
1394
- // _sourceFileList contains every user files that match "include" pattern including
1395
- // py file even if corresponding pyi exists.
1396
- for (const currentFileInfo of this._sourceFileList) {
1397
- // Make sure we only touch user code to prevent us
1398
- // from accidentally changing third party library or type stub.
1399
- if (!(0, sourceFileInfoUtils_1.isUserCode)(currentFileInfo)) {
1400
- continue;
1401
- }
1402
- // If module name isn't mentioned in the current file, skip the file
1403
- // except the file that got actually renamed/moved.
1404
- // The file that got moved might have relative import paths we need to update.
1405
- const filePath = currentFileInfo.sourceFile.getFilePath();
1406
- const content = (_a = currentFileInfo.sourceFile.getFileContent()) !== null && _a !== void 0 ? _a : '';
1407
- if (filePath !== currentFilePath && content.indexOf(filteringText) < 0) {
1408
- continue;
1409
- }
1410
- this._bindFile(currentFileInfo, content);
1411
- const parseResult = currentFileInfo.sourceFile.getParseResults();
1412
- if (!parseResult) {
1413
- continue;
1414
- }
1415
- renameModuleProvider.renameReferences(parseResult);
1416
- // This operation can consume significant memory, so check
1417
- // for situations where we need to discard the type cache.
1418
- this._handleMemoryHighUsage();
1419
- }
1420
- }
1421
974
  _handleMemoryHighUsage() {
1422
975
  const cacheUsage = this._cacheManager.getCacheUsage();
1423
976
  // If the total cache has exceeded 75%, determine whether we should empty
@@ -1769,7 +1322,7 @@ class Program {
1769
1322
  let importedFileInfo = this.getSourceFileInfo(importInfo.path);
1770
1323
  if (!importedFileInfo) {
1771
1324
  const importName = this._getImportNameForFile(importInfo.path);
1772
- const sourceFile = new sourceFile_1.SourceFile(this.fileSystem, importInfo.path, importName, importInfo.isThirdPartyImport, importInfo.isPyTypedPresent, this._console, this._logTracker);
1325
+ const sourceFile = new sourceFile_1.SourceFile(this.fileSystem, importInfo.path, importName, importInfo.isThirdPartyImport, importInfo.isPyTypedPresent, this._isEditMode, this._console, this._logTracker);
1773
1326
  importedFileInfo = {
1774
1327
  sourceFile,
1775
1328
  isTracked: false,
@@ -1878,7 +1431,7 @@ class Program {
1878
1431
  const importName = this._getImportNameForFile(filePath);
1879
1432
  const sourceFile = new sourceFile_1.SourceFile(this.fileSystem, filePath, importName,
1880
1433
  /* isThirdPartyImport */ false,
1881
- /* isInPyTypedPackage */ false, this._console, this._logTracker);
1434
+ /* isInPyTypedPackage */ false, this._isEditMode, this._console, this._logTracker);
1882
1435
  const sourceFileInfo = {
1883
1436
  sourceFile,
1884
1437
  isTracked: false,