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

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 (231) hide show
  1. package/dist/analyzer/backgroundAnalysisProgram.d.ts +4 -1
  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 +89 -6
  6. package/dist/analyzer/checker.js.map +1 -1
  7. package/dist/analyzer/constraintSolver.js +14 -15
  8. package/dist/analyzer/constraintSolver.js.map +1 -1
  9. package/dist/analyzer/constructors.d.ts +6 -0
  10. package/dist/analyzer/constructors.js +513 -0
  11. package/dist/analyzer/constructors.js.map +1 -0
  12. package/dist/analyzer/dataClasses.js +86 -2
  13. package/dist/analyzer/dataClasses.js.map +1 -1
  14. package/dist/analyzer/docStringConversion.js +1 -1
  15. package/dist/analyzer/docStringConversion.js.map +1 -1
  16. package/dist/analyzer/enums.js +62 -8
  17. package/dist/analyzer/enums.js.map +1 -1
  18. package/dist/analyzer/importResolver.js +47 -29
  19. package/dist/analyzer/importResolver.js.map +1 -1
  20. package/dist/analyzer/importStatementUtils.d.ts +2 -2
  21. package/dist/analyzer/importStatementUtils.js.map +1 -1
  22. package/dist/analyzer/namedTuples.js +3 -6
  23. package/dist/analyzer/namedTuples.js.map +1 -1
  24. package/dist/analyzer/operations.d.ts +16 -0
  25. package/dist/analyzer/operations.js +749 -0
  26. package/dist/analyzer/operations.js.map +1 -0
  27. package/dist/analyzer/parseTreeUtils.d.ts +4 -2
  28. package/dist/analyzer/parseTreeUtils.js +32 -1
  29. package/dist/analyzer/parseTreeUtils.js.map +1 -1
  30. package/dist/analyzer/patternMatching.js +16 -0
  31. package/dist/analyzer/patternMatching.js.map +1 -1
  32. package/dist/analyzer/program.d.ts +11 -33
  33. package/dist/analyzer/program.js +73 -735
  34. package/dist/analyzer/program.js.map +1 -1
  35. package/dist/analyzer/protocols.js +1 -1
  36. package/dist/analyzer/protocols.js.map +1 -1
  37. package/dist/analyzer/service.d.ts +5 -21
  38. package/dist/analyzer/service.js +26 -33
  39. package/dist/analyzer/service.js.map +1 -1
  40. package/dist/analyzer/sourceFile.d.ts +9 -41
  41. package/dist/analyzer/sourceFile.js +219 -238
  42. package/dist/analyzer/sourceFile.js.map +1 -1
  43. package/dist/analyzer/sourceFileInfoUtils.d.ts +3 -9
  44. package/dist/analyzer/sourceFileInfoUtils.js.map +1 -1
  45. package/dist/analyzer/symbol.d.ts +3 -1
  46. package/dist/analyzer/symbol.js +5 -0
  47. package/dist/analyzer/symbol.js.map +1 -1
  48. package/dist/analyzer/typeEvaluator.js +460 -1425
  49. package/dist/analyzer/typeEvaluator.js.map +1 -1
  50. package/dist/analyzer/typeEvaluatorTypes.d.ts +42 -7
  51. package/dist/analyzer/typeEvaluatorTypes.js +33 -1
  52. package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
  53. package/dist/analyzer/typeGuards.js +2 -8
  54. package/dist/analyzer/typeGuards.js.map +1 -1
  55. package/dist/analyzer/typePrinter.d.ts +3 -3
  56. package/dist/analyzer/typePrinter.js +247 -100
  57. package/dist/analyzer/typePrinter.js.map +1 -1
  58. package/dist/analyzer/typeUtils.d.ts +14 -7
  59. package/dist/analyzer/typeUtils.js +204 -49
  60. package/dist/analyzer/typeUtils.js.map +1 -1
  61. package/dist/analyzer/typeVarContext.d.ts +6 -7
  62. package/dist/analyzer/typeVarContext.js +21 -32
  63. package/dist/analyzer/typeVarContext.js.map +1 -1
  64. package/dist/analyzer/typedDicts.js +2 -2
  65. package/dist/analyzer/typedDicts.js.map +1 -1
  66. package/dist/analyzer/types.d.ts +7 -4
  67. package/dist/analyzer/types.js +20 -10
  68. package/dist/analyzer/types.js.map +1 -1
  69. package/dist/backgroundAnalysisBase.d.ts +1 -1
  70. package/dist/backgroundAnalysisBase.js +16 -0
  71. package/dist/backgroundAnalysisBase.js.map +1 -1
  72. package/dist/commands/dumpFileDebugInfoCommand.js +0 -1
  73. package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
  74. package/dist/common/extensibility.d.ts +28 -4
  75. package/dist/common/extensibility.js.map +1 -1
  76. package/dist/common/logTracker.d.ts +2 -0
  77. package/dist/common/logTracker.js +8 -1
  78. package/dist/common/logTracker.js.map +1 -1
  79. package/dist/common/lspUtils.d.ts +4 -1
  80. package/dist/common/lspUtils.js +38 -1
  81. package/dist/common/lspUtils.js.map +1 -1
  82. package/dist/common/pathUtils.d.ts +11 -11
  83. package/dist/common/pathUtils.js.map +1 -1
  84. package/dist/common/pythonVersion.d.ts +2 -1
  85. package/dist/common/pythonVersion.js +1 -0
  86. package/dist/common/pythonVersion.js.map +1 -1
  87. package/dist/common/workspaceEditUtils.d.ts +8 -8
  88. package/dist/common/workspaceEditUtils.js +10 -10
  89. package/dist/common/workspaceEditUtils.js.map +1 -1
  90. package/dist/languageServerBase.d.ts +3 -7
  91. package/dist/languageServerBase.js +41 -73
  92. package/dist/languageServerBase.js.map +1 -1
  93. package/dist/languageService/autoImporter.d.ts +50 -51
  94. package/dist/languageService/autoImporter.js +125 -210
  95. package/dist/languageService/autoImporter.js.map +1 -1
  96. package/dist/languageService/callHierarchyProvider.d.ts +1 -1
  97. package/dist/languageService/callHierarchyProvider.js +11 -37
  98. package/dist/languageService/callHierarchyProvider.js.map +1 -1
  99. package/dist/languageService/completionProvider.d.ts +39 -81
  100. package/dist/languageService/completionProvider.js +572 -801
  101. package/dist/languageService/completionProvider.js.map +1 -1
  102. package/dist/languageService/documentHighlightProvider.js +1 -1
  103. package/dist/languageService/documentHighlightProvider.js.map +1 -1
  104. package/dist/languageService/documentSymbolCollector.d.ts +6 -7
  105. package/dist/languageService/documentSymbolCollector.js +47 -28
  106. package/dist/languageService/documentSymbolCollector.js.map +1 -1
  107. package/dist/languageService/documentSymbolProvider.d.ts +13 -35
  108. package/dist/languageService/documentSymbolProvider.js +52 -264
  109. package/dist/languageService/documentSymbolProvider.js.map +1 -1
  110. package/dist/languageService/hoverProvider.d.ts +5 -6
  111. package/dist/languageService/hoverProvider.js +40 -132
  112. package/dist/languageService/hoverProvider.js.map +1 -1
  113. package/dist/languageService/referencesProvider.d.ts +6 -11
  114. package/dist/languageService/referencesProvider.js +23 -17
  115. package/dist/languageService/referencesProvider.js.map +1 -1
  116. package/dist/languageService/renameProvider.d.ts +16 -0
  117. package/dist/languageService/renameProvider.js +139 -0
  118. package/dist/languageService/renameProvider.js.map +1 -0
  119. package/dist/languageService/symbolIndexer.d.ts +31 -0
  120. package/dist/languageService/symbolIndexer.js +105 -0
  121. package/dist/languageService/symbolIndexer.js.map +1 -0
  122. package/dist/languageService/tooltipUtils.d.ts +8 -1
  123. package/dist/languageService/tooltipUtils.js +102 -1
  124. package/dist/languageService/tooltipUtils.js.map +1 -1
  125. package/dist/languageService/workspaceSymbolProvider.d.ts +17 -0
  126. package/dist/languageService/workspaceSymbolProvider.js +133 -0
  127. package/dist/languageService/workspaceSymbolProvider.js.map +1 -0
  128. package/dist/localization/localize.d.ts +33 -15
  129. package/dist/localization/localize.js +13 -7
  130. package/dist/localization/localize.js.map +1 -1
  131. package/dist/localization/package.nls.en-us.json +14 -7
  132. package/dist/parser/parser.js +3 -0
  133. package/dist/parser/parser.js.map +1 -1
  134. package/dist/pyright.js +26 -4
  135. package/dist/pyright.js.map +1 -1
  136. package/dist/tests/chainedSourceFiles.test.js +15 -20
  137. package/dist/tests/chainedSourceFiles.test.js.map +1 -1
  138. package/dist/tests/checker.test.js +14 -0
  139. package/dist/tests/checker.test.js.map +1 -1
  140. package/dist/tests/completions.test.js +11 -236
  141. package/dist/tests/completions.test.js.map +1 -1
  142. package/dist/tests/docStringConversion.test.js +36 -2
  143. package/dist/tests/docStringConversion.test.js.map +1 -1
  144. package/dist/tests/documentSymbolCollector.test.js +3 -3
  145. package/dist/tests/documentSymbolCollector.test.js.map +1 -1
  146. package/dist/tests/fourslash/completions.override2.fourslash.js +1 -16
  147. package/dist/tests/fourslash/completions.override2.fourslash.js.map +1 -1
  148. package/dist/tests/fourslash/fourslash.d.ts +4 -4
  149. package/dist/tests/fourslash/missingTypeStub.codeAction.fourslash.js +1 -1
  150. package/dist/tests/fourslash/missingTypeStub.codeAction.fourslash.js.map +1 -1
  151. package/dist/tests/harness/fourslash/testState.d.ts +17 -11
  152. package/dist/tests/harness/fourslash/testState.js +39 -50
  153. package/dist/tests/harness/fourslash/testState.js.map +1 -1
  154. package/dist/tests/importResolver.test.js +81 -1
  155. package/dist/tests/importResolver.test.js.map +1 -1
  156. package/dist/tests/sourceFile.test.js +1 -1
  157. package/dist/tests/sourceFile.test.js.map +1 -1
  158. package/dist/tests/testStateUtils.d.ts +2 -2
  159. package/dist/tests/testStateUtils.js +38 -8
  160. package/dist/tests/testStateUtils.js.map +1 -1
  161. package/dist/tests/typeEvaluator2.test.js +13 -1
  162. package/dist/tests/typeEvaluator2.test.js.map +1 -1
  163. package/dist/tests/typeEvaluator3.test.js +5 -1
  164. package/dist/tests/typeEvaluator3.test.js.map +1 -1
  165. package/dist/tests/typeEvaluator4.test.js +9 -1
  166. package/dist/tests/typeEvaluator4.test.js.map +1 -1
  167. package/dist/tests/typeEvaluator5.test.js +25 -9
  168. package/dist/tests/typeEvaluator5.test.js.map +1 -1
  169. package/dist/tests/workspaceEditUtils.test.js +95 -6
  170. package/dist/tests/workspaceEditUtils.test.js.map +1 -1
  171. package/package.json +4 -4
  172. package/dist/languageService/importAdder.d.ts +0 -40
  173. package/dist/languageService/importAdder.js +0 -388
  174. package/dist/languageService/importAdder.js.map +0 -1
  175. package/dist/languageService/indentationUtils.d.ts +0 -16
  176. package/dist/languageService/indentationUtils.js +0 -727
  177. package/dist/languageService/indentationUtils.js.map +0 -1
  178. package/dist/languageService/insertionPointUtils.d.ts +0 -9
  179. package/dist/languageService/insertionPointUtils.js +0 -132
  180. package/dist/languageService/insertionPointUtils.js.map +0 -1
  181. package/dist/languageService/renameModuleProvider.d.ts +0 -65
  182. package/dist/languageService/renameModuleProvider.js +0 -939
  183. package/dist/languageService/renameModuleProvider.js.map +0 -1
  184. package/dist/tests/fourslash/completions.commitChars.fourslash.d.ts +0 -1
  185. package/dist/tests/fourslash/completions.commitChars.fourslash.js +0 -81
  186. package/dist/tests/fourslash/completions.commitChars.fourslash.js.map +0 -1
  187. package/dist/tests/importAdder.test.d.ts +0 -1
  188. package/dist/tests/importAdder.test.js +0 -1325
  189. package/dist/tests/importAdder.test.js.map +0 -1
  190. package/dist/tests/indentationUtils.ptvs.test.d.ts +0 -1
  191. package/dist/tests/indentationUtils.ptvs.test.js +0 -324
  192. package/dist/tests/indentationUtils.ptvs.test.js.map +0 -1
  193. package/dist/tests/indentationUtils.reindent.test.d.ts +0 -1
  194. package/dist/tests/indentationUtils.reindent.test.js +0 -372
  195. package/dist/tests/indentationUtils.reindent.test.js.map +0 -1
  196. package/dist/tests/indentationUtils.test.d.ts +0 -1
  197. package/dist/tests/indentationUtils.test.js +0 -502
  198. package/dist/tests/indentationUtils.test.js.map +0 -1
  199. package/dist/tests/insertionPointUtils.test.d.ts +0 -1
  200. package/dist/tests/insertionPointUtils.test.js +0 -154
  201. package/dist/tests/insertionPointUtils.test.js.map +0 -1
  202. package/dist/tests/moveSymbol.importAdder.test.d.ts +0 -1
  203. package/dist/tests/moveSymbol.importAdder.test.js +0 -298
  204. package/dist/tests/moveSymbol.importAdder.test.js.map +0 -1
  205. package/dist/tests/moveSymbol.insertion.test.d.ts +0 -1
  206. package/dist/tests/moveSymbol.insertion.test.js +0 -537
  207. package/dist/tests/moveSymbol.insertion.test.js.map +0 -1
  208. package/dist/tests/moveSymbol.misc.test.d.ts +0 -1
  209. package/dist/tests/moveSymbol.misc.test.js +0 -169
  210. package/dist/tests/moveSymbol.misc.test.js.map +0 -1
  211. package/dist/tests/moveSymbol.updateReference.test.d.ts +0 -1
  212. package/dist/tests/moveSymbol.updateReference.test.js +0 -1071
  213. package/dist/tests/moveSymbol.updateReference.test.js.map +0 -1
  214. package/dist/tests/renameModule.folder.test.d.ts +0 -1
  215. package/dist/tests/renameModule.folder.test.js +0 -229
  216. package/dist/tests/renameModule.folder.test.js.map +0 -1
  217. package/dist/tests/renameModule.fromImports.test.d.ts +0 -1
  218. package/dist/tests/renameModule.fromImports.test.js +0 -790
  219. package/dist/tests/renameModule.fromImports.test.js.map +0 -1
  220. package/dist/tests/renameModule.imports.test.d.ts +0 -1
  221. package/dist/tests/renameModule.imports.test.js +0 -380
  222. package/dist/tests/renameModule.imports.test.js.map +0 -1
  223. package/dist/tests/renameModule.misc.test.d.ts +0 -1
  224. package/dist/tests/renameModule.misc.test.js +0 -615
  225. package/dist/tests/renameModule.misc.test.js.map +0 -1
  226. package/dist/tests/renameModule.relativePath.test.d.ts +0 -1
  227. package/dist/tests/renameModule.relativePath.test.js +0 -231
  228. package/dist/tests/renameModule.relativePath.test.js.map +0 -1
  229. package/dist/tests/renameModuleTestUtils.d.ts +0 -4
  230. package/dist/tests/renameModuleTestUtils.js +0 -76
  231. package/dist/tests/renameModuleTestUtils.js.map +0 -1
@@ -28,6 +28,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  const assert = __importStar(require("assert"));
30
30
  const vscode_languageserver_types_1 = require("vscode-languageserver-types");
31
+ const vscode_languageserver_1 = require("vscode-languageserver");
32
+ const sourceFile_1 = require("../analyzer/sourceFile");
31
33
  const pathUtils_1 = require("../common/pathUtils");
32
34
  const workspaceEditUtils_1 = require("../common/workspaceEditUtils");
33
35
  const analyzerServiceExecutor_1 = require("../languageService/analyzerServiceExecutor");
@@ -44,7 +46,7 @@ test('test applyWorkspaceEdits changes', async () => {
44
46
  const cloned = await getClonedService(state);
45
47
  const range = state.getRangeByMarkerName('marker');
46
48
  const fileChanged = new Set();
47
- (0, workspaceEditUtils_1.applyWorkspaceEdit)(cloned, {
49
+ applyWorkspaceEditToService(cloned, {
48
50
  changes: {
49
51
  [(0, pathUtils_1.convertPathToUri)(cloned.fs, range.fileName)]: [
50
52
  {
@@ -57,6 +59,88 @@ test('test applyWorkspaceEdits changes', async () => {
57
59
  assert.strictEqual(fileChanged.size, 1);
58
60
  assert.strictEqual((_a = cloned.test_program.getSourceFile(range.fileName)) === null || _a === void 0 ? void 0 : _a.getFileContent(), 'Text Changed');
59
61
  });
62
+ test('test edit mode for workspace', async () => {
63
+ const code = `
64
+ // @filename: test.py
65
+ //// [|/*marker*/|]
66
+ `;
67
+ const state = (0, testState_1.parseAndGetTestState)(code).state;
68
+ const range = state.getRangeByMarkerName('marker');
69
+ const addedFilePath = (0, pathUtils_1.combinePaths)((0, pathUtils_1.getDirectoryPath)(range.fileName), 'test2.py');
70
+ const edits = await state.workspace.service.runEditMode(async () => {
71
+ const fileChanged = new Set();
72
+ applyWorkspaceEditToService(state.workspace.service, {
73
+ documentChanges: [
74
+ vscode_languageserver_types_1.TextDocumentEdit.create({
75
+ uri: (0, pathUtils_1.convertPathToUri)(state.workspace.service.fs, range.fileName),
76
+ version: null,
77
+ }, [
78
+ {
79
+ range: state.convertPositionRange(range),
80
+ newText: 'import sys',
81
+ },
82
+ ]),
83
+ ],
84
+ }, fileChanged);
85
+ assert.strictEqual(fileChanged.size, 1);
86
+ const newSourceFile = state.workspace.service.test_program.getSourceFile(range.fileName);
87
+ state.workspace.service.backgroundAnalysisProgram.analyzeFile(newSourceFile.getFilePath(), vscode_languageserver_1.CancellationToken.None);
88
+ assert.strictEqual(newSourceFile === null || newSourceFile === void 0 ? void 0 : newSourceFile.getFileContent(), 'import sys');
89
+ assert.strictEqual(newSourceFile.getImports().length, 2);
90
+ // Add a new file.
91
+ state.workspace.service.backgroundAnalysisProgram.program.setFileOpened(addedFilePath, 0, '', {
92
+ isTracked: true,
93
+ ipythonMode: sourceFile_1.IPythonMode.None,
94
+ chainedFilePath: undefined,
95
+ realFilePath: addedFilePath,
96
+ });
97
+ applyWorkspaceEditToService(state.workspace.service, {
98
+ documentChanges: [
99
+ vscode_languageserver_types_1.TextDocumentEdit.create({
100
+ uri: (0, pathUtils_1.convertPathToUri)(state.workspace.service.fs, addedFilePath),
101
+ version: null,
102
+ }, [
103
+ {
104
+ range: state.convertPositionRange(range),
105
+ newText: 'import sys',
106
+ },
107
+ ]),
108
+ ],
109
+ }, fileChanged);
110
+ applyWorkspaceEditToService(state.workspace.service, {
111
+ documentChanges: [
112
+ vscode_languageserver_types_1.TextDocumentEdit.create({
113
+ uri: (0, pathUtils_1.convertPathToUri)(state.workspace.service.fs, addedFilePath),
114
+ version: null,
115
+ }, [
116
+ {
117
+ range: {
118
+ start: { line: 0, character: 7 },
119
+ end: { line: 0, character: 10 },
120
+ },
121
+ newText: 'os',
122
+ },
123
+ ]),
124
+ ],
125
+ }, fileChanged);
126
+ const addedSourceFile = state.workspace.service.test_program.getSourceFile(addedFilePath);
127
+ state.workspace.service.backgroundAnalysisProgram.analyzeFile(addedSourceFile.getFilePath(), vscode_languageserver_1.CancellationToken.None);
128
+ assert.strictEqual(addedSourceFile === null || addedSourceFile === void 0 ? void 0 : addedSourceFile.getFileContent(), 'import os');
129
+ assert.strictEqual(addedSourceFile.getImports().length, 2);
130
+ }, vscode_languageserver_1.CancellationToken.None);
131
+ // After leaving edit mode, we should be back to where we were.
132
+ const oldSourceFile = state.workspace.service.test_program.getSourceFile(range.fileName);
133
+ state.workspace.service.backgroundAnalysisProgram.analyzeFile(oldSourceFile.getFilePath(), vscode_languageserver_1.CancellationToken.None);
134
+ assert.strictEqual(oldSourceFile === null || oldSourceFile === void 0 ? void 0 : oldSourceFile.getFileContent(), '');
135
+ assert.strictEqual(oldSourceFile.getImports().length, 1);
136
+ assert.strictEqual(edits.length, 2);
137
+ assert.deepStrictEqual(edits[0].replacementText, 'import sys');
138
+ assert.deepStrictEqual(edits[1].replacementText, 'import os');
139
+ const addedSourceFile = state.workspace.service.test_program.getSourceFile(addedFilePath);
140
+ // The added file should be there, but be empty.
141
+ assert.ok(addedSourceFile);
142
+ assert.strictEqual(addedSourceFile === null || addedSourceFile === void 0 ? void 0 : addedSourceFile.getFileContent(), '');
143
+ });
60
144
  test('test applyWorkspaceEdits documentChanges', async () => {
61
145
  var _a;
62
146
  const code = `
@@ -67,7 +151,7 @@ test('test applyWorkspaceEdits documentChanges', async () => {
67
151
  const cloned = await getClonedService(state);
68
152
  const range = state.getRangeByMarkerName('marker');
69
153
  const fileChanged = new Set();
70
- (0, workspaceEditUtils_1.applyWorkspaceEdit)(cloned, {
154
+ applyWorkspaceEditToService(cloned, {
71
155
  documentChanges: [
72
156
  vscode_languageserver_types_1.TextDocumentEdit.create({
73
157
  uri: (0, pathUtils_1.convertPathToUri)(cloned.fs, range.fileName),
@@ -95,7 +179,7 @@ test('test generateWorkspaceEdits', async () => {
95
179
  const cloned = await getClonedService(state);
96
180
  const range1 = state.getRangeByMarkerName('marker1');
97
181
  const fileChanged = new Set();
98
- (0, workspaceEditUtils_1.applyWorkspaceEdit)(cloned, {
182
+ applyWorkspaceEditToService(cloned, {
99
183
  changes: {
100
184
  [(0, pathUtils_1.convertPathToUri)(cloned.fs, range1.fileName)]: [
101
185
  {
@@ -105,7 +189,7 @@ test('test generateWorkspaceEdits', async () => {
105
189
  ],
106
190
  },
107
191
  }, fileChanged);
108
- (0, workspaceEditUtils_1.applyWorkspaceEdit)(cloned, {
192
+ applyWorkspaceEditToService(cloned, {
109
193
  documentChanges: [
110
194
  vscode_languageserver_types_1.TextDocumentEdit.create({
111
195
  uri: (0, pathUtils_1.convertPathToUri)(cloned.fs, range1.fileName),
@@ -119,7 +203,7 @@ test('test generateWorkspaceEdits', async () => {
119
203
  ],
120
204
  }, fileChanged);
121
205
  const range2 = state.getRangeByMarkerName('marker2');
122
- (0, workspaceEditUtils_1.applyWorkspaceEdit)(cloned, {
206
+ applyWorkspaceEditToService(cloned, {
123
207
  documentChanges: [
124
208
  vscode_languageserver_types_1.TextDocumentEdit.create({
125
209
  uri: (0, pathUtils_1.convertPathToUri)(cloned.fs, range2.fileName),
@@ -132,7 +216,7 @@ test('test generateWorkspaceEdits', async () => {
132
216
  ]),
133
217
  ],
134
218
  }, fileChanged);
135
- (0, workspaceEditUtils_1.applyWorkspaceEdit)(cloned, {
219
+ applyWorkspaceEditToService(cloned, {
136
220
  changes: {
137
221
  [(0, pathUtils_1.convertPathToUri)(cloned.fs, range2.fileName)]: [
138
222
  {
@@ -161,6 +245,11 @@ test('test generateWorkspaceEdits', async () => {
161
245
  },
162
246
  }, actualEdits);
163
247
  });
248
+ function applyWorkspaceEditToService(service, edits, filesChanged) {
249
+ const view = service.backgroundAnalysisProgram.program;
250
+ const mutator = service;
251
+ (0, workspaceEditUtils_1.applyWorkspaceEdit)(view, mutator, edits, filesChanged);
252
+ }
164
253
  async function getClonedService(state) {
165
254
  return await analyzerServiceExecutor_1.AnalyzerServiceExecutor.cloneService(new testLanguageService_1.TestLanguageService(state.workspace, state.console, state.workspace.service.fs), state.workspace, { useBackgroundAnalysis: false });
166
255
  }
@@ -1 +1 @@
1
- {"version":3,"file":"workspaceEditUtils.test.js","sourceRoot":"","sources":["../../../src/tests/workspaceEditUtils.test.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;;;;;;;;;;;;;;;;;;AAEH,+CAAiC;AACjC,6EAA+D;AAE/D,mDAAuD;AACvD,qEAAyF;AACzF,wFAAqF;AACrF,iFAA8E;AAC9E,6DAAgF;AAChF,uFAAiF;AAEjF,IAAI,CAAC,kCAAkC,EAAE,KAAK,IAAI,EAAE;;IAChD,MAAM,IAAI,GAAG;;;SAGR,CAAC;IAEN,MAAM,KAAK,GAAG,IAAA,gCAAoB,EAAC,IAAI,CAAC,CAAC,KAAK,CAAC;IAC/C,MAAM,MAAM,GAAG,MAAM,gBAAgB,CAAC,KAAK,CAAC,CAAC;IAC7C,MAAM,KAAK,GAAG,KAAK,CAAC,oBAAoB,CAAC,QAAQ,CAAE,CAAC;IAEpD,MAAM,WAAW,GAAG,IAAI,GAAG,EAAU,C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EAAE,CACnC,CAAC;AACN,CAAC"}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@zzzen/pyright-internal",
3
3
  "displayName": "pyright",
4
4
  "description": "Type checker for the Python language",
5
- "version": "1.2.0-dev.20230430",
5
+ "version": "1.2.0-dev.20230514",
6
6
  "license": "MIT",
7
7
  "private": false,
8
8
  "files": [
@@ -16,8 +16,8 @@
16
16
  },
17
17
  "dependencies": {
18
18
  "@iarna/toml": "2.2.5",
19
- "@yarnpkg/fslib": "2.10.1",
20
- "@yarnpkg/libzip": "2.2.4",
19
+ "@yarnpkg/fslib": "2.10.3",
20
+ "@yarnpkg/libzip": "2.3.0",
21
21
  "chalk": "^4.1.2",
22
22
  "chokidar": "^3.5.3",
23
23
  "command-line-args": "^5.2.1",
@@ -28,7 +28,7 @@
28
28
  "typescript-char": "^0.0.0",
29
29
  "vscode-jsonrpc": "8.1.0",
30
30
  "vscode-languageserver": "8.1.0",
31
- "vscode-languageserver-textdocument": "^1.0.9",
31
+ "vscode-languageserver-textdocument": "^1.0.10",
32
32
  "vscode-languageserver-types": "3.17.3",
33
33
  "vscode-uri": "^3.0.7"
34
34
  },
@@ -1,40 +0,0 @@
1
- import { CancellationToken } from 'vscode-languageserver';
2
- import { Declaration } from '../analyzer/declaration';
3
- import { ImportResolver } from '../analyzer/importResolver';
4
- import { ImportNameInfo } from '../analyzer/importStatementUtils';
5
- import { TypeEvaluator } from '../analyzer/typeEvaluatorTypes';
6
- import { ConfigOptions } from '../common/configOptions';
7
- import { TextEditAction } from '../common/editAction';
8
- import { TextEditTracker } from '../common/textEditTracker';
9
- import { TextRange } from '../common/textRange';
10
- import { ExpressionNode, ModuleNode, NameNode } from '../parser/parseNodes';
11
- import { ParseResults } from '../parser/parser';
12
- import { ImportFormat } from './autoImporter';
13
- export interface ImportData {
14
- containsUnreferenceableSymbols: boolean;
15
- declarations: Map<Declaration, NameNode[]>;
16
- importInfos?: {
17
- filePath: string;
18
- nameInfo: ImportNameInfo;
19
- }[];
20
- }
21
- export declare class ImportAdder {
22
- private _configOptions;
23
- private _importResolver;
24
- private _evaluator;
25
- constructor(_configOptions: ConfigOptions, _importResolver: ImportResolver, _evaluator: TypeEvaluator);
26
- collectImportsForSymbolsUsed(root: ParseResults | ModuleNode, ranges: TextRange | TextRange[], token: CancellationToken): ImportData;
27
- addImportInfo(importInfo: {
28
- filePath: string;
29
- nameInfo: ImportNameInfo;
30
- }, importData: ImportData): void;
31
- addDeclaration(declaration: Declaration, node: ExpressionNode, importData: ImportData): boolean;
32
- applyImports(result: ImportData, filePath: string, parseResults: ParseResults, insertionPosition: number, importFormat: ImportFormat, token: CancellationToken): TextEditAction[];
33
- applyImportsTo(result: ImportData, parseResults: ParseResults, importFormat: ImportFormat, textEditTracker: TextEditTracker, token: CancellationToken): void;
34
- private _getImportNameWithModuleInfo;
35
- private _appendImportNameInfo;
36
- private _tryProcessExistingImports;
37
- private _addOrUpdateImport;
38
- private _getImportInfo;
39
- private _areSame;
40
- }
@@ -1,388 +0,0 @@
1
- "use strict";
2
- /*
3
- * importAdder.ts
4
- * Copyright (c) Microsoft Corporation.
5
- * Licensed under the MIT license.
6
- *
7
- * Provides code that figures out imports needed for symbols
8
- * used in the given range and apply them later.
9
- */
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.ImportAdder = void 0;
12
- const analyzerNodeInfo_1 = require("../analyzer/analyzerNodeInfo");
13
- const declaration_1 = require("../analyzer/declaration");
14
- const declarationUtils_1 = require("../analyzer/declarationUtils");
15
- const importStatementUtils_1 = require("../analyzer/importStatementUtils");
16
- const parseTreeUtils_1 = require("../analyzer/parseTreeUtils");
17
- const parseTreeWalker_1 = require("../analyzer/parseTreeWalker");
18
- const scopeUtils_1 = require("../analyzer/scopeUtils");
19
- const cancellationUtils_1 = require("../common/cancellationUtils");
20
- const collectionUtils_1 = require("../common/collectionUtils");
21
- const core_1 = require("../common/core");
22
- const pathUtils_1 = require("../common/pathUtils");
23
- const positionUtils_1 = require("../common/positionUtils");
24
- const textRange_1 = require("../common/textRange");
25
- class ImportAdder {
26
- constructor(_configOptions, _importResolver, _evaluator) {
27
- this._configOptions = _configOptions;
28
- this._importResolver = _importResolver;
29
- this._evaluator = _evaluator;
30
- }
31
- collectImportsForSymbolsUsed(root, ranges, token) {
32
- root = isParseResults(root) ? root.parseTree : root;
33
- ranges = (0, core_1.isArray)(ranges) ? ranges : [ranges];
34
- const collector = new NameCollector(this._evaluator, root, ranges, token);
35
- collector.walk(root);
36
- return {
37
- containsUnreferenceableSymbols: collector.containsUnreferenceableSymbols,
38
- declarations: collector.declsForSymbols,
39
- };
40
- }
41
- addImportInfo(importInfo, importData) {
42
- var _a;
43
- importData.importInfos = (_a = importData.importInfos) !== null && _a !== void 0 ? _a : [];
44
- importData.importInfos.push(importInfo);
45
- }
46
- addDeclaration(declaration, node, importData) {
47
- // We don't need import statement if decl is from builtins or synthesized.
48
- if (declaration.moduleName === 'builtins' || declaration.moduleName === '') {
49
- return false;
50
- }
51
- const name = node.nodeType === 38 /* Name */
52
- ? node
53
- : node.nodeType === 35 /* MemberAccess */
54
- ? node.memberName
55
- : undefined;
56
- if (!name) {
57
- return false;
58
- }
59
- (0, collectionUtils_1.getOrAdd)(importData.declarations, declaration, () => []).push(name);
60
- return true;
61
- }
62
- applyImports(result, filePath, parseResults, insertionPosition, importFormat, token) {
63
- (0, cancellationUtils_1.throwIfCancellationRequested)(token);
64
- const importStatements = (0, importStatementUtils_1.getTopLevelImports)(parseResults.parseTree);
65
- const importNameInfo = this._getImportNameWithModuleInfo(filePath, result, importFormat);
66
- const edits = [];
67
- const newNameInfo = [];
68
- for (const moduleAndInfo of (0, collectionUtils_1.createMapFromItems)(importNameInfo, (i) => i.module.moduleName)) {
69
- if (!this._tryProcessExistingImports(moduleAndInfo, importStatements, parseResults, edits)) {
70
- (0, collectionUtils_1.appendArray)(newNameInfo, moduleAndInfo[1]);
71
- continue;
72
- }
73
- }
74
- edits.push(...(0, importStatementUtils_1.getTextEditsForAutoImportInsertions)(newNameInfo, importStatements, parseResults, (0, positionUtils_1.convertOffsetToPosition)(insertionPosition, parseResults.tokenizerOutput.lines)));
75
- return edits;
76
- }
77
- applyImportsTo(result, parseResults, importFormat, textEditTracker, token) {
78
- (0, cancellationUtils_1.throwIfCancellationRequested)(token);
79
- const filePath = (0, analyzerNodeInfo_1.getFileInfo)(parseResults.parseTree).filePath;
80
- const importStatements = (0, importStatementUtils_1.getTopLevelImports)(parseResults.parseTree);
81
- const importNameInfo = this._getImportNameWithModuleInfo(filePath, result, importFormat);
82
- const newNameInfo = [];
83
- for (const moduleAndInfo of (0, collectionUtils_1.createMapFromItems)(importNameInfo, (i) => i.module.moduleName)) {
84
- if (!this._tryProcessExistingImports(moduleAndInfo, importStatements, parseResults, textEditTracker)) {
85
- (0, collectionUtils_1.appendArray)(newNameInfo, moduleAndInfo[1]);
86
- continue;
87
- }
88
- }
89
- for (const moduleAndInfo of (0, collectionUtils_1.createMapFromItems)(newNameInfo, (i) => i.module.moduleName)) {
90
- this._addOrUpdateImport(moduleAndInfo, importStatements, parseResults, moduleAndInfo[1], textEditTracker);
91
- }
92
- }
93
- _getImportNameWithModuleInfo(filePath, result, importFormat) {
94
- var _a;
95
- const importNameInfo = [];
96
- const execEnv = this._configOptions.findExecEnvironment(filePath);
97
- for (const decl of (_a = result.declarations.keys()) !== null && _a !== void 0 ? _a : []) {
98
- const importInfo = this._getImportInfo(decl, filePath);
99
- if (!importInfo || (0, declaration_1.isUnresolvedAliasDeclaration)(decl)) {
100
- continue;
101
- }
102
- this._appendImportNameInfo(filePath, execEnv, importFormat, importInfo, importNameInfo);
103
- }
104
- if (result.importInfos) {
105
- for (const importInfo of result.importInfos) {
106
- this._appendImportNameInfo(filePath, execEnv, importFormat, importInfo, importNameInfo);
107
- }
108
- }
109
- return importNameInfo;
110
- }
111
- _appendImportNameInfo(filePath, execEnv, importFormat, importInfo, importNameInfo) {
112
- const relativePath = (0, importStatementUtils_1.getRelativeModuleName)(this._importResolver.fileSystem, filePath, importInfo.filePath);
113
- const moduleAndType = this._importResolver.getModuleNameForImport(importInfo.filePath, execEnv);
114
- if (!moduleAndType.moduleName) {
115
- if (!importInfo.nameInfo.name) {
116
- return;
117
- }
118
- // module can't be addressed by absolute path in "from import" statement.
119
- // ex) namespace package at [workspace root] or [workspace root]\__init__.py(i)
120
- // use relative path
121
- importFormat = "relative" /* Relative */;
122
- }
123
- (0, collectionUtils_1.addIfUnique)(importNameInfo, {
124
- name: importInfo.nameInfo.name,
125
- alias: importInfo.nameInfo.alias,
126
- module: moduleAndType,
127
- nameForImportFrom: importFormat === "relative" /* Relative */ ? relativePath : undefined,
128
- }, (a, b) => this._areSame(a, b));
129
- }
130
- _tryProcessExistingImports(moduleAndInfo, importStatements, parseResults, edits) {
131
- for (const kindAndImports of (0, collectionUtils_1.createMapFromItems)(importStatements.orderedImports.filter((i) => i.moduleName === moduleAndInfo[0]), (i) => (i.node.nodeType === 20 /* Import */ ? 'import' : 'importFrom'))) {
132
- if (kindAndImports[0] === 'importFrom') {
133
- // We can't merge to "from module import *" statement.
134
- const imported = kindAndImports[1].filter((i) => i.node.nodeType === 22 /* ImportFrom */ && !i.node.isWildcardImport);
135
- if (imported.length === 0) {
136
- // No regular from import statement.
137
- continue;
138
- }
139
- // get name info that don't exist in any of existing import statements.
140
- const info = moduleAndInfo[1].filter((m) => !imported.some((n) => n.node.nodeType === 22 /* ImportFrom */ &&
141
- n.node.imports.some((i) => { var _a; return i.name.value === m.name && ((_a = i.alias) === null || _a === void 0 ? void 0 : _a.value) === m.alias; })));
142
- if ((0, core_1.isArray)(edits)) {
143
- (0, collectionUtils_1.appendArray)(edits, (0, importStatementUtils_1.getTextEditsForAutoImportSymbolAddition)(info, imported[0], parseResults));
144
- }
145
- else {
146
- this._addOrUpdateImport(moduleAndInfo, importStatements, parseResults, info, edits);
147
- }
148
- return true;
149
- }
150
- if (kindAndImports[0] === 'import') {
151
- // import statement already exists. skip those module info.
152
- (0, collectionUtils_1.removeArrayElements)(moduleAndInfo[1], (i) => !i.name && kindAndImports[1].some((n) => { var _a, _b; return i.alias === ((_b = (_a = n.subnode) === null || _a === void 0 ? void 0 : _a.alias) === null || _b === void 0 ? void 0 : _b.value); }));
153
- continue;
154
- }
155
- }
156
- return false;
157
- }
158
- _addOrUpdateImport(moduleAndInfo, importStatements, parseResults, info, editTracker) {
159
- if (info.length === 0) {
160
- return;
161
- }
162
- const name = moduleAndInfo[0];
163
- const nameForImportFrom = moduleAndInfo[1].length === 0 ? undefined : moduleAndInfo[1][0].nameForImportFrom;
164
- const importGroup = moduleAndInfo[1].length === 0
165
- ? 2 /* Local */
166
- : (0, importStatementUtils_1.getImportGroupFromModuleNameAndType)(moduleAndInfo[1][0].module);
167
- editTracker.addOrUpdateImport(parseResults, importStatements, { name, nameForImportFrom }, importGroup, info);
168
- }
169
- _getImportInfo(decl, destFilePath) {
170
- var _a, _b;
171
- if ((0, declaration_1.isAliasDeclaration)(decl)) {
172
- if (!decl.node) {
173
- // This is synthesized decl for implicit module case such as "import a.b"
174
- return { filePath: decl.path, nameInfo: {} };
175
- }
176
- if (decl.node.nodeType === 21 /* ImportAs */) {
177
- const importDecl = this._evaluator.getDeclarationsForNameNode(decl.node.module.nameParts[decl.node.module.nameParts.length - 1]);
178
- if (!importDecl || importDecl.length === 0) {
179
- // We have no idea where it came from.
180
- // ex) from unknown import unknown
181
- return undefined;
182
- }
183
- return {
184
- filePath: importDecl[0].path,
185
- nameInfo: { alias: decl.usesLocalName ? (_a = decl.node.alias) === null || _a === void 0 ? void 0 : _a.value : undefined },
186
- };
187
- }
188
- if (decl.node.nodeType === 23 /* ImportFromAs */) {
189
- let path = decl.path;
190
- if (!path) {
191
- // Check submodule case with no __init__
192
- if (decl.submoduleFallback) {
193
- path = (0, pathUtils_1.getDirectoryPath)(decl.submoduleFallback.path);
194
- }
195
- }
196
- if (!path) {
197
- // We have no idea where it came from.
198
- // ex) from unknown import unknown
199
- return undefined;
200
- }
201
- if (path === destFilePath && !decl.usesLocalName && !decl.submoduleFallback) {
202
- // Don't create import for the symbol (not module) defined in the current file
203
- // unless alias is used.
204
- //
205
- // We don't check insertion point since we don't create type alias for decl defined later
206
- // anyway. but in future, we could consider either rewrite or creating type alias for symbols
207
- // defined after insertion point.
208
- return undefined;
209
- }
210
- return {
211
- filePath: path,
212
- nameInfo: {
213
- name: decl.symbolName,
214
- alias: decl.usesLocalName ? (_b = decl.node.alias) === null || _b === void 0 ? void 0 : _b.value : undefined,
215
- },
216
- };
217
- }
218
- if (decl.node.nodeType === 22 /* ImportFrom */) {
219
- return {
220
- filePath: decl.path,
221
- nameInfo: { name: decl.symbolName },
222
- };
223
- }
224
- }
225
- if ((0, declaration_1.isVariableDeclaration)(decl) || (0, declaration_1.isFunctionDeclaration)(decl) || (0, declaration_1.isClassDeclaration)(decl)) {
226
- const name = (0, declarationUtils_1.getNameFromDeclaration)(decl);
227
- if (!name) {
228
- return undefined;
229
- }
230
- return {
231
- filePath: decl.path,
232
- nameInfo: { name },
233
- };
234
- }
235
- return undefined;
236
- }
237
- _areSame(a, b) {
238
- return (a.alias === b.alias &&
239
- a.name === b.name &&
240
- a.module.importType === b.module.importType &&
241
- a.module.isLocalTypingsFile === b.module.isLocalTypingsFile &&
242
- a.module.moduleName === b.module.moduleName);
243
- }
244
- }
245
- exports.ImportAdder = ImportAdder;
246
- class NameCollector extends parseTreeWalker_1.ParseTreeWalker {
247
- constructor(_evaluator, _root, _ranges, _token) {
248
- super();
249
- this._evaluator = _evaluator;
250
- this._root = _root;
251
- this._ranges = _ranges;
252
- this._token = _token;
253
- // Hold onto names that we need to move imports.
254
- this.declsForSymbols = new Map();
255
- this.containsUnreferenceableSymbols = false;
256
- this._filePath = (0, analyzerNodeInfo_1.getFileInfo)(this._root).filePath;
257
- // For now, we assume the given range is at right boundary such as statement, statements, expression or expressions.
258
- // In future, we might consider validating the range and adjusting it to the right boundary if needed.
259
- }
260
- walk(node) {
261
- if (!this._ranges.some((r) => textRange_1.TextRange.overlapsRange(r, node))) {
262
- return;
263
- }
264
- super.walk(node);
265
- }
266
- visitModuleName(node) {
267
- // We only care about references to module symbols. not decls.
268
- return false;
269
- }
270
- visitName(name) {
271
- if (!this._ranges.some((r) => textRange_1.TextRange.containsRange(r, name))) {
272
- return false;
273
- }
274
- (0, cancellationUtils_1.throwIfCancellationRequested)(this._token);
275
- // We process dotted name as a whole rather than
276
- // process each part of dotted name.
277
- if (!(0, parseTreeUtils_1.isLastNameOfDottedName)(name)) {
278
- return false;
279
- }
280
- const type = this._evaluator.getType(name);
281
- if ((type === null || type === void 0 ? void 0 : type.category) === 10 /* TypeVar */) {
282
- // Currently, we don't add import statement for type variables
283
- // such as TypeVar, TypeVarTuple, ParamSpec, etc.
284
- return false;
285
- }
286
- const dottedName = (0, parseTreeUtils_1.getDottedName)((0, parseTreeUtils_1.getDottedNameWithGivenNodeAsLastName)(name));
287
- if (!dottedName) {
288
- // Not dotted name
289
- // ex) foo().[var]
290
- return false;
291
- }
292
- // See whether the first dotted name bound to symbols defined in current file.
293
- const firstName = dottedName[0];
294
- const firstNameDecls = this._getDeclarationsInModule(firstName);
295
- if (!firstNameDecls || firstNameDecls.length === 0) {
296
- return false;
297
- }
298
- // Simple case.
299
- // ex) import os
300
- // [os]
301
- if (dottedName.length === 1) {
302
- this._handleName(firstName, firstNameDecls);
303
- return false;
304
- }
305
- for (const firstNameDecl of firstNameDecls) {
306
- if (!(0, declaration_1.isAliasDeclaration)(firstNameDecl) || firstNameDecl.node.nodeType !== 21 /* ImportAs */) {
307
- // decls we have is for symbols defined in current module.
308
- // ex) [foo]()
309
- this._handleName(firstName, [firstNameDecl]);
310
- continue;
311
- }
312
- // Import with alias
313
- // ex) import json.encoder as j
314
- if (firstNameDecl.usesLocalName) {
315
- this._handleName(firstName, [firstNameDecl]);
316
- continue;
317
- }
318
- // Special casing import statement with sub module ex) import a.[b]
319
- // It is complex for import a.[b] case since decl for [b] doesn't exist. so
320
- // when binding a.[b].foo(), we don't get decl for "import a.[b]", we need to
321
- // do some tree walk to find import a.[b] and synthesize decl for it.
322
- this._handleImplicitImports(firstNameDecl, dottedName, 1);
323
- }
324
- return false;
325
- }
326
- _getDeclarationsInModule(name) {
327
- var _a;
328
- return (_a = this._evaluator.getDeclarationsForNameNode(name)) === null || _a === void 0 ? void 0 : _a.filter((d) => (0, declarationUtils_1.isDefinedInFile)(d, this._filePath));
329
- }
330
- _handleImplicitImports(aliasDecl, dottedName, nameIndex) {
331
- if (dottedName.length === nameIndex) {
332
- return;
333
- }
334
- if (!aliasDecl.implicitImports) {
335
- this._handleName(dottedName[nameIndex - 1], [(0, declarationUtils_1.createSynthesizedAliasDeclaration)(aliasDecl.path)]);
336
- return;
337
- }
338
- const implicitImportDecl = aliasDecl.implicitImports.get(dottedName[nameIndex].value);
339
- if (!implicitImportDecl) {
340
- this._handleName(dottedName[nameIndex - 1], [(0, declarationUtils_1.createSynthesizedAliasDeclaration)(aliasDecl.path)]);
341
- return;
342
- }
343
- this._handleImplicitImports(implicitImportDecl, dottedName, nameIndex + 1);
344
- }
345
- _handleName(name, decls) {
346
- for (const decl of decls) {
347
- if (decl.node && this._ranges.some((r) => textRange_1.TextRange.containsRange(r, decl.node))) {
348
- // Make sure our range doesn't already contain them.
349
- continue;
350
- }
351
- if ((0, declaration_1.isParameterDeclaration)(decl)) {
352
- // Parameter is not referenceable from import statement.
353
- this.containsUnreferenceableSymbols = true;
354
- continue;
355
- }
356
- if ((0, declaration_1.isVariableDeclaration)(decl) || (0, declaration_1.isFunctionDeclaration)(decl) || (0, declaration_1.isClassDeclaration)(decl)) {
357
- // For now, we will allow private variable to be referenced by import
358
- // so that user can fix it up once import is added.
359
- // We only support top level variables.
360
- const scope = (0, scopeUtils_1.getScopeForNode)(name);
361
- if (!scope) {
362
- this.containsUnreferenceableSymbols = true;
363
- continue;
364
- }
365
- const result = scope.lookUpSymbolRecursive(name.value);
366
- if (!result || result.scope.type !== 3 /* Module */) {
367
- this.containsUnreferenceableSymbols = true;
368
- continue;
369
- }
370
- }
371
- this._addName(decl, name);
372
- }
373
- }
374
- _addName(decl, name) {
375
- (0, collectionUtils_1.getOrAdd)(this.declsForSymbols, decl, () => []).push(name);
376
- }
377
- }
378
- function isParseResults(obj) {
379
- return (obj &&
380
- obj.text !== undefined &&
381
- obj.parseTree &&
382
- obj.importedModules &&
383
- obj.futureImports &&
384
- obj.tokenizerOutput &&
385
- obj.containsWildcardImport !== undefined &&
386
- obj.typingSymbolAliases);
387
- }
388
- //# sourceMappingURL=importAdder.js.map