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

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 (210) hide show
  1. package/dist/analyzer/analyzerFileInfo.d.ts +1 -0
  2. package/dist/analyzer/analyzerFileInfo.js +4 -3
  3. package/dist/analyzer/analyzerFileInfo.js.map +1 -1
  4. package/dist/analyzer/backgroundAnalysisProgram.d.ts +17 -15
  5. package/dist/analyzer/backgroundAnalysisProgram.js +43 -53
  6. package/dist/analyzer/backgroundAnalysisProgram.js.map +1 -1
  7. package/dist/analyzer/binder.d.ts +0 -2
  8. package/dist/analyzer/binder.js +2 -20
  9. package/dist/analyzer/binder.js.map +1 -1
  10. package/dist/analyzer/checker.d.ts +1 -1
  11. package/dist/analyzer/checker.js +97 -29
  12. package/dist/analyzer/checker.js.map +1 -1
  13. package/dist/analyzer/constraintSolver.js +14 -15
  14. package/dist/analyzer/constraintSolver.js.map +1 -1
  15. package/dist/analyzer/constructorTransform.js +5 -1
  16. package/dist/analyzer/constructorTransform.js.map +1 -1
  17. package/dist/analyzer/constructors.js +248 -189
  18. package/dist/analyzer/constructors.js.map +1 -1
  19. package/dist/analyzer/dataClasses.js +5 -2
  20. package/dist/analyzer/dataClasses.js.map +1 -1
  21. package/dist/analyzer/declarationUtils.js +1 -0
  22. package/dist/analyzer/declarationUtils.js.map +1 -1
  23. package/dist/analyzer/docStringConversion.js +1 -1
  24. package/dist/analyzer/docStringConversion.js.map +1 -1
  25. package/dist/analyzer/enums.js +8 -0
  26. package/dist/analyzer/enums.js.map +1 -1
  27. package/dist/analyzer/importResolver.d.ts +4 -4
  28. package/dist/analyzer/importResolver.js +93 -69
  29. package/dist/analyzer/importResolver.js.map +1 -1
  30. package/dist/analyzer/importResult.d.ts +2 -2
  31. package/dist/analyzer/importStatementUtils.js +2 -2
  32. package/dist/analyzer/importStatementUtils.js.map +1 -1
  33. package/dist/analyzer/namedTuples.js +2 -5
  34. package/dist/analyzer/namedTuples.js.map +1 -1
  35. package/dist/analyzer/packageTypeVerifier.js +1 -1
  36. package/dist/analyzer/packageTypeVerifier.js.map +1 -1
  37. package/dist/analyzer/parseTreeUtils.js +2 -34
  38. package/dist/analyzer/parseTreeUtils.js.map +1 -1
  39. package/dist/analyzer/parseTreeWalker.js +2 -2
  40. package/dist/analyzer/parseTreeWalker.js.map +1 -1
  41. package/dist/analyzer/patternMatching.js +1 -0
  42. package/dist/analyzer/patternMatching.js.map +1 -1
  43. package/dist/analyzer/program.d.ts +18 -34
  44. package/dist/analyzer/program.js +57 -259
  45. package/dist/analyzer/program.js.map +1 -1
  46. package/dist/analyzer/protocols.js +4 -2
  47. package/dist/analyzer/protocols.js.map +1 -1
  48. package/dist/analyzer/service.d.ts +8 -16
  49. package/dist/analyzer/service.js +33 -47
  50. package/dist/analyzer/service.js.map +1 -1
  51. package/dist/analyzer/sourceFile.d.ts +1 -15
  52. package/dist/analyzer/sourceFile.js +14 -96
  53. package/dist/analyzer/sourceFile.js.map +1 -1
  54. package/dist/analyzer/sourceMapper.js +1 -1
  55. package/dist/analyzer/sourceMapper.js.map +1 -1
  56. package/dist/analyzer/symbol.d.ts +3 -1
  57. package/dist/analyzer/symbol.js +5 -0
  58. package/dist/analyzer/symbol.js.map +1 -1
  59. package/dist/analyzer/typeDocStringUtils.js +1 -1
  60. package/dist/analyzer/typeDocStringUtils.js.map +1 -1
  61. package/dist/analyzer/typeEvaluator.d.ts +2 -2
  62. package/dist/analyzer/typeEvaluator.js +495 -196
  63. package/dist/analyzer/typeEvaluator.js.map +1 -1
  64. package/dist/analyzer/typeEvaluatorTypes.d.ts +7 -2
  65. package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
  66. package/dist/analyzer/typeGuards.js +1 -0
  67. package/dist/analyzer/typeGuards.js.map +1 -1
  68. package/dist/analyzer/typePrinter.d.ts +3 -3
  69. package/dist/analyzer/typePrinter.js +255 -101
  70. package/dist/analyzer/typePrinter.js.map +1 -1
  71. package/dist/analyzer/typeUtils.d.ts +12 -7
  72. package/dist/analyzer/typeUtils.js +174 -49
  73. package/dist/analyzer/typeUtils.js.map +1 -1
  74. package/dist/analyzer/typeVarContext.d.ts +1 -2
  75. package/dist/analyzer/typeVarContext.js +16 -34
  76. package/dist/analyzer/typeVarContext.js.map +1 -1
  77. package/dist/analyzer/typedDicts.js +138 -41
  78. package/dist/analyzer/typedDicts.js.map +1 -1
  79. package/dist/analyzer/types.d.ts +10 -3
  80. package/dist/analyzer/types.js +32 -16
  81. package/dist/analyzer/types.js.map +1 -1
  82. package/dist/backgroundAnalysisBase.d.ts +25 -19
  83. package/dist/backgroundAnalysisBase.js +161 -115
  84. package/dist/backgroundAnalysisBase.js.map +1 -1
  85. package/dist/backgroundThreadBase.d.ts +1 -1
  86. package/dist/backgroundThreadBase.js +1 -1
  87. package/dist/backgroundThreadBase.js.map +1 -1
  88. package/dist/commands/dumpFileDebugInfoCommand.js +3 -4
  89. package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
  90. package/dist/common/configOptions.js +1 -1
  91. package/dist/common/configOptions.js.map +1 -1
  92. package/dist/common/extensibility.d.ts +26 -5
  93. package/dist/common/extensibility.js.map +1 -1
  94. package/dist/common/logTracker.d.ts +2 -0
  95. package/dist/common/logTracker.js +8 -1
  96. package/dist/common/logTracker.js.map +1 -1
  97. package/dist/common/lspUtils.d.ts +4 -1
  98. package/dist/common/lspUtils.js +38 -1
  99. package/dist/common/lspUtils.js.map +1 -1
  100. package/dist/common/pythonVersion.d.ts +2 -1
  101. package/dist/common/pythonVersion.js +1 -0
  102. package/dist/common/pythonVersion.js.map +1 -1
  103. package/dist/common/textRange.js +1 -1
  104. package/dist/common/textRange.js.map +1 -1
  105. package/dist/common/workspaceEditUtils.d.ts +3 -3
  106. package/dist/common/workspaceEditUtils.js +15 -17
  107. package/dist/common/workspaceEditUtils.js.map +1 -1
  108. package/dist/languageServerBase.d.ts +2 -5
  109. package/dist/languageServerBase.js +35 -62
  110. package/dist/languageServerBase.js.map +1 -1
  111. package/dist/languageService/autoImporter.d.ts +51 -52
  112. package/dist/languageService/autoImporter.js +126 -211
  113. package/dist/languageService/autoImporter.js.map +1 -1
  114. package/dist/languageService/callHierarchyProvider.js +8 -33
  115. package/dist/languageService/callHierarchyProvider.js.map +1 -1
  116. package/dist/languageService/completionProvider.d.ts +42 -81
  117. package/dist/languageService/completionProvider.js +608 -841
  118. package/dist/languageService/completionProvider.js.map +1 -1
  119. package/dist/languageService/documentSymbolCollector.d.ts +2 -2
  120. package/dist/languageService/documentSymbolCollector.js +40 -30
  121. package/dist/languageService/documentSymbolCollector.js.map +1 -1
  122. package/dist/languageService/documentSymbolProvider.d.ts +13 -35
  123. package/dist/languageService/documentSymbolProvider.js +52 -264
  124. package/dist/languageService/documentSymbolProvider.js.map +1 -1
  125. package/dist/languageService/hoverProvider.d.ts +1 -3
  126. package/dist/languageService/hoverProvider.js +11 -97
  127. package/dist/languageService/hoverProvider.js.map +1 -1
  128. package/dist/languageService/referencesProvider.d.ts +3 -3
  129. package/dist/languageService/referencesProvider.js +6 -8
  130. package/dist/languageService/referencesProvider.js.map +1 -1
  131. package/dist/languageService/renameProvider.d.ts +0 -1
  132. package/dist/languageService/renameProvider.js +2 -6
  133. package/dist/languageService/renameProvider.js.map +1 -1
  134. package/dist/languageService/signatureHelpProvider.js +1 -1
  135. package/dist/languageService/signatureHelpProvider.js.map +1 -1
  136. package/dist/languageService/symbolIndexer.d.ts +23 -0
  137. package/dist/languageService/symbolIndexer.js +105 -0
  138. package/dist/languageService/symbolIndexer.js.map +1 -0
  139. package/dist/languageService/tooltipUtils.d.ts +8 -1
  140. package/dist/languageService/tooltipUtils.js +102 -1
  141. package/dist/languageService/tooltipUtils.js.map +1 -1
  142. package/dist/languageService/workspaceSymbolProvider.d.ts +17 -0
  143. package/dist/languageService/workspaceSymbolProvider.js +133 -0
  144. package/dist/languageService/workspaceSymbolProvider.js.map +1 -0
  145. package/dist/localization/localize.d.ts +38 -4
  146. package/dist/localization/localize.js +21 -4
  147. package/dist/localization/localize.js.map +1 -1
  148. package/dist/localization/package.nls.en-us.json +23 -6
  149. package/dist/parser/parseNodes.d.ts +8 -8
  150. package/dist/parser/parseNodes.js +20 -10
  151. package/dist/parser/parseNodes.js.map +1 -1
  152. package/dist/parser/parser.d.ts +3 -3
  153. package/dist/parser/parser.js +136 -159
  154. package/dist/parser/parser.js.map +1 -1
  155. package/dist/parser/stringTokenUtils.d.ts +3 -13
  156. package/dist/parser/stringTokenUtils.js +8 -181
  157. package/dist/parser/stringTokenUtils.js.map +1 -1
  158. package/dist/parser/tokenizer.d.ts +3 -0
  159. package/dist/parser/tokenizer.js +211 -24
  160. package/dist/parser/tokenizer.js.map +1 -1
  161. package/dist/parser/tokenizerTypes.d.ts +31 -1
  162. package/dist/parser/tokenizerTypes.js +51 -1
  163. package/dist/parser/tokenizerTypes.js.map +1 -1
  164. package/dist/pyright.js +26 -4
  165. package/dist/pyright.js.map +1 -1
  166. package/dist/readonlyAugmentedFileSystem.js +1 -1
  167. package/dist/readonlyAugmentedFileSystem.js.map +1 -1
  168. package/dist/tests/chainedSourceFiles.test.js +15 -20
  169. package/dist/tests/chainedSourceFiles.test.js.map +1 -1
  170. package/dist/tests/checker.test.js +14 -0
  171. package/dist/tests/checker.test.js.map +1 -1
  172. package/dist/tests/completions.test.js +11 -236
  173. package/dist/tests/completions.test.js.map +1 -1
  174. package/dist/tests/docStringConversion.test.js +36 -2
  175. package/dist/tests/docStringConversion.test.js.map +1 -1
  176. package/dist/tests/fourslash/completions.override2.fourslash.js +1 -16
  177. package/dist/tests/fourslash/completions.override2.fourslash.js.map +1 -1
  178. package/dist/tests/harness/fourslash/testLanguageService.js +1 -1
  179. package/dist/tests/harness/fourslash/testLanguageService.js.map +1 -1
  180. package/dist/tests/harness/fourslash/testState.d.ts +14 -8
  181. package/dist/tests/harness/fourslash/testState.js +27 -37
  182. package/dist/tests/harness/fourslash/testState.js.map +1 -1
  183. package/dist/tests/importResolver.test.js +84 -4
  184. package/dist/tests/importResolver.test.js.map +1 -1
  185. package/dist/tests/textRange.test.js +45 -0
  186. package/dist/tests/textRange.test.js.map +1 -0
  187. package/dist/tests/tokenizer.test.js +272 -58
  188. package/dist/tests/tokenizer.test.js.map +1 -1
  189. package/dist/tests/typeEvaluator2.test.js +16 -0
  190. package/dist/tests/typeEvaluator2.test.js.map +1 -1
  191. package/dist/tests/typeEvaluator3.test.js +14 -0
  192. package/dist/tests/typeEvaluator3.test.js.map +1 -1
  193. package/dist/tests/typeEvaluator4.test.js +7 -2
  194. package/dist/tests/typeEvaluator4.test.js.map +1 -1
  195. package/dist/tests/typeEvaluator5.test.js +29 -9
  196. package/dist/tests/typeEvaluator5.test.js.map +1 -1
  197. package/dist/tests/workspaceEditUtils.test.js +15 -10
  198. package/dist/tests/workspaceEditUtils.test.js.map +1 -1
  199. package/dist/workspaceFactory.js +3 -5
  200. package/dist/workspaceFactory.js.map +1 -1
  201. package/package.json +1 -1
  202. package/dist/languageService/importAdder.d.ts +0 -40
  203. package/dist/languageService/importAdder.js +0 -388
  204. package/dist/languageService/importAdder.js.map +0 -1
  205. package/dist/tests/fourslash/completions.commitChars.fourslash.d.ts +0 -1
  206. package/dist/tests/fourslash/completions.commitChars.fourslash.js +0 -81
  207. package/dist/tests/fourslash/completions.commitChars.fourslash.js.map +0 -1
  208. package/dist/tests/importAdder.test.js +0 -1325
  209. package/dist/tests/importAdder.test.js.map +0 -1
  210. /package/dist/tests/{importAdder.test.d.ts → textRange.test.d.ts} +0 -0
@@ -1,15 +1,12 @@
1
- import { CancellationToken, CompletionItem, DocumentSymbol } from 'vscode-languageserver';
2
- import { ConfigOptions, ExecutionEnvironment } from '../common/configOptions';
1
+ import { CancellationToken } from 'vscode-languageserver';
2
+ import { ConfigOptions } from '../common/configOptions';
3
3
  import { ConsoleInterface } from '../common/console';
4
4
  import { Diagnostic } from '../common/diagnostic';
5
5
  import { FileDiagnostics } from '../common/diagnosticSink';
6
6
  import { FileEditAction } from '../common/editAction';
7
- import { ProgramView } from '../common/extensibility';
7
+ import { ProgramMutator, ProgramView } from '../common/extensibility';
8
8
  import { LogTracker } from '../common/logTracker';
9
- import { Position, Range } from '../common/textRange';
10
- import { AutoImportOptions, AutoImportResult } from '../languageService/autoImporter';
11
- import { AbbreviationMap, CompletionOptions, CompletionResultsList } from '../languageService/completionProvider';
12
- import { IndexOptions, IndexResults, WorkspaceSymbolCallback } from '../languageService/documentSymbolProvider';
9
+ import { Range } from '../common/textRange';
13
10
  import { ParseResults } from '../parser/parser';
14
11
  import { CacheManager } from './cacheManager';
15
12
  import { ImportResolver } from './importResolver';
@@ -18,7 +15,6 @@ import { SourceMapper } from './sourceMapper';
18
15
  import { Symbol } from './symbol';
19
16
  import { PrintTypeOptions, TypeEvaluator } from './typeEvaluatorTypes';
20
17
  import { Type } from './types';
21
- export declare const MaxWorkspaceIndexFileCount = 2000;
22
18
  export interface SourceFileInfo {
23
19
  sourceFile: SourceFile;
24
20
  isTypeshedFile: boolean;
@@ -40,10 +36,6 @@ export interface MaxAnalysisTime {
40
36
  openFilesTimeInMs: number;
41
37
  noOpenFilesTimeInMs: number;
42
38
  }
43
- export interface Indices {
44
- setWorkspaceIndex(path: string, indexResults: IndexResults): void;
45
- getIndex(execEnv: string | undefined): Map<string, IndexResults> | undefined;
46
- }
47
39
  export declare type PreCheckCallback = (parseResults: ParseResults, evaluator: TypeEvaluator) => void;
48
40
  export interface OpenFileOptions {
49
41
  isTracked: boolean;
@@ -53,22 +45,22 @@ export interface OpenFileOptions {
53
45
  }
54
46
  export declare class Program {
55
47
  private _disableChecker?;
56
- private _console;
57
- private _sourceFileList;
58
- private _sourceFileMap;
48
+ private static _nextId;
49
+ private readonly _console;
50
+ private readonly _sourceFileList;
51
+ private readonly _sourceFileMap;
52
+ private readonly _logTracker;
53
+ private readonly _cacheManager;
54
+ private readonly _id;
59
55
  private _allowedThirdPartyImports;
60
- private _evaluator;
61
56
  private _configOptions;
62
57
  private _importResolver;
63
- private _logTracker;
58
+ private _evaluator;
64
59
  private _parsedFileCount;
65
60
  private _preCheckCallback;
66
- private _cacheManager;
67
- private _id;
68
- private static _nextId;
69
61
  private _isEditMode;
70
- constructor(initialImportResolver: ImportResolver, initialConfigOptions: ConfigOptions, console?: ConsoleInterface, logTracker?: LogTracker, _disableChecker?: boolean | undefined, cacheManager?: CacheManager);
71
- get id(): number;
62
+ constructor(initialImportResolver: ImportResolver, initialConfigOptions: ConfigOptions, console?: ConsoleInterface, logTracker?: LogTracker, _disableChecker?: boolean | undefined, cacheManager?: CacheManager, id?: string);
63
+ get id(): string;
72
64
  get console(): ConsoleInterface;
73
65
  get rootPath(): string;
74
66
  get evaluator(): TypeEvaluator | undefined;
@@ -90,8 +82,8 @@ export declare class Program {
90
82
  getChainedFilePath(filePath: string): string | undefined;
91
83
  updateChainedFilePath(filePath: string, chainedFilePath: string | undefined): void;
92
84
  setFileClosed(filePath: string, isTracked?: boolean): FileDiagnostics[];
93
- markAllFilesDirty(evenIfContentsAreSame: boolean, indexingNeeded?: boolean): void;
94
- markFilesDirty(filePaths: string[], evenIfContentsAreSame: boolean, indexingNeeded?: boolean): void;
85
+ markAllFilesDirty(evenIfContentsAreSame: boolean): void;
86
+ markFilesDirty(filePaths: string[], evenIfContentsAreSame: boolean): void;
95
87
  getFileCount(userFileOnly?: boolean): number;
96
88
  getUserFileCount(): number;
97
89
  getUserFiles(): SourceFileInfo[];
@@ -103,13 +95,13 @@ export declare class Program {
103
95
  owns(filePath: string): boolean;
104
96
  getSourceFile(filePath: string): SourceFile | undefined;
105
97
  getBoundSourceFile(filePath: string): SourceFile | undefined;
106
- getSourceFileInfoList(): SourceFileInfo[];
98
+ getSourceFileInfoList(): readonly SourceFileInfo[];
107
99
  getSourceFileInfo(filePath: string): SourceFileInfo | undefined;
108
100
  getBoundSourceFileInfo(filePath: string, content?: string, force?: boolean): SourceFileInfo | undefined;
109
101
  analyze(maxTime?: MaxAnalysisTime, token?: CancellationToken): boolean;
110
102
  analyzeFile(filePath: string, token?: CancellationToken): boolean;
111
- indexWorkspace(callback: (path: string, results: IndexResults) => void, token: CancellationToken): number;
112
103
  run<T>(callback: (p: ProgramView) => T, token: CancellationToken): T;
104
+ runWithMutation(callback: (v: ProgramView, m: ProgramMutator) => void, token: CancellationToken): void;
113
105
  getSourceMapper(filePath: string, token: CancellationToken, mapCompiled?: boolean, preferStubs?: boolean): SourceMapper;
114
106
  getParseResults(filePath: string): ParseResults | undefined;
115
107
  handleMemoryHighUsage(): void;
@@ -119,18 +111,11 @@ export declare class Program {
119
111
  getTypeOfSymbol(symbol: Symbol): Type;
120
112
  printType(type: Type, options?: PrintTypeOptions): string;
121
113
  getTextOnRange(filePath: string, range: Range, token: CancellationToken): string | undefined;
122
- getAutoImports(filePath: string, range: Range, similarityLimit: number, nameMap: AbbreviationMap | undefined, options: AutoImportOptions, token: CancellationToken): AutoImportResult[];
123
114
  getDiagnostics(options: ConfigOptions): FileDiagnostics[];
124
115
  getDiagnosticsForRange(filePath: string, range: Range): Diagnostic[];
125
- getFileIndex(filePath: string, options: IndexOptions, token: CancellationToken): IndexResults | undefined;
126
- addSymbolsForDocument(filePath: string, symbolList: DocumentSymbol[], token: CancellationToken): void;
127
- reportSymbolsForWorkspace(query: string, reporter: WorkspaceSymbolCallback, token: CancellationToken): void;
128
- getCompletionsForPosition(filePath: string, position: Position, workspacePath: string, options: CompletionOptions, nameMap: AbbreviationMap | undefined, libraryMap: Map<string, IndexResults> | undefined, token: CancellationToken): Promise<CompletionResultsList | undefined>;
129
- resolveCompletionItem(filePath: string, completionItem: CompletionItem, options: CompletionOptions, nameMap: AbbreviationMap | undefined, libraryMap: Map<string, IndexResults> | undefined, token: CancellationToken): void;
130
116
  clone(): Program;
131
117
  getCacheUsage(): number;
132
118
  emptyCache(): void;
133
- test_createSourceMapper(execEnv: ExecutionEnvironment, from?: SourceFileInfo): SourceMapper;
134
119
  private _handleMemoryHighUsage;
135
120
  private _discardCachedParseResults;
136
121
  private _runEvaluatorWithCancellationToken;
@@ -153,7 +138,6 @@ export declare class Program {
153
138
  private _bindFile;
154
139
  private _getEffectiveFutureImports;
155
140
  private _lookUpImport;
156
- private _buildModuleSymbolsMap;
157
141
  private _shouldCheckFile;
158
142
  private _checkTypes;
159
143
  private _getImportsRecursive;
@@ -28,12 +28,10 @@ var __importStar = (this && this.__importStar) || function (mod) {
28
28
  return result;
29
29
  };
30
30
  Object.defineProperty(exports, "__esModule", { value: true });
31
- exports.Program = exports.MaxWorkspaceIndexFileCount = void 0;
31
+ exports.Program = void 0;
32
32
  const vscode_languageserver_1 = require("vscode-languageserver");
33
- const vscode_languageserver_types_1 = require("vscode-languageserver-types");
34
33
  const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
35
34
  const cancellationUtils_1 = require("../common/cancellationUtils");
36
- const collectionUtils_1 = require("../common/collectionUtils");
37
35
  const configOptions_1 = require("../common/configOptions");
38
36
  const console_1 = require("../common/console");
39
37
  const debug = __importStar(require("../common/debug"));
@@ -42,25 +40,19 @@ const extensibility_1 = require("../common/extensibility");
42
40
  const logTracker_1 = require("../common/logTracker");
43
41
  const pathUtils_1 = require("../common/pathUtils");
44
42
  const positionUtils_1 = require("../common/positionUtils");
45
- const stringUtils_1 = require("../common/stringUtils");
46
43
  const textRange_1 = require("../common/textRange");
47
44
  const timing_1 = require("../common/timing");
48
- const autoImporter_1 = require("../languageService/autoImporter");
49
- const completionProvider_1 = require("../languageService/completionProvider");
50
45
  const AnalyzerNodeInfo = __importStar(require("./analyzerNodeInfo"));
51
46
  const cacheManager_1 = require("./cacheManager");
52
47
  const circularDependency_1 = require("./circularDependency");
53
48
  const parseTreeUtils_1 = require("./parseTreeUtils");
54
- const scopeUtils_1 = require("./scopeUtils");
55
49
  const sourceFile_1 = require("./sourceFile");
56
50
  const sourceFileInfoUtils_1 = require("./sourceFileInfoUtils");
57
51
  const sourceMapper_1 = require("./sourceMapper");
58
- const symbolNameUtils_1 = require("./symbolNameUtils");
59
52
  const tracePrinter_1 = require("./tracePrinter");
60
53
  const typeEvaluatorWithTracker_1 = require("./typeEvaluatorWithTracker");
61
54
  const typeStubWriter_1 = require("./typeStubWriter");
62
55
  const _maxImportDepth = 256;
63
- exports.MaxWorkspaceIndexFileCount = 2000;
64
56
  // Container for all of the files that are being analyzed. Files
65
57
  // can fall into one or more of the following categories:
66
58
  // Tracked - specified by the config options
@@ -68,7 +60,7 @@ exports.MaxWorkspaceIndexFileCount = 2000;
68
60
  // Opened - temporarily opened in the editor
69
61
  // Shadowed - implementation file that shadows a type stub file
70
62
  class Program {
71
- constructor(initialImportResolver, initialConfigOptions, console, logTracker, _disableChecker, cacheManager) {
63
+ constructor(initialImportResolver, initialConfigOptions, console, logTracker, _disableChecker, cacheManager, id) {
72
64
  this._disableChecker = _disableChecker;
73
65
  this._sourceFileList = [];
74
66
  this._sourceFileMap = new Map();
@@ -104,6 +96,20 @@ class Program {
104
96
  if (!sourceFileInfo) {
105
97
  return undefined;
106
98
  }
99
+ if (options === null || options === void 0 ? void 0 : options.skipParsing) {
100
+ // Return dummy information if the caller has indicated that parsing is
101
+ // unnecessary. This is used in cases where the caller simply wants to
102
+ // know if the source file exists but is not interested in the contents.
103
+ return {
104
+ symbolTable: new Map(),
105
+ dunderAllNames: undefined,
106
+ usesUnsupportedDunderAllForm: false,
107
+ get docString() {
108
+ return undefined;
109
+ },
110
+ isInPyTypedPackage: false,
111
+ };
112
+ }
107
113
  if (sourceFileInfo.sourceFile.isBindingRequired()) {
108
114
  // Bind the file if it's not already bound. Don't count this time
109
115
  // against the type checker.
@@ -136,7 +142,7 @@ class Program {
136
142
  this._cacheManager = cacheManager !== null && cacheManager !== void 0 ? cacheManager : new cacheManager_1.CacheManager();
137
143
  this._cacheManager.registerCacheOwner(this);
138
144
  this._createNewEvaluator();
139
- this._id = Program._nextId;
145
+ this._id = id !== null && id !== void 0 ? id : `Prog_${Program._nextId}`;
140
146
  Program._nextId += 1;
141
147
  }
142
148
  get id() {
@@ -351,14 +357,14 @@ class Program {
351
357
  }
352
358
  return this._removeUnneededFiles();
353
359
  }
354
- markAllFilesDirty(evenIfContentsAreSame, indexingNeeded = true) {
360
+ markAllFilesDirty(evenIfContentsAreSame) {
355
361
  const markDirtySet = new Set();
356
362
  this._sourceFileList.forEach((sourceFileInfo) => {
357
363
  if (evenIfContentsAreSame) {
358
- sourceFileInfo.sourceFile.markDirty(indexingNeeded);
364
+ sourceFileInfo.sourceFile.markDirty();
359
365
  }
360
366
  else if (sourceFileInfo.sourceFile.didContentsChangeOnDisk()) {
361
- sourceFileInfo.sourceFile.markDirty(indexingNeeded);
367
+ sourceFileInfo.sourceFile.markDirty();
362
368
  // Mark any files that depend on this file as dirty
363
369
  // also. This will retrigger analysis of these other files.
364
370
  this._markFileDirtyRecursive(sourceFileInfo, markDirtySet);
@@ -368,7 +374,7 @@ class Program {
368
374
  this._createNewEvaluator();
369
375
  }
370
376
  }
371
- markFilesDirty(filePaths, evenIfContentsAreSame, indexingNeeded = true) {
377
+ markFilesDirty(filePaths, evenIfContentsAreSame) {
372
378
  const markDirtySet = new Set();
373
379
  filePaths.forEach((filePath) => {
374
380
  const sourceFileInfo = this.getSourceFileInfo(filePath);
@@ -377,7 +383,7 @@ class Program {
377
383
  // Handle builtins and __builtins__ specially. They are implicitly
378
384
  // included by all source files.
379
385
  if (fileName === 'builtins.pyi' || fileName === '__builtins__.pyi') {
380
- this.markAllFilesDirty(evenIfContentsAreSame, indexingNeeded);
386
+ this.markAllFilesDirty(evenIfContentsAreSame);
381
387
  return;
382
388
  }
383
389
  // If !evenIfContentsAreSame, see if the on-disk contents have
@@ -385,7 +391,7 @@ class Program {
385
391
  // because we'll receive updates directly from the client.
386
392
  if (evenIfContentsAreSame ||
387
393
  (!sourceFileInfo.isOpenByClient && sourceFileInfo.sourceFile.didContentsChangeOnDisk())) {
388
- sourceFileInfo.sourceFile.markDirty(indexingNeeded);
394
+ sourceFileInfo.sourceFile.markDirty();
389
395
  // Mark any files that depend on this file as dirty
390
396
  // also. This will retrigger analysis of these other files.
391
397
  this._markFileDirtyRecursive(sourceFileInfo, markDirtySet);
@@ -526,59 +532,6 @@ class Program {
526
532
  return false;
527
533
  });
528
534
  }
529
- indexWorkspace(callback, token) {
530
- if (!this._configOptions.indexing) {
531
- return 0;
532
- }
533
- return this._runEvaluatorWithCancellationToken(token, () => {
534
- // Go through all workspace files to create indexing data.
535
- // This will cause all files in the workspace to be parsed and bound. But
536
- // _handleMemoryHighUsage will make sure we don't OOM and
537
- // at the end of this method, we will drop all trees and symbol tables
538
- // created due to indexing.
539
- let count = 0;
540
- const initiallyParsedSet = new Set();
541
- for (const sourceFileInfo of this._sourceFileList) {
542
- if (!sourceFileInfo.sourceFile.isParseRequired()) {
543
- initiallyParsedSet.add(sourceFileInfo);
544
- }
545
- if ((0, sourceFileInfoUtils_1.isUserCode)(sourceFileInfo) && !sourceFileInfo.sourceFile.isIndexingRequired()) {
546
- count++;
547
- }
548
- }
549
- if (count >= exports.MaxWorkspaceIndexFileCount) {
550
- // Already processed max files.
551
- return 0;
552
- }
553
- for (const sourceFileInfo of this._sourceFileList) {
554
- if (!(0, sourceFileInfoUtils_1.isUserCode)(sourceFileInfo) || !sourceFileInfo.sourceFile.isIndexingRequired()) {
555
- continue;
556
- }
557
- this._bindFile(sourceFileInfo);
558
- const results = sourceFileInfo.sourceFile.index({ indexingForAutoImportMode: false }, token);
559
- if (results) {
560
- if (++count > exports.MaxWorkspaceIndexFileCount) {
561
- this._console.warn(`Workspace indexing has hit its upper limit: 2000 files`);
562
- dropParseAndBindInfoCreatedForIndexing(this._sourceFileList, initiallyParsedSet);
563
- return count;
564
- }
565
- callback(sourceFileInfo.sourceFile.getFilePath(), results);
566
- }
567
- this._handleMemoryHighUsage();
568
- }
569
- dropParseAndBindInfoCreatedForIndexing(this._sourceFileList, initiallyParsedSet);
570
- return count;
571
- });
572
- function dropParseAndBindInfoCreatedForIndexing(sourceFiles, initiallyParsedSet) {
573
- for (const sourceFileInfo of sourceFiles) {
574
- if (sourceFileInfo.sourceFile.isParseRequired() || initiallyParsedSet.has(sourceFileInfo)) {
575
- continue;
576
- }
577
- // Drop parse and bind info created during indexing.
578
- sourceFileInfo.sourceFile.dropParseAndBindInfo();
579
- }
580
- }
581
- }
582
535
  // This will allow the callback to execute a type evaluator with an associated
583
536
  // cancellation token and provide a read-only program.
584
537
  run(callback, token) {
@@ -586,6 +539,38 @@ class Program {
586
539
  const evaluator = (_a = this._evaluator) !== null && _a !== void 0 ? _a : this._createNewEvaluator();
587
540
  return evaluator.runWithCancellationToken(token, () => callback(this));
588
541
  }
542
+ // This will allow the callback to execute a type evaluator with an associated
543
+ // cancellation token and provide a mutable program. Should already be in edit mode when called.
544
+ runWithMutation(callback, token) {
545
+ var _a;
546
+ if (this._isEditMode) {
547
+ // Create a temporary mutator that doesn't talk to the
548
+ // background thread. In edit mode there is no background thread.
549
+ const mutator = {
550
+ addInterimFile: (f) => {
551
+ return this.addInterimFile(f);
552
+ },
553
+ setFileOpened: (p, v, c, i, ch, r) => {
554
+ this.setFileOpened(p, v, c, {
555
+ isTracked: this.owns(p),
556
+ ipythonMode: i,
557
+ chainedFilePath: ch,
558
+ realFilePath: r,
559
+ });
560
+ },
561
+ updateOpenFileContents: (p, v, c, i, r) => {
562
+ this.setFileOpened(p, v, c, {
563
+ isTracked: this.owns(p),
564
+ ipythonMode: i,
565
+ chainedFilePath: undefined,
566
+ realFilePath: r,
567
+ });
568
+ },
569
+ };
570
+ const evaluator = (_a = this._evaluator) !== null && _a !== void 0 ? _a : this._createNewEvaluator();
571
+ evaluator.runWithCancellationToken(token, () => callback(this, mutator));
572
+ }
573
+ }
589
574
  getSourceMapper(filePath, token, mapCompiled, preferStubs) {
590
575
  const sourceFileInfo = this.getSourceFileInfo(filePath);
591
576
  const execEnv = this._configOptions.findExecEnvironment(filePath);
@@ -726,51 +711,6 @@ class Program {
726
711
  return fileContents.substr(textRange.start, textRange.length);
727
712
  });
728
713
  }
729
- getAutoImports(filePath, range, similarityLimit, nameMap, options, token) {
730
- const sourceFileInfo = this.getSourceFileInfo(filePath);
731
- if (!sourceFileInfo) {
732
- return [];
733
- }
734
- const sourceFile = sourceFileInfo.sourceFile;
735
- const fileContents = sourceFile.getOpenFileContents();
736
- if (fileContents === undefined) {
737
- // this only works with opened file
738
- return [];
739
- }
740
- return this._runEvaluatorWithCancellationToken(token, () => {
741
- var _a;
742
- this._bindFile(sourceFileInfo);
743
- const parseTree = sourceFile.getParseResults();
744
- const textRange = (0, positionUtils_1.convertRangeToTextRange)(range, parseTree.tokenizerOutput.lines);
745
- if (!textRange) {
746
- return [];
747
- }
748
- const currentNode = (0, parseTreeUtils_1.findNodeByOffset)(parseTree.parseTree, textRange.start);
749
- if (!currentNode) {
750
- return [];
751
- }
752
- const writtenWord = fileContents.substr(textRange.start, textRange.length);
753
- const map = this._buildModuleSymbolsMap(sourceFileInfo, options.libraryMap,
754
- /* includeSymbolsFromIndices */ true, token);
755
- options.patternMatcher =
756
- (_a = options.patternMatcher) !== null && _a !== void 0 ? _a : ((p, t) => (0, stringUtils_1.computeCompletionSimilarity)(p, t) > similarityLimit);
757
- const autoImporter = new autoImporter_1.AutoImporter(this._configOptions.findExecEnvironment(filePath), this._importResolver, parseTree, range.start, new completionProvider_1.CompletionMap(), map, options);
758
- // Filter out any name that is already defined in the current scope.
759
- const results = [];
760
- const currentScope = (0, scopeUtils_1.getScopeForNode)(currentNode);
761
- if (currentScope) {
762
- const info = nameMap === null || nameMap === void 0 ? void 0 : nameMap.get(writtenWord);
763
- if (info) {
764
- // No scope filter is needed since we only do exact match.
765
- (0, collectionUtils_1.appendArray)(results, autoImporter.getAutoImportCandidatesForAbbr(writtenWord, info, token));
766
- }
767
- results.push(...autoImporter
768
- .getAutoImportCandidates(writtenWord, similarityLimit, /* abbrFromUsers */ undefined, token)
769
- .filter((r) => !currentScope.lookUpSymbolRecursive(r.name)));
770
- }
771
- return results;
772
- });
773
- }
774
714
  getDiagnostics(options) {
775
715
  const fileDiagnostics = this._removeUnneededFiles();
776
716
  this._sourceFileList.forEach((sourceFileInfo) => {
@@ -815,127 +755,13 @@ class Program {
815
755
  return (0, textRange_1.doRangesIntersect)(diag.range, range);
816
756
  });
817
757
  }
818
- getFileIndex(filePath, options, token) {
819
- if (options.indexingForAutoImportMode) {
820
- // Memory optimization. We only want to hold onto symbols
821
- // usable outside when importSymbolsOnly is on.
822
- const name = (0, pathUtils_1.stripFileExtension)((0, pathUtils_1.getFileName)(filePath));
823
- if ((0, symbolNameUtils_1.isPrivateOrProtectedName)(name)) {
824
- return undefined;
825
- }
826
- }
827
- this._handleMemoryHighUsage();
828
- return this._runEvaluatorWithCancellationToken(token, () => {
829
- var _a;
830
- const sourceFileInfo = this.getSourceFileInfo(filePath);
831
- if (!sourceFileInfo) {
832
- return undefined;
833
- }
834
- const content = (_a = sourceFileInfo.sourceFile.getFileContent()) !== null && _a !== void 0 ? _a : '';
835
- if (options.indexingForAutoImportMode &&
836
- !options.includeAllSymbols &&
837
- !sourceFileInfo.sourceFile.isStubFile() &&
838
- !sourceFileInfo.sourceFile.isThirdPartyPyTypedPresent()) {
839
- // Perf optimization. if py file doesn't contain __all__
840
- // No need to parse and bind.
841
- if (content.indexOf('__all__') < 0) {
842
- return undefined;
843
- }
844
- }
845
- this._bindFile(sourceFileInfo, content);
846
- return sourceFileInfo.sourceFile.index(options, token);
847
- });
848
- }
849
- addSymbolsForDocument(filePath, symbolList, token) {
850
- return this._runEvaluatorWithCancellationToken(token, () => {
851
- const sourceFileInfo = this.getSourceFileInfo(filePath);
852
- if (sourceFileInfo) {
853
- if (!sourceFileInfo.sourceFile.getCachedIndexResults()) {
854
- // If we already have cached index for this file, no need to bind this file.
855
- this._bindFile(sourceFileInfo);
856
- }
857
- sourceFileInfo.sourceFile.addHierarchicalSymbolsForDocument(symbolList, token);
858
- }
859
- });
860
- }
861
- reportSymbolsForWorkspace(query, reporter, token) {
862
- this._runEvaluatorWithCancellationToken(token, () => {
863
- // Don't do a search if the query is empty. We'll return
864
- // too many results in this case.
865
- if (!query) {
866
- return;
867
- }
868
- // "Workspace symbols" searches symbols only from user code.
869
- for (const sourceFileInfo of this._sourceFileList) {
870
- if (!(0, sourceFileInfoUtils_1.isUserCode)(sourceFileInfo)) {
871
- continue;
872
- }
873
- if (!sourceFileInfo.sourceFile.getCachedIndexResults()) {
874
- // If we already have cached index for this file, no need to bind this file.
875
- this._bindFile(sourceFileInfo);
876
- }
877
- const symbolList = sourceFileInfo.sourceFile.getSymbolsForDocument(query, token);
878
- if (symbolList.length > 0) {
879
- reporter(symbolList);
880
- }
881
- // This operation can consume significant memory, so check
882
- // for situations where we need to discard the type cache.
883
- this._handleMemoryHighUsage();
884
- }
885
- });
886
- }
887
- async getCompletionsForPosition(filePath, position, workspacePath, options, nameMap, libraryMap, token) {
888
- const sourceFileInfo = this.getSourceFileInfo(filePath);
889
- if (!sourceFileInfo) {
890
- return undefined;
891
- }
892
- const completionResult = this._logTracker.log(`completion at ${filePath}:${position.line}:${position.character}`, (ls) => {
893
- var _a;
894
- const result = this._runEvaluatorWithCancellationToken(token, () => {
895
- this._bindFile(sourceFileInfo);
896
- return sourceFileInfo.sourceFile.getCompletionsForPosition(this, position, workspacePath, this._lookUpImport, options, nameMap, libraryMap, () => this._buildModuleSymbolsMap(sourceFileInfo, libraryMap, options.includeUserSymbolsInAutoImport, token), token);
897
- });
898
- ls.add(`found ${(_a = result === null || result === void 0 ? void 0 : result.completionMap.size) !== null && _a !== void 0 ? _a : 'null'} items`);
899
- return result;
900
- });
901
- const completionResultsList = {
902
- completionList: vscode_languageserver_types_1.CompletionList.create(completionResult === null || completionResult === void 0 ? void 0 : completionResult.completionMap.toArray()),
903
- memberAccessInfo: completionResult === null || completionResult === void 0 ? void 0 : completionResult.memberAccessInfo,
904
- autoImportInfo: completionResult === null || completionResult === void 0 ? void 0 : completionResult.autoImportInfo,
905
- extensionInfo: completionResult === null || completionResult === void 0 ? void 0 : completionResult.extensionInfo,
906
- };
907
- const parseResults = sourceFileInfo.sourceFile.getParseResults();
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);
912
- const offset = (0, positionUtils_1.convertPositionToOffset)(position, parseResults.tokenizerOutput.lines);
913
- if (offset !== undefined && sourceMapper) {
914
- await Promise.all(extensibility_1.Extensions.getProgramExtensions(parseResults.parseTree).map((e) => {
915
- var _a;
916
- return (_a = e.completionListExtension) === null || _a === void 0 ? void 0 : _a.updateCompletionResults(this.evaluator, sourceMapper, options, completionResultsList, parseResults, offset, this._configOptions.functionSignatureDisplay, token);
917
- }));
918
- }
919
- }
920
- return completionResultsList;
921
- }
922
- resolveCompletionItem(filePath, completionItem, options, nameMap, libraryMap, token) {
923
- return this._runEvaluatorWithCancellationToken(token, () => {
924
- const sourceFileInfo = this.getSourceFileInfo(filePath);
925
- if (!sourceFileInfo) {
926
- return;
927
- }
928
- this._bindFile(sourceFileInfo);
929
- sourceFileInfo.sourceFile.resolveCompletionItem(this, this._lookUpImport, options, nameMap, libraryMap, () => this._buildModuleSymbolsMap(sourceFileInfo, libraryMap, options.includeUserSymbolsInAutoImport, token), completionItem, token);
930
- });
931
- }
932
758
  clone() {
933
759
  var _a, _b;
934
760
  const program = new Program(this._importResolver, this._configOptions, this._console, new logTracker_1.LogTracker(this._console, 'Cloned'));
935
761
  // Cloned program will use whatever user files the program currently has.
936
762
  const userFiles = this.getUserFiles();
937
763
  program.setTrackedFiles(userFiles.map((i) => i.sourceFile.getFilePath()));
938
- program.markAllFilesDirty(true);
764
+ program.markAllFilesDirty(/* evenIfContentsAreSame */ true);
939
765
  // Make sure we keep editor content (open file) which could be different than one in the file system.
940
766
  for (const fileInfo of this.getOpened()) {
941
767
  const version = fileInfo.sourceFile.getClientVersion();
@@ -968,9 +794,6 @@ class Program {
968
794
  this._parsedFileCount = 0;
969
795
  extensibility_1.Extensions.getProgramExtensions(this.rootPath).forEach((e) => (e.clearCache ? e.clearCache() : null));
970
796
  }
971
- test_createSourceMapper(execEnv, from) {
972
- return this._createSourceMapper(execEnv, vscode_languageserver_1.CancellationToken.None, /* from */ from, /* mapCompiled */ false);
973
- }
974
797
  _handleMemoryHighUsage() {
975
798
  const cacheUsage = this._cacheManager.getCacheUsage();
976
799
  // If the total cache has exceeded 75%, determine whether we should empty
@@ -1182,7 +1005,7 @@ class Program {
1182
1005
  thirdPartyImportAllowed = true;
1183
1006
  }
1184
1007
  else if (importResult.isNamespacePackage &&
1185
- importResult.filteredImplicitImports.some((implicitImport) => !!implicitImport.pyTypedInfo)) {
1008
+ Array.from(importResult.filteredImplicitImports.values()).some((implicitImport) => !!implicitImport.pyTypedInfo)) {
1186
1009
  // Handle the case where the import targets a namespace package, and a
1187
1010
  // submodule contained within it has a py.typed marker.
1188
1011
  thirdPartyImportAllowed = true;
@@ -1581,31 +1404,6 @@ class Program {
1581
1404
  });
1582
1405
  return effectiveFutureImports;
1583
1406
  }
1584
- // Build a map of all modules within this program and the module-
1585
- // level scope that contains the symbol table for the module.
1586
- _buildModuleSymbolsMap(sourceFileToExclude, libraryMap, includeSymbolsFromIndices, token) {
1587
- // If we have library map, always use the map for library symbols.
1588
- const predicate = (s) => {
1589
- if (!libraryMap) {
1590
- // We don't have any prebuilt indices, so we need to include
1591
- // all files.
1592
- return true;
1593
- }
1594
- if (!this._configOptions.indexing) {
1595
- // We have some prebuilt indices such as stdlib, but indexing is disabled.
1596
- // Include files we don't have prebuilt indices.
1597
- return libraryMap.get(s.sourceFile.getFilePath()) === undefined;
1598
- }
1599
- // We have prebuilt indices for third party libraries. Include only
1600
- // user files.
1601
- return (0, sourceFileInfoUtils_1.isUserCode)(s);
1602
- };
1603
- // Only include import alias from user files if indexing is off for now.
1604
- // Currently, when indexing is off, we don't do import alias deduplication, so
1605
- // adding import alias is cheap. But when indexing is on, we do deduplication, which
1606
- // require resolveAliasDeclaration that can cause more files to be parsed and bound.
1607
- return (0, autoImporter_1.buildModuleSymbolsMap)(this._sourceFileList.filter((s) => s !== sourceFileToExclude && predicate(s)), includeSymbolsFromIndices, token);
1608
- }
1609
1407
  _shouldCheckFile(fileInfo) {
1610
1408
  // Always do a full checking for a file that's open in the editor.
1611
1409
  if (fileInfo.isOpenByClient) {