@zzzen/pyright-internal 1.2.0-dev.20230212 → 1.2.0-dev.20230226

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 (170) hide show
  1. package/dist/analyzer/backgroundAnalysisProgram.d.ts +1 -0
  2. package/dist/analyzer/backgroundAnalysisProgram.js +5 -0
  3. package/dist/analyzer/backgroundAnalysisProgram.js.map +1 -1
  4. package/dist/analyzer/binder.js +9 -1
  5. package/dist/analyzer/binder.js.map +1 -1
  6. package/dist/analyzer/checker.js +12 -6
  7. package/dist/analyzer/checker.js.map +1 -1
  8. package/dist/analyzer/codeFlowEngine.js +1 -1
  9. package/dist/analyzer/codeFlowEngine.js.map +1 -1
  10. package/dist/analyzer/commentUtils.d.ts +6 -1
  11. package/dist/analyzer/commentUtils.js +100 -25
  12. package/dist/analyzer/commentUtils.js.map +1 -1
  13. package/dist/analyzer/constraintSolver.js +0 -10
  14. package/dist/analyzer/constraintSolver.js.map +1 -1
  15. package/dist/analyzer/declaration.d.ts +2 -0
  16. package/dist/analyzer/declaration.js.map +1 -1
  17. package/dist/analyzer/importResolver.d.ts +3 -2
  18. package/dist/analyzer/importResolver.js +28 -19
  19. package/dist/analyzer/importResolver.js.map +1 -1
  20. package/dist/analyzer/importStatementUtils.d.ts +1 -0
  21. package/dist/analyzer/importStatementUtils.js +14 -1
  22. package/dist/analyzer/importStatementUtils.js.map +1 -1
  23. package/dist/analyzer/parseTreeUtils.d.ts +5 -2
  24. package/dist/analyzer/parseTreeUtils.js +21 -3
  25. package/dist/analyzer/parseTreeUtils.js.map +1 -1
  26. package/dist/analyzer/patternMatching.d.ts +1 -0
  27. package/dist/analyzer/patternMatching.js +54 -6
  28. package/dist/analyzer/patternMatching.js.map +1 -1
  29. package/dist/analyzer/program.d.ts +11 -4
  30. package/dist/analyzer/program.js +122 -25
  31. package/dist/analyzer/program.js.map +1 -1
  32. package/dist/analyzer/properties.js +5 -1
  33. package/dist/analyzer/properties.js.map +1 -1
  34. package/dist/analyzer/protocols.js +4 -3
  35. package/dist/analyzer/protocols.js.map +1 -1
  36. package/dist/analyzer/service.d.ts +7 -6
  37. package/dist/analyzer/service.js +31 -39
  38. package/dist/analyzer/service.js.map +1 -1
  39. package/dist/analyzer/sourceFile.d.ts +4 -0
  40. package/dist/analyzer/sourceFile.js +85 -16
  41. package/dist/analyzer/sourceFile.js.map +1 -1
  42. package/dist/analyzer/typeEvaluator.js +127 -76
  43. package/dist/analyzer/typeEvaluator.js.map +1 -1
  44. package/dist/backgroundAnalysisBase.d.ts +2 -2
  45. package/dist/backgroundAnalysisBase.js +21 -8
  46. package/dist/backgroundAnalysisBase.js.map +1 -1
  47. package/dist/backgroundThreadBase.js +1 -0
  48. package/dist/backgroundThreadBase.js.map +1 -1
  49. package/dist/commands/commandController.js +1 -0
  50. package/dist/commands/commandController.js.map +1 -1
  51. package/dist/commands/quickActionCommand.js +2 -2
  52. package/dist/commands/quickActionCommand.js.map +1 -1
  53. package/dist/common/cancellationUtils.d.ts +18 -2
  54. package/dist/common/cancellationUtils.js +80 -3
  55. package/dist/common/cancellationUtils.js.map +1 -1
  56. package/dist/common/commandLineOptions.d.ts +2 -0
  57. package/dist/common/commandLineOptions.js.map +1 -1
  58. package/dist/common/configOptions.d.ts +3 -0
  59. package/dist/common/configOptions.js +10 -1
  60. package/dist/common/configOptions.js.map +1 -1
  61. package/dist/common/core.d.ts +2 -0
  62. package/dist/common/core.js +9 -1
  63. package/dist/common/core.js.map +1 -1
  64. package/dist/common/diagnostic.d.ts +15 -3
  65. package/dist/common/diagnostic.js +13 -4
  66. package/dist/common/diagnostic.js.map +1 -1
  67. package/dist/common/editAction.d.ts +1 -0
  68. package/dist/common/editAction.js +8 -0
  69. package/dist/common/editAction.js.map +1 -1
  70. package/dist/common/extensibility.d.ts +36 -12
  71. package/dist/common/extensibility.js +63 -18
  72. package/dist/common/extensibility.js.map +1 -1
  73. package/dist/common/fileBasedCancellationUtils.d.ts +0 -1
  74. package/dist/common/fileBasedCancellationUtils.js +7 -81
  75. package/dist/common/fileBasedCancellationUtils.js.map +1 -1
  76. package/dist/common/pathUtils.d.ts +3 -0
  77. package/dist/common/pathUtils.js +18 -0
  78. package/dist/common/pathUtils.js.map +1 -1
  79. package/dist/common/textEditTracker.d.ts +37 -0
  80. package/dist/common/textEditTracker.js +301 -0
  81. package/dist/common/textEditTracker.js.map +1 -0
  82. package/dist/common/workspaceEditUtils.d.ts +14 -8
  83. package/dist/common/workspaceEditUtils.js +115 -59
  84. package/dist/common/workspaceEditUtils.js.map +1 -1
  85. package/dist/languageServerBase.d.ts +3 -0
  86. package/dist/languageServerBase.js +93 -4
  87. package/dist/languageServerBase.js.map +1 -1
  88. package/dist/languageService/analyzerServiceExecutor.js +1 -0
  89. package/dist/languageService/analyzerServiceExecutor.js.map +1 -1
  90. package/dist/languageService/codeActionProvider.js +1 -1
  91. package/dist/languageService/codeActionProvider.js.map +1 -1
  92. package/dist/languageService/completionProvider.js +3 -3
  93. package/dist/languageService/completionProvider.js.map +1 -1
  94. package/dist/languageService/definitionProvider.js +1 -1
  95. package/dist/languageService/definitionProvider.js.map +1 -1
  96. package/dist/languageService/documentSymbolCollector.js +1 -1
  97. package/dist/languageService/documentSymbolCollector.js.map +1 -1
  98. package/dist/languageService/hoverProvider.js +13 -6
  99. package/dist/languageService/hoverProvider.js.map +1 -1
  100. package/dist/languageService/importAdder.d.ts +5 -1
  101. package/dist/languageService/importAdder.js +50 -14
  102. package/dist/languageService/importAdder.js.map +1 -1
  103. package/dist/languageService/indentationUtils.d.ts +5 -1
  104. package/dist/languageService/indentationUtils.js +12 -2
  105. package/dist/languageService/indentationUtils.js.map +1 -1
  106. package/dist/languageService/insertionPointUtils.js +28 -7
  107. package/dist/languageService/insertionPointUtils.js.map +1 -1
  108. package/dist/languageService/renameModuleProvider.d.ts +20 -10
  109. package/dist/languageService/renameModuleProvider.js +300 -229
  110. package/dist/languageService/renameModuleProvider.js.map +1 -1
  111. package/dist/localization/localize.d.ts +12 -0
  112. package/dist/localization/localize.js +6 -0
  113. package/dist/localization/localize.js.map +1 -1
  114. package/dist/localization/package.nls.en-us.json +8 -1
  115. package/dist/tests/checker.test.js +5 -0
  116. package/dist/tests/checker.test.js.map +1 -1
  117. package/dist/tests/fourslash/hover.docstring.parameter.fourslash.d.ts +1 -0
  118. package/dist/tests/fourslash/hover.docstring.parameter.fourslash.js +57 -0
  119. package/dist/tests/fourslash/hover.docstring.parameter.fourslash.js.map +1 -0
  120. package/dist/tests/fourslash/hover.inferred.fourslash.d.ts +1 -0
  121. package/dist/tests/fourslash/hover.inferred.fourslash.js +24 -0
  122. package/dist/tests/fourslash/hover.inferred.fourslash.js.map +1 -0
  123. package/dist/tests/harness/fourslash/testState.js +9 -2
  124. package/dist/tests/harness/fourslash/testState.js.map +1 -1
  125. package/dist/tests/importAdder.test.js +40 -3
  126. package/dist/tests/importAdder.test.js.map +1 -1
  127. package/dist/tests/indentationUtils.reindent.test.js +1 -1
  128. package/dist/tests/indentationUtils.reindent.test.js.map +1 -1
  129. package/dist/tests/insertionPointUtils.test.js +70 -3
  130. package/dist/tests/insertionPointUtils.test.js.map +1 -1
  131. package/dist/tests/moveSymbol.importAdder.test.js +192 -0
  132. package/dist/tests/moveSymbol.importAdder.test.js.map +1 -0
  133. package/dist/tests/moveSymbol.insertion.test.d.ts +1 -0
  134. package/dist/tests/moveSymbol.insertion.test.js +397 -0
  135. package/dist/tests/moveSymbol.insertion.test.js.map +1 -0
  136. package/dist/tests/moveSymbol.misc.test.d.ts +1 -0
  137. package/dist/tests/moveSymbol.misc.test.js +142 -0
  138. package/dist/tests/moveSymbol.misc.test.js.map +1 -0
  139. package/dist/tests/moveSymbol.updateReference.test.d.ts +1 -0
  140. package/dist/tests/{updateSymbolReference.test.js → moveSymbol.updateReference.test.js} +235 -158
  141. package/dist/tests/moveSymbol.updateReference.test.js.map +1 -0
  142. package/dist/tests/parseTreeUtils.test.js +36 -13
  143. package/dist/tests/parseTreeUtils.test.js.map +1 -1
  144. package/dist/tests/renameModuleTestUtils.js +9 -3
  145. package/dist/tests/renameModuleTestUtils.js.map +1 -1
  146. package/dist/tests/testStateUtils.d.ts +2 -0
  147. package/dist/tests/testStateUtils.js +25 -22
  148. package/dist/tests/testStateUtils.js.map +1 -1
  149. package/dist/tests/textEditUtil.test.d.ts +1 -0
  150. package/dist/tests/textEditUtil.test.js +107 -0
  151. package/dist/tests/textEditUtil.test.js.map +1 -0
  152. package/dist/tests/typeEvaluator1.test.js +4 -0
  153. package/dist/tests/typeEvaluator1.test.js.map +1 -1
  154. package/dist/tests/typeEvaluator2.test.js +12 -0
  155. package/dist/tests/typeEvaluator2.test.js.map +1 -1
  156. package/dist/tests/typeEvaluator3.test.js +9 -0
  157. package/dist/tests/typeEvaluator3.test.js.map +1 -1
  158. package/dist/tests/typeEvaluator4.test.js +5 -1
  159. package/dist/tests/typeEvaluator4.test.js.map +1 -1
  160. package/dist/tests/workspaceEditUtils.test.js +7 -7
  161. package/dist/tests/workspaceEditUtils.test.js.map +1 -1
  162. package/dist/workspaceMap.d.ts +0 -1
  163. package/dist/workspaceMap.js +0 -11
  164. package/dist/workspaceMap.js.map +1 -1
  165. package/package.json +3 -3
  166. package/dist/common/textEditUtils.d.ts +0 -24
  167. package/dist/common/textEditUtils.js +0 -167
  168. package/dist/common/textEditUtils.js.map +0 -1
  169. package/dist/tests/updateSymbolReference.test.js.map +0 -1
  170. /package/dist/tests/{updateSymbolReference.test.d.ts → moveSymbol.importAdder.test.d.ts} +0 -0
@@ -33,8 +33,10 @@ const vscode_languageserver_1 = require("vscode-languageserver");
33
33
  const vscode_languageserver_types_1 = require("vscode-languageserver-types");
34
34
  const cancellationUtils_1 = require("../common/cancellationUtils");
35
35
  const collectionUtils_1 = require("../common/collectionUtils");
36
+ const configOptions_1 = require("../common/configOptions");
36
37
  const console_1 = require("../common/console");
37
38
  const debug_1 = require("../common/debug");
39
+ const diagnosticSink_1 = require("../common/diagnosticSink");
38
40
  const extensibility_1 = require("../common/extensibility");
39
41
  const logTracker_1 = require("../common/logTracker");
40
42
  const pathUtils_1 = require("../common/pathUtils");
@@ -42,10 +44,14 @@ const positionUtils_1 = require("../common/positionUtils");
42
44
  const stringUtils_1 = require("../common/stringUtils");
43
45
  const textRange_1 = require("../common/textRange");
44
46
  const timing_1 = require("../common/timing");
47
+ const workspaceEditUtils_1 = require("../common/workspaceEditUtils");
45
48
  const autoImporter_1 = require("../languageService/autoImporter");
46
49
  const callHierarchyProvider_1 = require("../languageService/callHierarchyProvider");
47
50
  const completionProvider_1 = require("../languageService/completionProvider");
48
51
  const documentSymbolCollector_1 = require("../languageService/documentSymbolCollector");
52
+ const importAdder_1 = require("../languageService/importAdder");
53
+ const indentationUtils_1 = require("../languageService/indentationUtils");
54
+ const insertionPointUtils_1 = require("../languageService/insertionPointUtils");
49
55
  const referencesProvider_1 = require("../languageService/referencesProvider");
50
56
  const renameModuleProvider_1 = require("../languageService/renameModuleProvider");
51
57
  const AnalyzerNodeInfo = __importStar(require("./analyzerNodeInfo"));
@@ -137,6 +143,8 @@ class Program {
137
143
  this._cacheManager = cacheManager !== null && cacheManager !== void 0 ? cacheManager : new cacheManager_1.CacheManager();
138
144
  this._cacheManager.registerCacheOwner(this);
139
145
  this._createNewEvaluator();
146
+ this._id = Program._nextId;
147
+ Program._nextId += 1;
140
148
  }
141
149
  dispose() {
142
150
  this._cacheManager.unregisterCacheOwner(this);
@@ -147,6 +155,9 @@ class Program {
147
155
  get console() {
148
156
  return this._console;
149
157
  }
158
+ get id() {
159
+ return this._id;
160
+ }
150
161
  setConfigOptions(configOptions) {
151
162
  this._configOptions = configOptions;
152
163
  this._importResolver.setConfigOptions(configOptions);
@@ -208,6 +219,15 @@ class Program {
208
219
  this.addTrackedFile(filePath, isThirdPartyImport, isInPyTypedPackage);
209
220
  });
210
221
  }
222
+ addInterimFile(filePath) {
223
+ // Double check not already there.
224
+ let fileInfo = this.getSourceFileInfo(filePath);
225
+ if (!fileInfo) {
226
+ fileInfo = this._createInterimFileInfo(filePath);
227
+ this._addToSourceFileListAndMap(fileInfo);
228
+ }
229
+ return fileInfo;
230
+ }
211
231
  addTrackedFile(filePath, isThirdPartyImport = false, isInPyTypedPackage = false) {
212
232
  let sourceFileInfo = this.getSourceFileInfo(filePath);
213
233
  const importName = this._getImportNameForFile(filePath);
@@ -269,8 +289,6 @@ class Program {
269
289
  sourceFileInfo.diagnosticsVersion = 0;
270
290
  }
271
291
  sourceFileInfo.sourceFile.setClientVersion(version, contents);
272
- // Tell any extensions that this source file changed.
273
- (0, extensibility_1.getExtensions)().forEach((e) => (e.sourceFileChanged ? e.sourceFileChanged(sourceFileInfo) : undefined));
274
292
  }
275
293
  getChainedFilePath(filePath) {
276
294
  var _a;
@@ -358,8 +376,8 @@ class Program {
358
376
  getUserFileCount() {
359
377
  return this._sourceFileList.filter((s) => (0, sourceFileInfoUtils_1.isUserCode)(s)).length;
360
378
  }
361
- getTracked() {
362
- return this._sourceFileList.filter((s) => s.isTracked);
379
+ getUserFiles() {
380
+ return this._sourceFileList.filter((s) => (0, sourceFileInfoUtils_1.isUserCode)(s));
363
381
  }
364
382
  getOpened() {
365
383
  return this._sourceFileList.filter((s) => s.isOpenByClient);
@@ -388,6 +406,15 @@ class Program {
388
406
  const normalized = (0, pathUtils_1.normalizePathCase)(this._fs, folder);
389
407
  return this._sourceFileList.some((i) => i.sourceFile.getFilePath().startsWith(normalized));
390
408
  }
409
+ owns(filePath) {
410
+ const fileInfo = this.getSourceFileInfo(filePath);
411
+ if (fileInfo) {
412
+ // If we already determined whether the file is tracked or not, don't do it again.
413
+ // This will make sure we have consistent look at the state once it is loaded to the memory.
414
+ return fileInfo.isTracked;
415
+ }
416
+ return (0, configOptions_1.matchFileSpecs)(this._configOptions, filePath);
417
+ }
391
418
  getSourceFile(filePath) {
392
419
  const sourceFileInfo = this.getSourceFileInfo(filePath);
393
420
  if (!sourceFileInfo) {
@@ -402,12 +429,12 @@ class Program {
402
429
  getSourceFileInfo(filePath) {
403
430
  return this._sourceFileMap.get((0, pathUtils_1.normalizePathCase)(this._fs, filePath));
404
431
  }
405
- getBoundSourceFileInfo(filePath) {
432
+ getBoundSourceFileInfo(filePath, content, force) {
406
433
  const sourceFileInfo = this.getSourceFileInfo(filePath);
407
434
  if (!sourceFileInfo) {
408
435
  return undefined;
409
436
  }
410
- this._bindFile(sourceFileInfo);
437
+ this._bindFile(sourceFileInfo, content, force);
411
438
  return sourceFileInfo;
412
439
  }
413
440
  // Performs parsing and analysis of any source files in the program
@@ -658,8 +685,7 @@ class Program {
658
685
  _addShadowedFile(stubFile, shadowImplPath) {
659
686
  let shadowFileInfo = this.getSourceFileInfo(shadowImplPath);
660
687
  if (!shadowFileInfo) {
661
- shadowFileInfo = this._createInterimFileInfo(shadowImplPath);
662
- this._addToSourceFileListAndMap(shadowFileInfo);
688
+ shadowFileInfo = this.addInterimFile(shadowImplPath);
663
689
  }
664
690
  if (!shadowFileInfo.shadows.includes(stubFile)) {
665
691
  shadowFileInfo.shadows.push(stubFile);
@@ -707,8 +733,8 @@ class Program {
707
733
  : undefined);
708
734
  return this._evaluator;
709
735
  }
710
- _parseFile(fileToParse, content) {
711
- if (!this._isFileNeeded(fileToParse) || !fileToParse.sourceFile.isParseRequired()) {
736
+ _parseFile(fileToParse, content, force) {
737
+ if (!force && (!this._isFileNeeded(fileToParse) || !fileToParse.sourceFile.isParseRequired())) {
712
738
  return;
713
739
  }
714
740
  if (fileToParse.sourceFile.parse(this._configOptions, this._importResolver, content)) {
@@ -727,12 +753,12 @@ class Program {
727
753
  }
728
754
  // Binds the specified file and all of its dependencies, recursively. If
729
755
  // it runs out of time, it returns true. If it completes, it returns false.
730
- _bindFile(fileToAnalyze, content) {
756
+ _bindFile(fileToAnalyze, content, force) {
731
757
  var _a, _b;
732
- if (!this._isFileNeeded(fileToAnalyze) || !fileToAnalyze.sourceFile.isBindingRequired()) {
758
+ if (!force && (!this._isFileNeeded(fileToAnalyze) || !fileToAnalyze.sourceFile.isBindingRequired())) {
733
759
  return;
734
760
  }
735
- this._parseFile(fileToAnalyze, content);
761
+ this._parseFile(fileToAnalyze, content, force);
736
762
  const getScopeIfAvailable = (fileInfo) => {
737
763
  if (!fileInfo || fileInfo === fileToAnalyze) {
738
764
  return undefined;
@@ -1316,14 +1342,11 @@ class Program {
1316
1342
  autoImportInfo: completionResult === null || completionResult === void 0 ? void 0 : completionResult.autoImportInfo,
1317
1343
  extensionInfo: completionResult === null || completionResult === void 0 ? void 0 : completionResult.extensionInfo,
1318
1344
  };
1319
- if (!(0, extensibility_1.getExtensions)().some((e) => e.completionListExtension)) {
1320
- return completionResultsList;
1321
- }
1322
1345
  const parseResults = sourceFileInfo.sourceFile.getParseResults();
1323
1346
  if ((parseResults === null || parseResults === void 0 ? void 0 : parseResults.parseTree) && (parseResults === null || parseResults === void 0 ? void 0 : parseResults.text)) {
1324
1347
  const offset = (0, positionUtils_1.convertPositionToOffset)(position, parseResults.tokenizerOutput.lines);
1325
1348
  if (offset !== undefined && sourceMapper) {
1326
- await Promise.all((0, extensibility_1.getExtensions)().map((e) => {
1349
+ await Promise.all(extensibility_1.Extensions.getProgramExtensions(parseResults.parseTree).map((e) => {
1327
1350
  var _a;
1328
1351
  return (_a = e.completionListExtension) === null || _a === void 0 ? void 0 : _a.updateCompletionResults(this.evaluator, sourceMapper, options, completionResultsList, parseResults, offset, this._configOptions.functionSignatureDisplay, token);
1329
1352
  }));
@@ -1358,12 +1381,23 @@ class Program {
1358
1381
  return { edits: renameModuleProvider.getEdits(), fileOperations: [] };
1359
1382
  });
1360
1383
  }
1361
- moveSymbolAtPosition(filePath, newFilePath, position, token) {
1384
+ moveSymbolAtPosition(filePath, newFilePath, position, options, token) {
1362
1385
  return this._runEvaluatorWithCancellationToken(token, () => {
1386
+ const sourceFileExt = (0, pathUtils_1.getFileExtension)(filePath);
1387
+ const destFileExt = (0, pathUtils_1.getFileExtension)(newFilePath);
1388
+ if (sourceFileExt.toLowerCase() !== destFileExt.toLowerCase()) {
1389
+ // Don't allow moving a symbol from py to pyi or vice versa.
1390
+ return undefined;
1391
+ }
1363
1392
  const fileInfo = this.getSourceFileInfo(filePath);
1364
1393
  if (!fileInfo) {
1365
1394
  return undefined;
1366
1395
  }
1396
+ const newFileInfo = this.getBoundSourceFileInfo(newFilePath);
1397
+ if (fileInfo === newFileInfo) {
1398
+ // Can't move symbol to the same file.
1399
+ return undefined;
1400
+ }
1367
1401
  this._bindFile(fileInfo);
1368
1402
  const parseResults = fileInfo.sourceFile.getParseResults();
1369
1403
  if (!parseResults) {
@@ -1378,7 +1412,7 @@ class Program {
1378
1412
  return undefined;
1379
1413
  }
1380
1414
  // If this isn't a name node, there are no references to be found.
1381
- if (node.nodeType !== 38 /* Name */) {
1415
+ if (node.nodeType !== 38 /* Name */ || !renameModuleProvider_1.RenameModuleProvider.canMoveSymbol(this._evaluator, node)) {
1382
1416
  return undefined;
1383
1417
  }
1384
1418
  const execEnv = this._configOptions.findExecEnvironment(filePath);
@@ -1389,8 +1423,71 @@ class Program {
1389
1423
  return undefined;
1390
1424
  }
1391
1425
  this._processModuleReferences(renameModuleProvider, node.value, filePath);
1392
- return { edits: renameModuleProvider.getEdits(), fileOperations: [] };
1426
+ const sourceDecl = renameModuleProvider.declarations.find((d) => d.node && (0, pathUtils_1.getFileExtension)(d.path) === sourceFileExt);
1427
+ if (!sourceDecl) {
1428
+ // Can't find symbol we can move.
1429
+ return undefined;
1430
+ }
1431
+ const symbolRange = renameModuleProvider_1.RenameModuleProvider.getSymbolTextRange(parseResults, sourceDecl);
1432
+ const importAdder = new importAdder_1.ImportAdder(this._configOptions, this._importResolver, this._evaluator);
1433
+ const collectedimports = importAdder.collectImportsForSymbolsUsed(parseResults, symbolRange, token);
1434
+ let insertionPoint = 0;
1435
+ let insertionIndentation = 0;
1436
+ const newFileParseResults = newFileInfo === null || newFileInfo === void 0 ? void 0 : newFileInfo.sourceFile.getParseResults();
1437
+ if (newFileParseResults) {
1438
+ const insertBefore = renameModuleProvider.tryGetFirstSymbolUsage(newFileParseResults);
1439
+ insertionPoint = (0, insertionPointUtils_1.getInsertionPointForSymbolUnderModule)(this._evaluator, newFileParseResults, node.value, {
1440
+ symbolDeclToIgnore: sourceDecl.path,
1441
+ insertBefore,
1442
+ });
1443
+ if (insertionPoint === undefined) {
1444
+ // No place to insert the symbol.
1445
+ return undefined;
1446
+ }
1447
+ insertionIndentation = (0, indentationUtils_1.getModuleStatementIndentation)(newFileParseResults);
1448
+ }
1449
+ const reindentResult = (0, indentationUtils_1.reindentSpan)(parseResults, symbolRange, insertionIndentation);
1450
+ const fullRange = renameModuleProvider_1.RenameModuleProvider.getSymbolFullStatementTextRange(parseResults, sourceDecl);
1451
+ renameModuleProvider.textEditTracker.addEdit(filePath, (0, positionUtils_1.convertTextRangeToRange)(textRange_1.TextRange.combine([reindentResult.originalSpan, fullRange]), parseResults.tokenizerOutput.lines), '');
1452
+ const fileOperations = [];
1453
+ let codeSnippetToInsert = reindentResult.text;
1454
+ if (newFileParseResults) {
1455
+ // TODO: We need to "add import" statement for symbols defined in the destination file
1456
+ // if we couldn't find insertion point where all constraints are met.
1457
+ // For example, if the symbol we are moving is used before other symbols it references are declared.
1458
+ importAdder.applyImportsTo(collectedimports, newFileParseResults, options.importFormat, renameModuleProvider.textEditTracker, token);
1459
+ const range = (0, positionUtils_1.convertTextRangeToRange)({ start: insertionPoint, length: 0 }, newFileParseResults.tokenizerOutput.lines);
1460
+ // If we are adding at the end of line (ex, end of a file),
1461
+ // add new lines.
1462
+ const newLinesToAdd = _getNumberOfBlankLinesToInsert(newFileParseResults, range.end);
1463
+ codeSnippetToInsert = '\n'.repeat(newLinesToAdd) + codeSnippetToInsert;
1464
+ renameModuleProvider.textEditTracker.addEdit(newFilePath, range, codeSnippetToInsert);
1465
+ }
1466
+ else {
1467
+ fileOperations.push({ kind: 'create', filePath: newFilePath });
1468
+ const tempParseResults = (0, sourceFile_1.parseFile)(this._configOptions, newFilePath, codeSnippetToInsert, sourceFile_1.IPythonMode.None, new diagnosticSink_1.DiagnosticSink());
1469
+ const insertAddEdits = importAdder.applyImports(collectedimports, newFilePath, tempParseResults, insertionPoint, options.importFormat, token);
1470
+ const updateContent = (0, workspaceEditUtils_1.applyTextEditsToString)(insertAddEdits, tempParseResults.tokenizerOutput.lines, codeSnippetToInsert);
1471
+ renameModuleProvider.textEditTracker.addEdit(newFilePath, (0, textRange_1.getEmptyRange)(), updateContent);
1472
+ }
1473
+ return {
1474
+ edits: renameModuleProvider.getEdits(),
1475
+ fileOperations,
1476
+ };
1393
1477
  });
1478
+ function _getNumberOfBlankLinesToInsert(parseResults, position) {
1479
+ // This basically try to add 2 blanks lines before previous line with text.
1480
+ if (position.line === 0 && position.character === 0) {
1481
+ return 0;
1482
+ }
1483
+ const linesToAdd = position.line > 0 && (0, parseTreeUtils_1.isBlankLine)(parseResults, position.line - 1)
1484
+ ? position.line > 1 && (0, parseTreeUtils_1.isBlankLine)(parseResults, position.line - 2)
1485
+ ? 0
1486
+ : 1
1487
+ : 2;
1488
+ // Add one more line for the line that position is on if it is not blank.
1489
+ return position.character !== 0 ? linesToAdd + 1 : linesToAdd;
1490
+ }
1394
1491
  }
1395
1492
  canRenameSymbolAtPosition(filePath, position, isDefaultWorkspace, allowModuleRename, token) {
1396
1493
  return this._runEvaluatorWithCancellationToken(token, () => {
@@ -1584,6 +1681,7 @@ class Program {
1584
1681
  this._createNewEvaluator();
1585
1682
  this._discardCachedParseResults();
1586
1683
  this._parsedFileCount = 0;
1684
+ extensibility_1.Extensions.getProgramExtensions(this.rootPath).forEach((e) => (e.clearCache ? e.clearCache() : null));
1587
1685
  }
1588
1686
  test_createSourceMapper(execEnv, from) {
1589
1687
  return this._createSourceMapper(execEnv, vscode_languageserver_1.CancellationToken.None, /*from*/ from, /* mapCompiled */ false);
@@ -1655,7 +1753,7 @@ class Program {
1655
1753
  if (!parseResult) {
1656
1754
  continue;
1657
1755
  }
1658
- renameModuleProvider.renameReferences(filePath, parseResult);
1756
+ renameModuleProvider.renameReferences(parseResult);
1659
1757
  // This operation can consume significant memory, so check
1660
1758
  // for situations where we need to discard the type cache.
1661
1759
  this._handleMemoryHighUsage();
@@ -1814,8 +1912,7 @@ class Program {
1814
1912
  // Special case for import statement.
1815
1913
  // ex) import X.Y
1816
1914
  // SourceFile for X might not be in memory since import `X.Y` only brings in Y
1817
- stubFileInfo = this._createInterimFileInfo(stubFilePath);
1818
- this._addToSourceFileListAndMap(stubFileInfo);
1915
+ stubFileInfo = this.addInterimFile(stubFilePath);
1819
1916
  }
1820
1917
  this._addShadowedFile(stubFileInfo, implFilePath);
1821
1918
  return this.getBoundSourceFile(implFilePath);
@@ -1825,8 +1922,7 @@ class Program {
1825
1922
  // Special case for import statement.
1826
1923
  // ex) import X.Y
1827
1924
  // SourceFile for X might not be in memory since import `X.Y` only brings in Y
1828
- fileInfo = this._createInterimFileInfo(f);
1829
- this._addToSourceFileListAndMap(fileInfo);
1925
+ fileInfo = this.addInterimFile(f);
1830
1926
  // Even though this file is not referenced by anything, make sure
1831
1927
  // we have parse tree for doc string.
1832
1928
  fileInfo.sourceFile.parse(this._configOptions, this._importResolver);
@@ -2079,4 +2175,5 @@ class Program {
2079
2175
  }
2080
2176
  }
2081
2177
  exports.Program = Program;
2178
+ Program._nextId = 0;
2082
2179
  //# sourceMappingURL=program.js.map