@tsc-rs/typescript 0.0.0-placeholder → 0.8.0
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.
- package/LICENSE +21 -0
- package/NOTICE.txt +599 -0
- package/README.md +111 -0
- package/bin/tsc +2 -0
- package/dist/api/async/api.d.ts +1041 -0
- package/dist/api/async/api.d.ts.map +1 -0
- package/dist/api/async/api.js +3143 -0
- package/dist/api/async/api.js.map +1 -0
- package/dist/api/async/client.d.ts +52 -0
- package/dist/api/async/client.d.ts.map +1 -0
- package/dist/api/async/client.js +365 -0
- package/dist/api/async/client.js.map +1 -0
- package/dist/api/async/types.d.ts +375 -0
- package/dist/api/async/types.d.ts.map +1 -0
- package/dist/api/async/types.js +2 -0
- package/dist/api/async/types.js.map +1 -0
- package/dist/api/compilerOptions.generated.d.ts +123 -0
- package/dist/api/compilerOptions.generated.d.ts.map +1 -0
- package/dist/api/compilerOptions.generated.js +8 -0
- package/dist/api/compilerOptions.generated.js.map +1 -0
- package/dist/api/diagnosticFormatter.d.ts +9 -0
- package/dist/api/diagnosticFormatter.d.ts.map +1 -0
- package/dist/api/diagnosticFormatter.js +169 -0
- package/dist/api/diagnosticFormatter.js.map +1 -0
- package/dist/api/fs.d.ts +78 -0
- package/dist/api/fs.d.ts.map +1 -0
- package/dist/api/fs.js +70 -0
- package/dist/api/fs.js.map +1 -0
- package/dist/api/fsCallbacks.d.ts +27 -0
- package/dist/api/fsCallbacks.d.ts.map +1 -0
- package/dist/api/fsCallbacks.js +111 -0
- package/dist/api/fsCallbacks.js.map +1 -0
- package/dist/api/node/encoder.d.ts +18 -0
- package/dist/api/node/encoder.d.ts.map +1 -0
- package/dist/api/node/encoder.generated.d.ts +5 -0
- package/dist/api/node/encoder.generated.d.ts.map +1 -0
- package/dist/api/node/encoder.generated.js +74 -0
- package/dist/api/node/encoder.generated.js.map +1 -0
- package/dist/api/node/encoder.js +292 -0
- package/dist/api/node/encoder.js.map +1 -0
- package/dist/api/node/msgpack.d.ts +32 -0
- package/dist/api/node/msgpack.d.ts.map +1 -0
- package/dist/api/node/msgpack.js +212 -0
- package/dist/api/node/msgpack.js.map +1 -0
- package/dist/api/node/node.d.ts +102 -0
- package/dist/api/node/node.d.ts.map +1 -0
- package/dist/api/node/node.generated.d.ts +189 -0
- package/dist/api/node/node.generated.d.ts.map +1 -0
- package/dist/api/node/node.generated.js +884 -0
- package/dist/api/node/node.generated.js.map +1 -0
- package/dist/api/node/node.infrastructure.d.ts +64 -0
- package/dist/api/node/node.infrastructure.d.ts.map +1 -0
- package/dist/api/node/node.infrastructure.js +102 -0
- package/dist/api/node/node.infrastructure.js.map +1 -0
- package/dist/api/node/node.js +454 -0
- package/dist/api/node/node.js.map +1 -0
- package/dist/api/node/protocol.d.ts +32 -0
- package/dist/api/node/protocol.d.ts.map +1 -0
- package/dist/api/node/protocol.generated.d.ts +4 -0
- package/dist/api/node/protocol.generated.d.ts.map +1 -0
- package/dist/api/node/protocol.generated.js +241 -0
- package/dist/api/node/protocol.generated.js.map +1 -0
- package/dist/api/node/protocol.js +33 -0
- package/dist/api/node/protocol.js.map +1 -0
- package/dist/api/node/wtf8.d.ts +10 -0
- package/dist/api/node/wtf8.d.ts.map +1 -0
- package/dist/api/node/wtf8.js +130 -0
- package/dist/api/node/wtf8.js.map +1 -0
- package/dist/api/options.d.ts +41 -0
- package/dist/api/options.d.ts.map +1 -0
- package/dist/api/options.js +32 -0
- package/dist/api/options.js.map +1 -0
- package/dist/api/path.d.ts +149 -0
- package/dist/api/path.d.ts.map +1 -0
- package/dist/api/path.js +884 -0
- package/dist/api/path.js.map +1 -0
- package/dist/api/prepareCompilerOptions.generated.d.ts +5 -0
- package/dist/api/prepareCompilerOptions.generated.d.ts.map +1 -0
- package/dist/api/prepareCompilerOptions.generated.js +24 -0
- package/dist/api/prepareCompilerOptions.generated.js.map +1 -0
- package/dist/api/proto.d.ts +95 -0
- package/dist/api/proto.d.ts.map +1 -0
- package/dist/api/proto.generated.d.ts +1423 -0
- package/dist/api/proto.generated.d.ts.map +1 -0
- package/dist/api/proto.generated.js +21 -0
- package/dist/api/proto.generated.js.map +1 -0
- package/dist/api/proto.js +65 -0
- package/dist/api/proto.js.map +1 -0
- package/dist/api/sourceFileCache.d.ts +110 -0
- package/dist/api/sourceFileCache.d.ts.map +1 -0
- package/dist/api/sourceFileCache.js +300 -0
- package/dist/api/sourceFileCache.js.map +1 -0
- package/dist/api/sync/api.d.ts +1729 -0
- package/dist/api/sync/api.d.ts.map +1 -0
- package/dist/api/sync/api.js +5484 -0
- package/dist/api/sync/api.js.map +1 -0
- package/dist/api/sync/client.d.ts +34 -0
- package/dist/api/sync/client.d.ts.map +1 -0
- package/dist/api/sync/client.js +148 -0
- package/dist/api/sync/client.js.map +1 -0
- package/dist/api/sync/generatorSupport.d.ts +32 -0
- package/dist/api/sync/generatorSupport.d.ts.map +1 -0
- package/dist/api/sync/generatorSupport.js +323 -0
- package/dist/api/sync/generatorSupport.js.map +1 -0
- package/dist/api/sync/types.d.ts +502 -0
- package/dist/api/sync/types.d.ts.map +1 -0
- package/dist/api/sync/types.js +2 -0
- package/dist/api/sync/types.js.map +1 -0
- package/dist/api/syncChannel.d.ts +115 -0
- package/dist/api/syncChannel.d.ts.map +1 -0
- package/dist/api/syncChannel.js +511 -0
- package/dist/api/syncChannel.js.map +1 -0
- package/dist/api/timing.d.ts +175 -0
- package/dist/api/timing.d.ts.map +1 -0
- package/dist/api/timing.js +149 -0
- package/dist/api/timing.js.map +1 -0
- package/dist/api/typedPaths.d.ts +3 -0
- package/dist/api/typedPaths.d.ts.map +1 -0
- package/dist/api/typedPaths.js +2 -0
- package/dist/api/typedPaths.js.map +1 -0
- package/dist/api/userPreferences.generated.d.ts +195 -0
- package/dist/api/userPreferences.generated.d.ts.map +1 -0
- package/dist/api/userPreferences.generated.js +3 -0
- package/dist/api/userPreferences.generated.js.map +1 -0
- package/dist/ast/ast.d.ts +186 -0
- package/dist/ast/ast.d.ts.map +1 -0
- package/dist/ast/ast.generated.d.ts +1167 -0
- package/dist/ast/ast.generated.d.ts.map +1 -0
- package/dist/ast/ast.generated.js +4 -0
- package/dist/ast/ast.generated.js.map +1 -0
- package/dist/ast/ast.js +7 -0
- package/dist/ast/ast.js.map +1 -0
- package/dist/ast/astnav.d.ts +22 -0
- package/dist/ast/astnav.d.ts.map +1 -0
- package/dist/ast/astnav.js +741 -0
- package/dist/ast/astnav.js.map +1 -0
- package/dist/ast/clone.d.ts +16 -0
- package/dist/ast/clone.d.ts.map +1 -0
- package/dist/ast/clone.js +104 -0
- package/dist/ast/clone.js.map +1 -0
- package/dist/ast/factory.generated.d.ts +533 -0
- package/dist/ast/factory.generated.d.ts.map +1 -0
- package/dist/ast/factory.generated.js +5750 -0
- package/dist/ast/factory.generated.js.map +1 -0
- package/dist/ast/index.d.ts +25 -0
- package/dist/ast/index.d.ts.map +1 -0
- package/dist/ast/index.js +25 -0
- package/dist/ast/index.js.map +1 -0
- package/dist/ast/is.d.ts +36 -0
- package/dist/ast/is.d.ts.map +1 -0
- package/dist/ast/is.generated.d.ts +1217 -0
- package/dist/ast/is.generated.d.ts.map +1 -0
- package/dist/ast/is.generated.js +1400 -0
- package/dist/ast/is.generated.js.map +1 -0
- package/dist/ast/is.js +456 -0
- package/dist/ast/is.js.map +1 -0
- package/dist/ast/jsdoc.d.ts +12 -0
- package/dist/ast/jsdoc.d.ts.map +1 -0
- package/dist/ast/jsdoc.js +208 -0
- package/dist/ast/jsdoc.js.map +1 -0
- package/dist/ast/modifiers.d.ts +4 -0
- package/dist/ast/modifiers.d.ts.map +1 -0
- package/dist/ast/modifiers.js +41 -0
- package/dist/ast/modifiers.js.map +1 -0
- package/dist/ast/scanner.d.ts +97 -0
- package/dist/ast/scanner.d.ts.map +1 -0
- package/dist/ast/scanner.js +2231 -0
- package/dist/ast/scanner.js.map +1 -0
- package/dist/ast/spanMap.d.ts +88 -0
- package/dist/ast/spanMap.d.ts.map +1 -0
- package/dist/ast/spanMap.js +417 -0
- package/dist/ast/spanMap.js.map +1 -0
- package/dist/ast/utils.d.ts +30 -0
- package/dist/ast/utils.d.ts.map +1 -0
- package/dist/ast/utils.js +318 -0
- package/dist/ast/utils.js.map +1 -0
- package/dist/ast/visitor.d.ts +16 -0
- package/dist/ast/visitor.d.ts.map +1 -0
- package/dist/ast/visitor.generated.d.ts +50 -0
- package/dist/ast/visitor.generated.d.ts.map +1 -0
- package/dist/ast/visitor.generated.js +979 -0
- package/dist/ast/visitor.generated.js.map +1 -0
- package/dist/ast/visitor.js +87 -0
- package/dist/ast/visitor.js.map +1 -0
- package/dist/enums/caseSensitivity.d.ts +2 -0
- package/dist/enums/caseSensitivity.d.ts.map +1 -0
- package/dist/enums/caseSensitivity.enum.d.ts +5 -0
- package/dist/enums/caseSensitivity.enum.d.ts.map +1 -0
- package/dist/enums/caseSensitivity.enum.js +7 -0
- package/dist/enums/caseSensitivity.enum.js.map +1 -0
- package/dist/enums/caseSensitivity.js +7 -0
- package/dist/enums/caseSensitivity.js.map +1 -0
- package/dist/enums/characterCodes.d.ts +2 -0
- package/dist/enums/characterCodes.d.ts.map +1 -0
- package/dist/enums/characterCodes.enum.d.ts +129 -0
- package/dist/enums/characterCodes.enum.d.ts.map +1 -0
- package/dist/enums/characterCodes.enum.js +132 -0
- package/dist/enums/characterCodes.enum.js.map +1 -0
- package/dist/enums/characterCodes.js +130 -0
- package/dist/enums/characterCodes.js.map +1 -0
- package/dist/enums/checkFlags.d.ts +2 -0
- package/dist/enums/checkFlags.d.ts.map +1 -0
- package/dist/enums/checkFlags.enum.d.ts +34 -0
- package/dist/enums/checkFlags.enum.d.ts.map +1 -0
- package/dist/enums/checkFlags.enum.js +36 -0
- package/dist/enums/checkFlags.enum.js.map +1 -0
- package/dist/enums/checkFlags.js +36 -0
- package/dist/enums/checkFlags.js.map +1 -0
- package/dist/enums/commentDirectiveType.d.ts +2 -0
- package/dist/enums/commentDirectiveType.d.ts.map +1 -0
- package/dist/enums/commentDirectiveType.enum.d.ts +5 -0
- package/dist/enums/commentDirectiveType.enum.d.ts.map +1 -0
- package/dist/enums/commentDirectiveType.enum.js +6 -0
- package/dist/enums/commentDirectiveType.enum.js.map +1 -0
- package/dist/enums/commentDirectiveType.js +6 -0
- package/dist/enums/commentDirectiveType.js.map +1 -0
- package/dist/enums/completionItemKind.d.ts +2 -0
- package/dist/enums/completionItemKind.d.ts.map +1 -0
- package/dist/enums/completionItemKind.enum.d.ts +28 -0
- package/dist/enums/completionItemKind.enum.d.ts.map +1 -0
- package/dist/enums/completionItemKind.enum.js +30 -0
- package/dist/enums/completionItemKind.enum.js.map +1 -0
- package/dist/enums/completionItemKind.js +30 -0
- package/dist/enums/completionItemKind.js.map +1 -0
- package/dist/enums/diagnosticCategory.d.ts +2 -0
- package/dist/enums/diagnosticCategory.d.ts.map +1 -0
- package/dist/enums/diagnosticCategory.enum.d.ts +7 -0
- package/dist/enums/diagnosticCategory.enum.d.ts.map +1 -0
- package/dist/enums/diagnosticCategory.enum.js +9 -0
- package/dist/enums/diagnosticCategory.enum.js.map +1 -0
- package/dist/enums/diagnosticCategory.js +9 -0
- package/dist/enums/diagnosticCategory.js.map +1 -0
- package/dist/enums/diagnosticDirectivePolicy.d.ts +2 -0
- package/dist/enums/diagnosticDirectivePolicy.d.ts.map +1 -0
- package/dist/enums/diagnosticDirectivePolicy.enum.d.ts +5 -0
- package/dist/enums/diagnosticDirectivePolicy.enum.d.ts.map +1 -0
- package/dist/enums/diagnosticDirectivePolicy.enum.js +7 -0
- package/dist/enums/diagnosticDirectivePolicy.enum.js.map +1 -0
- package/dist/enums/diagnosticDirectivePolicy.js +7 -0
- package/dist/enums/diagnosticDirectivePolicy.js.map +1 -0
- package/dist/enums/elementFlags.d.ts +2 -0
- package/dist/enums/elementFlags.d.ts.map +1 -0
- package/dist/enums/elementFlags.enum.d.ts +12 -0
- package/dist/enums/elementFlags.enum.d.ts.map +1 -0
- package/dist/enums/elementFlags.enum.js +14 -0
- package/dist/enums/elementFlags.enum.js.map +1 -0
- package/dist/enums/elementFlags.js +14 -0
- package/dist/enums/elementFlags.js.map +1 -0
- package/dist/enums/emitOnly.d.ts +2 -0
- package/dist/enums/emitOnly.d.ts.map +1 -0
- package/dist/enums/emitOnly.enum.d.ts +6 -0
- package/dist/enums/emitOnly.enum.d.ts.map +1 -0
- package/dist/enums/emitOnly.enum.js +8 -0
- package/dist/enums/emitOnly.enum.js.map +1 -0
- package/dist/enums/emitOnly.js +8 -0
- package/dist/enums/emitOnly.js.map +1 -0
- package/dist/enums/indexKind.d.ts +2 -0
- package/dist/enums/indexKind.d.ts.map +1 -0
- package/dist/enums/indexKind.enum.d.ts +5 -0
- package/dist/enums/indexKind.enum.d.ts.map +1 -0
- package/dist/enums/indexKind.enum.js +7 -0
- package/dist/enums/indexKind.enum.js.map +1 -0
- package/dist/enums/indexKind.js +7 -0
- package/dist/enums/indexKind.js.map +1 -0
- package/dist/enums/internalSymbolName.d.ts +2 -0
- package/dist/enums/internalSymbolName.d.ts.map +1 -0
- package/dist/enums/internalSymbolName.enum.d.ts +23 -0
- package/dist/enums/internalSymbolName.enum.d.ts.map +1 -0
- package/dist/enums/internalSymbolName.enum.js +25 -0
- package/dist/enums/internalSymbolName.enum.js.map +1 -0
- package/dist/enums/internalSymbolName.js +25 -0
- package/dist/enums/internalSymbolName.js.map +1 -0
- package/dist/enums/jsDeclarationKind.d.ts +2 -0
- package/dist/enums/jsDeclarationKind.d.ts.map +1 -0
- package/dist/enums/jsDeclarationKind.enum.d.ts +10 -0
- package/dist/enums/jsDeclarationKind.enum.d.ts.map +1 -0
- package/dist/enums/jsDeclarationKind.enum.js +12 -0
- package/dist/enums/jsDeclarationKind.enum.js.map +1 -0
- package/dist/enums/jsDeclarationKind.js +12 -0
- package/dist/enums/jsDeclarationKind.js.map +1 -0
- package/dist/enums/jsxEmit.d.ts +2 -0
- package/dist/enums/jsxEmit.d.ts.map +1 -0
- package/dist/enums/jsxEmit.enum.d.ts +9 -0
- package/dist/enums/jsxEmit.enum.d.ts.map +1 -0
- package/dist/enums/jsxEmit.enum.js +11 -0
- package/dist/enums/jsxEmit.enum.js.map +1 -0
- package/dist/enums/jsxEmit.js +11 -0
- package/dist/enums/jsxEmit.js.map +1 -0
- package/dist/enums/languageVariant.d.ts +2 -0
- package/dist/enums/languageVariant.d.ts.map +1 -0
- package/dist/enums/languageVariant.enum.d.ts +5 -0
- package/dist/enums/languageVariant.enum.d.ts.map +1 -0
- package/dist/enums/languageVariant.enum.js +6 -0
- package/dist/enums/languageVariant.enum.js.map +1 -0
- package/dist/enums/languageVariant.js +6 -0
- package/dist/enums/languageVariant.js.map +1 -0
- package/dist/enums/modifierFlags.d.ts +2 -0
- package/dist/enums/modifierFlags.d.ts.map +1 -0
- package/dist/enums/modifierFlags.enum.d.ts +42 -0
- package/dist/enums/modifierFlags.enum.d.ts.map +1 -0
- package/dist/enums/modifierFlags.enum.js +44 -0
- package/dist/enums/modifierFlags.enum.js.map +1 -0
- package/dist/enums/modifierFlags.js +44 -0
- package/dist/enums/modifierFlags.js.map +1 -0
- package/dist/enums/moduleDetectionKind.d.ts +2 -0
- package/dist/enums/moduleDetectionKind.d.ts.map +1 -0
- package/dist/enums/moduleDetectionKind.enum.d.ts +7 -0
- package/dist/enums/moduleDetectionKind.enum.d.ts.map +1 -0
- package/dist/enums/moduleDetectionKind.enum.js +9 -0
- package/dist/enums/moduleDetectionKind.enum.js.map +1 -0
- package/dist/enums/moduleDetectionKind.js +9 -0
- package/dist/enums/moduleDetectionKind.js.map +1 -0
- package/dist/enums/moduleKind.d.ts +2 -0
- package/dist/enums/moduleKind.d.ts.map +1 -0
- package/dist/enums/moduleKind.enum.d.ts +17 -0
- package/dist/enums/moduleKind.enum.d.ts.map +1 -0
- package/dist/enums/moduleKind.enum.js +19 -0
- package/dist/enums/moduleKind.enum.js.map +1 -0
- package/dist/enums/moduleKind.js +19 -0
- package/dist/enums/moduleKind.js.map +1 -0
- package/dist/enums/moduleResolutionKind.d.ts +2 -0
- package/dist/enums/moduleResolutionKind.d.ts.map +1 -0
- package/dist/enums/moduleResolutionKind.enum.d.ts +9 -0
- package/dist/enums/moduleResolutionKind.enum.d.ts.map +1 -0
- package/dist/enums/moduleResolutionKind.enum.js +11 -0
- package/dist/enums/moduleResolutionKind.enum.js.map +1 -0
- package/dist/enums/moduleResolutionKind.js +11 -0
- package/dist/enums/moduleResolutionKind.js.map +1 -0
- package/dist/enums/newLineKind.d.ts +2 -0
- package/dist/enums/newLineKind.d.ts.map +1 -0
- package/dist/enums/newLineKind.enum.d.ts +6 -0
- package/dist/enums/newLineKind.enum.d.ts.map +1 -0
- package/dist/enums/newLineKind.enum.js +8 -0
- package/dist/enums/newLineKind.enum.js.map +1 -0
- package/dist/enums/newLineKind.js +8 -0
- package/dist/enums/newLineKind.js.map +1 -0
- package/dist/enums/nodeBuilderFlags.d.ts +2 -0
- package/dist/enums/nodeBuilderFlags.d.ts.map +1 -0
- package/dist/enums/nodeBuilderFlags.enum.d.ts +36 -0
- package/dist/enums/nodeBuilderFlags.enum.d.ts.map +1 -0
- package/dist/enums/nodeBuilderFlags.enum.js +38 -0
- package/dist/enums/nodeBuilderFlags.enum.js.map +1 -0
- package/dist/enums/nodeBuilderFlags.js +38 -0
- package/dist/enums/nodeBuilderFlags.js.map +1 -0
- package/dist/enums/nodeFlags.d.ts +2 -0
- package/dist/enums/nodeFlags.d.ts.map +1 -0
- package/dist/enums/nodeFlags.enum.d.ts +44 -0
- package/dist/enums/nodeFlags.enum.d.ts.map +1 -0
- package/dist/enums/nodeFlags.enum.js +46 -0
- package/dist/enums/nodeFlags.enum.js.map +1 -0
- package/dist/enums/nodeFlags.js +46 -0
- package/dist/enums/nodeFlags.js.map +1 -0
- package/dist/enums/objectFlags.d.ts +2 -0
- package/dist/enums/objectFlags.d.ts.map +1 -0
- package/dist/enums/objectFlags.enum.d.ts +51 -0
- package/dist/enums/objectFlags.enum.d.ts.map +1 -0
- package/dist/enums/objectFlags.enum.js +53 -0
- package/dist/enums/objectFlags.enum.js.map +1 -0
- package/dist/enums/objectFlags.js +53 -0
- package/dist/enums/objectFlags.js.map +1 -0
- package/dist/enums/outerExpressionKinds.d.ts +2 -0
- package/dist/enums/outerExpressionKinds.d.ts.map +1 -0
- package/dist/enums/outerExpressionKinds.enum.d.ts +16 -0
- package/dist/enums/outerExpressionKinds.enum.d.ts.map +1 -0
- package/dist/enums/outerExpressionKinds.enum.js +18 -0
- package/dist/enums/outerExpressionKinds.enum.js.map +1 -0
- package/dist/enums/outerExpressionKinds.js +18 -0
- package/dist/enums/outerExpressionKinds.js.map +1 -0
- package/dist/enums/regularExpressionFlags.d.ts +2 -0
- package/dist/enums/regularExpressionFlags.d.ts.map +1 -0
- package/dist/enums/regularExpressionFlags.enum.d.ts +13 -0
- package/dist/enums/regularExpressionFlags.enum.d.ts.map +1 -0
- package/dist/enums/regularExpressionFlags.enum.js +14 -0
- package/dist/enums/regularExpressionFlags.enum.js.map +1 -0
- package/dist/enums/regularExpressionFlags.js +14 -0
- package/dist/enums/regularExpressionFlags.js.map +1 -0
- package/dist/enums/scriptKind.d.ts +2 -0
- package/dist/enums/scriptKind.d.ts.map +1 -0
- package/dist/enums/scriptKind.enum.d.ts +9 -0
- package/dist/enums/scriptKind.enum.d.ts.map +1 -0
- package/dist/enums/scriptKind.enum.js +11 -0
- package/dist/enums/scriptKind.enum.js.map +1 -0
- package/dist/enums/scriptKind.js +11 -0
- package/dist/enums/scriptKind.js.map +1 -0
- package/dist/enums/scriptTarget.d.ts +2 -0
- package/dist/enums/scriptTarget.d.ts.map +1 -0
- package/dist/enums/scriptTarget.enum.d.ts +18 -0
- package/dist/enums/scriptTarget.enum.d.ts.map +1 -0
- package/dist/enums/scriptTarget.enum.js +20 -0
- package/dist/enums/scriptTarget.enum.js.map +1 -0
- package/dist/enums/scriptTarget.js +20 -0
- package/dist/enums/scriptTarget.js.map +1 -0
- package/dist/enums/signatureFlags.d.ts +2 -0
- package/dist/enums/signatureFlags.d.ts.map +1 -0
- package/dist/enums/signatureFlags.enum.d.ts +15 -0
- package/dist/enums/signatureFlags.enum.d.ts.map +1 -0
- package/dist/enums/signatureFlags.enum.js +17 -0
- package/dist/enums/signatureFlags.enum.js.map +1 -0
- package/dist/enums/signatureFlags.js +17 -0
- package/dist/enums/signatureFlags.js.map +1 -0
- package/dist/enums/signatureKind.d.ts +2 -0
- package/dist/enums/signatureKind.d.ts.map +1 -0
- package/dist/enums/signatureKind.enum.d.ts +5 -0
- package/dist/enums/signatureKind.enum.d.ts.map +1 -0
- package/dist/enums/signatureKind.enum.js +7 -0
- package/dist/enums/signatureKind.enum.js.map +1 -0
- package/dist/enums/signatureKind.js +7 -0
- package/dist/enums/signatureKind.js.map +1 -0
- package/dist/enums/spanMapFeature.d.ts +2 -0
- package/dist/enums/spanMapFeature.d.ts.map +1 -0
- package/dist/enums/spanMapFeature.enum.d.ts +25 -0
- package/dist/enums/spanMapFeature.enum.d.ts.map +1 -0
- package/dist/enums/spanMapFeature.enum.js +27 -0
- package/dist/enums/spanMapFeature.enum.js.map +1 -0
- package/dist/enums/spanMapFeature.js +27 -0
- package/dist/enums/spanMapFeature.js.map +1 -0
- package/dist/enums/spanMapFidelity.d.ts +2 -0
- package/dist/enums/spanMapFidelity.d.ts.map +1 -0
- package/dist/enums/spanMapFidelity.enum.d.ts +7 -0
- package/dist/enums/spanMapFidelity.enum.d.ts.map +1 -0
- package/dist/enums/spanMapFidelity.enum.js +9 -0
- package/dist/enums/spanMapFidelity.enum.js.map +1 -0
- package/dist/enums/spanMapFidelity.js +9 -0
- package/dist/enums/spanMapFidelity.js.map +1 -0
- package/dist/enums/spanMapKind.d.ts +2 -0
- package/dist/enums/spanMapKind.d.ts.map +1 -0
- package/dist/enums/spanMapKind.enum.d.ts +6 -0
- package/dist/enums/spanMapKind.enum.d.ts.map +1 -0
- package/dist/enums/spanMapKind.enum.js +8 -0
- package/dist/enums/spanMapKind.enum.js.map +1 -0
- package/dist/enums/spanMapKind.js +8 -0
- package/dist/enums/spanMapKind.js.map +1 -0
- package/dist/enums/symbolFlags.d.ts +2 -0
- package/dist/enums/symbolFlags.d.ts.map +1 -0
- package/dist/enums/symbolFlags.enum.d.ts +70 -0
- package/dist/enums/symbolFlags.enum.d.ts.map +1 -0
- package/dist/enums/symbolFlags.enum.js +72 -0
- package/dist/enums/symbolFlags.enum.js.map +1 -0
- package/dist/enums/symbolFlags.js +72 -0
- package/dist/enums/symbolFlags.js.map +1 -0
- package/dist/enums/symbolOwnerKind.d.ts +2 -0
- package/dist/enums/symbolOwnerKind.d.ts.map +1 -0
- package/dist/enums/symbolOwnerKind.enum.d.ts +5 -0
- package/dist/enums/symbolOwnerKind.enum.d.ts.map +1 -0
- package/dist/enums/symbolOwnerKind.enum.js +7 -0
- package/dist/enums/symbolOwnerKind.enum.js.map +1 -0
- package/dist/enums/symbolOwnerKind.js +7 -0
- package/dist/enums/symbolOwnerKind.js.map +1 -0
- package/dist/enums/syntaxKind.d.ts +2 -0
- package/dist/enums/syntaxKind.d.ts.map +1 -0
- package/dist/enums/syntaxKind.enum.d.ts +390 -0
- package/dist/enums/syntaxKind.enum.d.ts.map +1 -0
- package/dist/enums/syntaxKind.enum.js +392 -0
- package/dist/enums/syntaxKind.enum.js.map +1 -0
- package/dist/enums/syntaxKind.js +392 -0
- package/dist/enums/syntaxKind.js.map +1 -0
- package/dist/enums/tokenFlags.d.ts +2 -0
- package/dist/enums/tokenFlags.d.ts.map +1 -0
- package/dist/enums/tokenFlags.enum.d.ts +30 -0
- package/dist/enums/tokenFlags.enum.d.ts.map +1 -0
- package/dist/enums/tokenFlags.enum.js +32 -0
- package/dist/enums/tokenFlags.enum.js.map +1 -0
- package/dist/enums/tokenFlags.js +32 -0
- package/dist/enums/tokenFlags.js.map +1 -0
- package/dist/enums/typeFlags.d.ts +2 -0
- package/dist/enums/typeFlags.d.ts.map +1 -0
- package/dist/enums/typeFlags.enum.d.ts +76 -0
- package/dist/enums/typeFlags.enum.d.ts.map +1 -0
- package/dist/enums/typeFlags.enum.js +78 -0
- package/dist/enums/typeFlags.enum.js.map +1 -0
- package/dist/enums/typeFlags.js +78 -0
- package/dist/enums/typeFlags.js.map +1 -0
- package/dist/enums/typeFormatFlags.d.ts +2 -0
- package/dist/enums/typeFormatFlags.d.ts.map +1 -0
- package/dist/enums/typeFormatFlags.enum.d.ts +29 -0
- package/dist/enums/typeFormatFlags.enum.d.ts.map +1 -0
- package/dist/enums/typeFormatFlags.enum.js +31 -0
- package/dist/enums/typeFormatFlags.enum.js.map +1 -0
- package/dist/enums/typeFormatFlags.js +31 -0
- package/dist/enums/typeFormatFlags.js.map +1 -0
- package/dist/enums/typePredicateKind.d.ts +2 -0
- package/dist/enums/typePredicateKind.d.ts.map +1 -0
- package/dist/enums/typePredicateKind.enum.d.ts +7 -0
- package/dist/enums/typePredicateKind.enum.d.ts.map +1 -0
- package/dist/enums/typePredicateKind.enum.js +9 -0
- package/dist/enums/typePredicateKind.enum.js.map +1 -0
- package/dist/enums/typePredicateKind.js +9 -0
- package/dist/enums/typePredicateKind.js.map +1 -0
- package/dist/internal/utils.d.ts +23 -0
- package/dist/internal/utils.d.ts.map +1 -0
- package/dist/internal/utils.js +25 -0
- package/dist/internal/utils.js.map +1 -0
- package/dist/vscode/extensionApi.d.ts +100 -0
- package/dist/vscode/extensionApi.d.ts.map +1 -0
- package/dist/vscode/extensionApi.js +2 -0
- package/dist/vscode/extensionApi.js.map +1 -0
- package/dist/vscode/moduleLoader.d.ts +14 -0
- package/dist/vscode/moduleLoader.d.ts.map +1 -0
- package/dist/vscode/moduleLoader.js +36 -0
- package/dist/vscode/moduleLoader.js.map +1 -0
- package/dist/vscode/protocol.generated.d.ts +2886 -0
- package/dist/vscode/protocol.generated.d.ts.map +1 -0
- package/dist/vscode/protocol.generated.js +4 -0
- package/dist/vscode/protocol.generated.js.map +1 -0
- package/lib/getExePath.d.ts +2 -0
- package/lib/getExePath.js +70 -0
- package/lib/install.js +108 -0
- package/lib/tsc.js +28 -0
- package/lib/version.cjs +5 -0
- package/lib/version.d.cts +2 -0
- package/package.json +79 -6
- package/schemas/jsconfig.schema.json +2207 -0
- package/schemas/tsconfig.schema.json +2206 -0
- package/vendor/vscode-jsonrpc/License.txt +11 -0
- package/vendor/vscode-jsonrpc/README.md +54 -0
- package/vendor/vscode-jsonrpc/lib/browser/main.d.ts +17 -0
- package/vendor/vscode-jsonrpc/lib/browser/main.js +83 -0
- package/vendor/vscode-jsonrpc/lib/browser/ril.d.ts +22 -0
- package/vendor/vscode-jsonrpc/lib/browser/ril.js +210 -0
- package/vendor/vscode-jsonrpc/lib/common/api.d.ts +14 -0
- package/vendor/vscode-jsonrpc/lib/common/api.js +87 -0
- package/vendor/vscode-jsonrpc/lib/common/cancellation.d.ts +32 -0
- package/vendor/vscode-jsonrpc/lib/common/cancellation.js +132 -0
- package/vendor/vscode-jsonrpc/lib/common/connection.d.ts +367 -0
- package/vendor/vscode-jsonrpc/lib/common/connection.js +1271 -0
- package/vendor/vscode-jsonrpc/lib/common/disposable.d.ts +9 -0
- package/vendor/vscode-jsonrpc/lib/common/disposable.js +16 -0
- package/vendor/vscode-jsonrpc/lib/common/encoding.d.ts +52 -0
- package/vendor/vscode-jsonrpc/lib/common/encoding.js +70 -0
- package/vendor/vscode-jsonrpc/lib/common/events.d.ts +39 -0
- package/vendor/vscode-jsonrpc/lib/common/events.js +135 -0
- package/vendor/vscode-jsonrpc/lib/common/is.d.ts +7 -0
- package/vendor/vscode-jsonrpc/lib/common/is.js +34 -0
- package/vendor/vscode-jsonrpc/lib/common/linkedMap.d.ts +55 -0
- package/vendor/vscode-jsonrpc/lib/common/linkedMap.js +412 -0
- package/vendor/vscode-jsonrpc/lib/common/messageBuffer.d.ts +18 -0
- package/vendor/vscode-jsonrpc/lib/common/messageBuffer.js +155 -0
- package/vendor/vscode-jsonrpc/lib/common/messageReader.d.ts +77 -0
- package/vendor/vscode-jsonrpc/lib/common/messageReader.js +246 -0
- package/vendor/vscode-jsonrpc/lib/common/messageWriter.d.ts +60 -0
- package/vendor/vscode-jsonrpc/lib/common/messageWriter.js +157 -0
- package/vendor/vscode-jsonrpc/lib/common/messages.d.ts +369 -0
- package/vendor/vscode-jsonrpc/lib/common/messages.js +436 -0
- package/vendor/vscode-jsonrpc/lib/common/ral.d.ts +74 -0
- package/vendor/vscode-jsonrpc/lib/common/ral.js +23 -0
- package/vendor/vscode-jsonrpc/lib/common/semaphore.d.ts +10 -0
- package/vendor/vscode-jsonrpc/lib/common/semaphore.js +74 -0
- package/vendor/vscode-jsonrpc/lib/common/sharedArrayCancellation.d.ts +15 -0
- package/vendor/vscode-jsonrpc/lib/common/sharedArrayCancellation.js +77 -0
- package/vendor/vscode-jsonrpc/lib/node/main.d.ts +58 -0
- package/vendor/vscode-jsonrpc/lib/node/main.js +289 -0
- package/vendor/vscode-jsonrpc/lib/node/ril.d.ts +12 -0
- package/vendor/vscode-jsonrpc/lib/node/ril.js +163 -0
- package/vendor/vscode-jsonrpc/package.json +54 -0
- package/vendor/vscode-jsonrpc/typings/thenable.d.ts +5 -0
|
@@ -0,0 +1,3143 @@
|
|
|
1
|
+
import { CheckFlags } from "#enums/checkFlags";
|
|
2
|
+
import { CompletionItemKind } from "#enums/completionItemKind";
|
|
3
|
+
import { DiagnosticCategory } from "#enums/diagnosticCategory";
|
|
4
|
+
import { ElementFlags } from "#enums/elementFlags";
|
|
5
|
+
import { EmitOnly } from "#enums/emitOnly";
|
|
6
|
+
import { IndexKind } from "#enums/indexKind";
|
|
7
|
+
import { JsxEmit } from "#enums/jsxEmit";
|
|
8
|
+
import { ModuleKind } from "#enums/moduleKind";
|
|
9
|
+
import { ModuleResolutionKind } from "#enums/moduleResolutionKind";
|
|
10
|
+
import { NewLineKind } from "#enums/newLineKind";
|
|
11
|
+
import { NodeBuilderFlags } from "#enums/nodeBuilderFlags";
|
|
12
|
+
import { ObjectFlags } from "#enums/objectFlags";
|
|
13
|
+
import { ScriptKind } from "#enums/scriptKind";
|
|
14
|
+
import { SignatureFlags } from "#enums/signatureFlags";
|
|
15
|
+
import { SignatureKind } from "#enums/signatureKind";
|
|
16
|
+
import { SymbolFlags } from "#enums/symbolFlags";
|
|
17
|
+
import { SymbolOwnerKind } from "#enums/symbolOwnerKind";
|
|
18
|
+
import { TypeFlags } from "#enums/typeFlags";
|
|
19
|
+
import { TypeFormatFlags } from "#enums/typeFormatFlags";
|
|
20
|
+
import { TypePredicateKind } from "#enums/typePredicateKind";
|
|
21
|
+
import { ModifierFlags, unescapeLeadingUnderscores, } from "../../ast/index.js";
|
|
22
|
+
import { assertNever } from "../../internal/utils.js";
|
|
23
|
+
import { encodeNode, uint8ArrayToBase64, } from "../node/encoder.js";
|
|
24
|
+
import { decodeNode, getNodeId, parseNodeHandleFromCompiler, readParseOptionsKey, readSourceFileHash, readSourceFileLease, RemoteNode, RemoteSourceFile, } from "../node/node.js";
|
|
25
|
+
import { Wtf8Decoder } from "../node/wtf8.js";
|
|
26
|
+
import { canonicalize, CaseSensitivity, pathKey, toRootedDirectoryPath, toRootedPath, } from "../path.js";
|
|
27
|
+
import { prepareCompilerOptions } from "../prepareCompilerOptions.generated.js";
|
|
28
|
+
import { resolveFileName, toCreateSnapshotRequest, validateSymbolResponse, } from "../proto.js";
|
|
29
|
+
import { SourceFileCache, } from "../sourceFileCache.js";
|
|
30
|
+
import { Client, } from "./client.js";
|
|
31
|
+
export { formatDiagnostics, formatDiagnosticsWithColorAndContext } from "../diagnosticFormatter.js";
|
|
32
|
+
export { documentURIToFileName, fileNameToDocumentURI } from "../path.js";
|
|
33
|
+
export { CheckFlags, CompletionItemKind, DiagnosticCategory, ElementFlags, EmitOnly, IndexKind, JsxEmit, ModifierFlags, ModuleKind, ModuleResolutionKind, NodeBuilderFlags, ObjectFlags, ScriptKind, SignatureFlags, SignatureKind, SymbolFlags, SymbolOwnerKind, TypeFlags, TypeFormatFlags, TypePredicateKind };
|
|
34
|
+
let nextModuleResolutionCallbackId = 0;
|
|
35
|
+
function registerModuleResolutionCallback(client, callback, getSnapshot) {
|
|
36
|
+
const name = `resolveModuleName/${++nextModuleResolutionCallbackId}`;
|
|
37
|
+
const dispose = client.registerCallback(name, params => {
|
|
38
|
+
const { moduleName, containingDirectory, resolutionMode, snapshot: snapshotId, inProgressSnapshot } = params;
|
|
39
|
+
let snapshot = snapshotId === undefined ? undefined : getSnapshot(snapshotId);
|
|
40
|
+
if (snapshotId !== undefined && snapshot === undefined) {
|
|
41
|
+
throw new Error(`Snapshot ${snapshotId} is inactive`);
|
|
42
|
+
}
|
|
43
|
+
if (inProgressSnapshot !== undefined) {
|
|
44
|
+
snapshot = -inProgressSnapshot;
|
|
45
|
+
}
|
|
46
|
+
return callback(moduleName, containingDirectory, resolutionMode, { snapshot });
|
|
47
|
+
});
|
|
48
|
+
return { name, dispose };
|
|
49
|
+
}
|
|
50
|
+
// @sync-only-start
|
|
51
|
+
// export { all, defer, type APIRequestGenerator, type AnyAPIRequestGenerator, type AllAPIRequestGenerator, type DeferredAPIRequestGenerator, type ExecutedGeneratorsResults } from "./generatorSupport.ts";
|
|
52
|
+
// import {executeRequestGenerators, type ExecutedGeneratorsResults, type AnyAPIRequestGenerator} from "./generatorSupport.ts";
|
|
53
|
+
// import { sourceFileResponseToUint8Array } from "../node/encoder.ts";
|
|
54
|
+
// @sync-only-end
|
|
55
|
+
export class API {
|
|
56
|
+
/** @internal */
|
|
57
|
+
client;
|
|
58
|
+
/** @internal */
|
|
59
|
+
sourceFileCache;
|
|
60
|
+
toPath;
|
|
61
|
+
decoder = new Wtf8Decoder();
|
|
62
|
+
currentDirectory;
|
|
63
|
+
caseSensitivity;
|
|
64
|
+
initialized = false;
|
|
65
|
+
initializing;
|
|
66
|
+
activeSnapshots = new Map();
|
|
67
|
+
activeBuildOrchestrators = new Set();
|
|
68
|
+
activeSourceFileLeases = new Map();
|
|
69
|
+
printer;
|
|
70
|
+
internal;
|
|
71
|
+
constructor(options = {}) {
|
|
72
|
+
this.client = new Client(options);
|
|
73
|
+
this.sourceFileCache = new SourceFileCache();
|
|
74
|
+
this.printer = new Printer(this.client);
|
|
75
|
+
this.internal = new InternalAPI(this.client, () => this.ensureInitialized()); // @sync: this.internal = new InternalAPI(this.client, this.ensureInitialized);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Looks up a remote declaration's binder symbol. Throws for synthesized or configuration ASTs.
|
|
79
|
+
*/
|
|
80
|
+
async getSymbol(declaration) {
|
|
81
|
+
const file = getRemoteSourceFile(declaration);
|
|
82
|
+
if (!file)
|
|
83
|
+
throw new Error(`Source file not found for declaration`);
|
|
84
|
+
const record = file.symbolCache;
|
|
85
|
+
if (!record)
|
|
86
|
+
throw new Error(`Cached source file not found for declaration`);
|
|
87
|
+
const index = parseNodeHandleFromCompiler(getNodeId(declaration)).index;
|
|
88
|
+
const cached = record.symbolsByDeclarationNodeIndex.get(index);
|
|
89
|
+
if (cached)
|
|
90
|
+
return cached;
|
|
91
|
+
// @sync-only-start
|
|
92
|
+
// return this.fetchDeclarationSymbol(record, index);
|
|
93
|
+
// @sync-only-end
|
|
94
|
+
// @sync-skip-block-start
|
|
95
|
+
let request = record.declarationSymbolRequests.get(index);
|
|
96
|
+
if (!request) {
|
|
97
|
+
request = this.fetchDeclarationSymbol(record, index);
|
|
98
|
+
record.declarationSymbolRequests.set(index, request);
|
|
99
|
+
}
|
|
100
|
+
try {
|
|
101
|
+
return await request;
|
|
102
|
+
}
|
|
103
|
+
finally {
|
|
104
|
+
record.declarationSymbolRequests.delete(index);
|
|
105
|
+
}
|
|
106
|
+
// @sync-skip-block-end
|
|
107
|
+
}
|
|
108
|
+
async fetchDeclarationSymbol(record, index) {
|
|
109
|
+
const data = await this.client.apiRequest("getSymbolOfDeclaration", {
|
|
110
|
+
file: record.descriptor,
|
|
111
|
+
index,
|
|
112
|
+
});
|
|
113
|
+
validateSymbolResponse(data);
|
|
114
|
+
const reference = data.reference;
|
|
115
|
+
if (reference.kind !== SymbolOwnerKind.File) {
|
|
116
|
+
throw new Error(`Symbol ${reference.id} is not file-owned`);
|
|
117
|
+
}
|
|
118
|
+
const fileOwner = { record, api: this };
|
|
119
|
+
const symbol = this.sourceFileCache.getOrCreateSymbol(record, reference.file, reference.id, () => new Symbol(data, { kind: SymbolOwnerKind.File, owner: fileOwner }));
|
|
120
|
+
record.symbolsByDeclarationNodeIndex.set(index, symbol);
|
|
121
|
+
return symbol;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Create an API instance from an existing LSP connection's API session.
|
|
125
|
+
* Use this when connecting to an API pipe provided by an LSP server via custom/initializeAPISession.
|
|
126
|
+
*/
|
|
127
|
+
static async fromLSPConnection(options) {
|
|
128
|
+
const api = new API(options);
|
|
129
|
+
await api.ensureInitialized();
|
|
130
|
+
return api;
|
|
131
|
+
}
|
|
132
|
+
// @sync-skip-block-start
|
|
133
|
+
batchContext() {
|
|
134
|
+
return this.client.batchContext();
|
|
135
|
+
}
|
|
136
|
+
// @sync-skip-block-end
|
|
137
|
+
// @sync-only-start
|
|
138
|
+
// batch<T extends readonly AnyAPIRequestGenerator[]>(...requestGenerators: T): ExecutedGeneratorsResults<T> {
|
|
139
|
+
// return executeRequestGenerators(requestGenerators, requests => this.client.batchRequests(requests).responses);
|
|
140
|
+
// }
|
|
141
|
+
// @sync-only-end
|
|
142
|
+
async ensureInitialized() {
|
|
143
|
+
if (this.initialized)
|
|
144
|
+
return;
|
|
145
|
+
return this.initializing ??= this.initializeWorker();
|
|
146
|
+
}
|
|
147
|
+
async initializeWorker() {
|
|
148
|
+
try {
|
|
149
|
+
const response = await this.client.apiRequest("initialize", null);
|
|
150
|
+
this.currentDirectory = response.currentDirectory;
|
|
151
|
+
this.caseSensitivity = response.caseSensitivity;
|
|
152
|
+
this.toPath = (fileName, basePath = response.currentDirectory) => pathKey(toRootedPath(fileName, toRootedDirectoryPath(basePath, response.currentDirectory)), response.caseSensitivity);
|
|
153
|
+
this.initialized = true;
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
this.initializing = undefined;
|
|
157
|
+
throw error;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
getCurrentDirectory() {
|
|
161
|
+
if (this.currentDirectory === undefined) {
|
|
162
|
+
throw new Error("API has not been initialized");
|
|
163
|
+
}
|
|
164
|
+
return this.currentDirectory;
|
|
165
|
+
}
|
|
166
|
+
getCanonicalFileName(fileName) {
|
|
167
|
+
return canonicalize(fileName, this.getCaseSensitivity());
|
|
168
|
+
}
|
|
169
|
+
getCaseSensitivity() {
|
|
170
|
+
if (this.caseSensitivity === undefined) {
|
|
171
|
+
throw new Error("API has not been initialized");
|
|
172
|
+
}
|
|
173
|
+
return this.caseSensitivity;
|
|
174
|
+
}
|
|
175
|
+
getNewLine() {
|
|
176
|
+
return "\n";
|
|
177
|
+
}
|
|
178
|
+
async createBuildOrchestrator(rootNames, buildOrchestratorOptions) {
|
|
179
|
+
await this.ensureInitialized();
|
|
180
|
+
const orchestratorResponse = await this.client.apiRequest("createBuildOrchestrator", {
|
|
181
|
+
...buildOrchestratorOptions,
|
|
182
|
+
...buildOrchestratorOptions.overrideCompilerOptions,
|
|
183
|
+
cwd: buildOrchestratorOptions.cwd === undefined
|
|
184
|
+
? undefined
|
|
185
|
+
: toRootedDirectoryPath(buildOrchestratorOptions.cwd, this.getCurrentDirectory()),
|
|
186
|
+
rootNames,
|
|
187
|
+
});
|
|
188
|
+
const orchestrator = new BuildOrchestrator(this.client, orchestratorResponse, () => {
|
|
189
|
+
this.activeBuildOrchestrators.delete(orchestrator);
|
|
190
|
+
});
|
|
191
|
+
this.activeBuildOrchestrators.add(orchestrator);
|
|
192
|
+
return orchestrator;
|
|
193
|
+
}
|
|
194
|
+
async parseConfigFile(file) {
|
|
195
|
+
await this.ensureInitialized();
|
|
196
|
+
return this.client.apiRequest("parseConfigFile", { file });
|
|
197
|
+
}
|
|
198
|
+
async parseCommandLine(commandLine) {
|
|
199
|
+
await this.ensureInitialized();
|
|
200
|
+
return this.client.apiRequest("parseCommandLine", { commandLine });
|
|
201
|
+
}
|
|
202
|
+
async readConfigFile(file) {
|
|
203
|
+
await this.ensureInitialized();
|
|
204
|
+
return this.client.apiRequest("readConfigFile", { file });
|
|
205
|
+
}
|
|
206
|
+
async parseJsonConfigFileContent(json, options) {
|
|
207
|
+
await this.ensureInitialized();
|
|
208
|
+
return this.client.apiRequest("parseJsonConfigFileContent", { json, ...options });
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Create and retain a source file independently of a program.
|
|
212
|
+
* Dispose the returned lease when the source file no longer needs to remain available remotely.
|
|
213
|
+
*/
|
|
214
|
+
async createSourceFile(fileName, sourceText, options = {}) {
|
|
215
|
+
await this.ensureInitialized();
|
|
216
|
+
const data = await this.client.apiRequestBinary("createSourceFile", { fileName, sourceText, options });
|
|
217
|
+
if (!data) {
|
|
218
|
+
throw new Error("createSourceFile returned no source file");
|
|
219
|
+
}
|
|
220
|
+
return this.retainSourceFileResponse(data);
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Read, create, and retain a source file independently of a program.
|
|
224
|
+
* Dispose the returned lease when the source file no longer needs to remain available remotely.
|
|
225
|
+
*/
|
|
226
|
+
async createSourceFileFromFile(file, options = {}) {
|
|
227
|
+
await this.ensureInitialized();
|
|
228
|
+
const data = await this.client.apiRequestBinary("createSourceFileFromFile", { fileName: resolveFileName(file), options });
|
|
229
|
+
if (!data) {
|
|
230
|
+
throw new Error("createSourceFileFromFile returned no source file");
|
|
231
|
+
}
|
|
232
|
+
return this.retainSourceFileResponse(data);
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Retain an ordinary remote source file independently of the snapshot or lease that produced it.
|
|
236
|
+
*/
|
|
237
|
+
async retainSourceFile(sourceFile) {
|
|
238
|
+
await this.ensureInitialized();
|
|
239
|
+
if (!(sourceFile instanceof RemoteSourceFile)) {
|
|
240
|
+
throw new TypeError("Only remote source files can be retained");
|
|
241
|
+
}
|
|
242
|
+
const cached = this.sourceFileCache.get(sourceFile);
|
|
243
|
+
if (cached && cached !== sourceFile) {
|
|
244
|
+
throw new Error("Source file is no longer the canonical cached instance");
|
|
245
|
+
}
|
|
246
|
+
const result = await this.client.apiRequest("retainSourceFile", { file: sourceFileDescriptor(sourceFile) });
|
|
247
|
+
return this.addSourceFileLease(sourceFile, result.lease);
|
|
248
|
+
}
|
|
249
|
+
retainSourceFileResponse(data) {
|
|
250
|
+
const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
251
|
+
const lease = readSourceFileLease(view);
|
|
252
|
+
try {
|
|
253
|
+
const decoded = new RemoteSourceFile(data, this.decoder, this.client.getTimingCollector(), this);
|
|
254
|
+
return this.addSourceFileLease(decoded, lease);
|
|
255
|
+
}
|
|
256
|
+
catch (error) {
|
|
257
|
+
// @sync-skip-block-start
|
|
258
|
+
void this.client.apiRequest("releaseSourceFile", { lease }).catch(() => { });
|
|
259
|
+
// @sync-skip-block-end
|
|
260
|
+
// @sync-only-start
|
|
261
|
+
// try {
|
|
262
|
+
// this.client.apiRequest("releaseSourceFile", { lease });
|
|
263
|
+
// }
|
|
264
|
+
// catch {}
|
|
265
|
+
// @sync-only-end
|
|
266
|
+
throw error;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
addSourceFileLease(sourceFile, lease) {
|
|
270
|
+
const cached = this.sourceFileCache.setForLease(sourceFile, lease);
|
|
271
|
+
const retained = new RetainedSourceFile(cached, lease, () => {
|
|
272
|
+
this.activeSourceFileLeases.delete(lease);
|
|
273
|
+
this.sourceFileCache.releaseLease(lease);
|
|
274
|
+
});
|
|
275
|
+
this.activeSourceFileLeases.set(lease, retained);
|
|
276
|
+
return retained;
|
|
277
|
+
}
|
|
278
|
+
async transpileModule(input, options = {}) {
|
|
279
|
+
await this.ensureInitialized();
|
|
280
|
+
return this.client.apiRequest("transpileModule", { input, options });
|
|
281
|
+
}
|
|
282
|
+
async transpileModuleFromFile(file, options = {}) {
|
|
283
|
+
await this.ensureInitialized();
|
|
284
|
+
return this.client.apiRequest("transpileModuleFromFile", { fileName: resolveFileName(file), options });
|
|
285
|
+
}
|
|
286
|
+
async transpileDeclaration(input, options = {}) {
|
|
287
|
+
await this.ensureInitialized();
|
|
288
|
+
return this.client.apiRequest("transpileDeclaration", { input, options });
|
|
289
|
+
}
|
|
290
|
+
async transpileDeclarationFromFile(file, options = {}) {
|
|
291
|
+
await this.ensureInitialized();
|
|
292
|
+
return this.client.apiRequest("transpileDeclarationFromFile", { fileName: resolveFileName(file), options });
|
|
293
|
+
}
|
|
294
|
+
async createSnapshot(params) {
|
|
295
|
+
await this.ensureInitialized();
|
|
296
|
+
const requestParams = toCreateSnapshotRequest(this.prepareCreateSnapshotParams(params));
|
|
297
|
+
const data = await this.client.apiRequest("createSnapshot", requestParams);
|
|
298
|
+
const snapshot = new Snapshot(data, this.toPath, this, () => {
|
|
299
|
+
this.activeSnapshots.delete(snapshot.id);
|
|
300
|
+
this.sourceFileCache.releaseSnapshot(snapshot.id);
|
|
301
|
+
}, this.createSnapshotUpdater(() => snapshot), undefined);
|
|
302
|
+
this.activeSnapshots.set(snapshot.id, snapshot);
|
|
303
|
+
return snapshot;
|
|
304
|
+
}
|
|
305
|
+
async updateSnapshot(baseSnapshot, params) {
|
|
306
|
+
await this.ensureInitialized();
|
|
307
|
+
if (this.activeSnapshots.get(baseSnapshot.id) !== baseSnapshot || baseSnapshot.isDisposed()) {
|
|
308
|
+
throw new Error("Cannot update an inactive snapshot");
|
|
309
|
+
}
|
|
310
|
+
const data = await this.client.apiRequest("updateSnapshot", {
|
|
311
|
+
snapshot: baseSnapshot.id,
|
|
312
|
+
changes: toCreateSnapshotRequest(this.prepareCreateSnapshotParams(params)),
|
|
313
|
+
});
|
|
314
|
+
if (data.snapshot === baseSnapshot.id) {
|
|
315
|
+
await this.client.apiRequest("release", { snapshot: data.snapshot });
|
|
316
|
+
return baseSnapshot;
|
|
317
|
+
}
|
|
318
|
+
this.sourceFileCache.retainForSnapshot(data.snapshot, baseSnapshot.id, data.changes);
|
|
319
|
+
const snapshot = new Snapshot(data, this.toPath, this, () => {
|
|
320
|
+
this.activeSnapshots.delete(snapshot.id);
|
|
321
|
+
this.sourceFileCache.releaseSnapshot(snapshot.id);
|
|
322
|
+
}, this.createSnapshotUpdater(() => snapshot), baseSnapshot);
|
|
323
|
+
this.activeSnapshots.set(snapshot.id, snapshot);
|
|
324
|
+
return snapshot;
|
|
325
|
+
}
|
|
326
|
+
prepareCreateSnapshotParams(params) {
|
|
327
|
+
if (!params)
|
|
328
|
+
return undefined;
|
|
329
|
+
const prepareOptions = (options) => {
|
|
330
|
+
if (!options)
|
|
331
|
+
return undefined;
|
|
332
|
+
const { moduleResolver, projectReferences, ...rest } = options;
|
|
333
|
+
moduleResolver?.ensureNotDisposed();
|
|
334
|
+
return {
|
|
335
|
+
...rest,
|
|
336
|
+
moduleResolver: moduleResolver?.id,
|
|
337
|
+
projectReferences: projectReferences?.map(reference => ({
|
|
338
|
+
...reference,
|
|
339
|
+
path: toRootedPath(reference.path, this.getCurrentDirectory()),
|
|
340
|
+
})),
|
|
341
|
+
};
|
|
342
|
+
};
|
|
343
|
+
return {
|
|
344
|
+
...params,
|
|
345
|
+
createPrograms: params.createPrograms?.map(program => ({ ...program, options: prepareOptions(program.options) })),
|
|
346
|
+
reconfigurePrograms: params.reconfigurePrograms?.map(program => ({ ...program, options: prepareOptions(program.options) })),
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
prepareLanguageServerSnapshotChanges(changes) {
|
|
350
|
+
if (!changes)
|
|
351
|
+
return undefined;
|
|
352
|
+
const prepared = this.prepareCreateSnapshotParams(changes);
|
|
353
|
+
return prepared;
|
|
354
|
+
}
|
|
355
|
+
createSnapshotUpdater(getSnapshot) {
|
|
356
|
+
const update = params => this.updateSnapshot(getSnapshot(), params); // @sync: const update = ((params: CreateSnapshotParams) => this.updateSnapshot(getSnapshot(), params)) as SnapshotUpdater;
|
|
357
|
+
// @sync-only-start
|
|
358
|
+
// const owner = this;
|
|
359
|
+
// update.gen = function* (params: CreateSnapshotParams) { return yield* owner.updateSnapshot.gen(getSnapshot(), params); };
|
|
360
|
+
// @sync-only-end
|
|
361
|
+
return update;
|
|
362
|
+
}
|
|
363
|
+
async getCurrentLanguageServerSnapshot(...args) {
|
|
364
|
+
await this.ensureInitialized();
|
|
365
|
+
const changes = args[0];
|
|
366
|
+
const baseSnapshot = args[1];
|
|
367
|
+
if (baseSnapshot && (this.activeSnapshots.get(baseSnapshot.id) !== baseSnapshot || baseSnapshot.isDisposed())) {
|
|
368
|
+
throw new Error("Cannot use an inactive snapshot as a response base");
|
|
369
|
+
}
|
|
370
|
+
const data = await this.client.apiRequest("getCurrentLanguageServerSnapshot", {
|
|
371
|
+
baseSnapshot: baseSnapshot?.id,
|
|
372
|
+
changes: this.prepareLanguageServerSnapshotChanges(changes),
|
|
373
|
+
});
|
|
374
|
+
if (baseSnapshot) {
|
|
375
|
+
this.sourceFileCache.retainForSnapshot(data.snapshot, baseSnapshot.id, data.changes);
|
|
376
|
+
}
|
|
377
|
+
const snapshot = new Snapshot(data, this.toPath, this, () => {
|
|
378
|
+
this.activeSnapshots.delete(snapshot.id);
|
|
379
|
+
this.sourceFileCache.releaseSnapshot(snapshot.id);
|
|
380
|
+
}, this.createSnapshotUpdater(() => snapshot), baseSnapshot);
|
|
381
|
+
this.activeSnapshots.set(snapshot.id, snapshot);
|
|
382
|
+
return snapshot;
|
|
383
|
+
}
|
|
384
|
+
async [globalThis.Symbol.asyncDispose]() {
|
|
385
|
+
await this.close(); // @sync: this.close();
|
|
386
|
+
}
|
|
387
|
+
async close() {
|
|
388
|
+
await this.initializing?.catch(() => { }); // @sync-skip
|
|
389
|
+
try {
|
|
390
|
+
for (const retained of [...this.activeSourceFileLeases.values()]) {
|
|
391
|
+
await retained.dispose();
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
finally {
|
|
395
|
+
try {
|
|
396
|
+
for (const orchestrator of [...this.activeBuildOrchestrators]) {
|
|
397
|
+
await orchestrator.dispose();
|
|
398
|
+
}
|
|
399
|
+
for (const snapshot of [...this.activeSnapshots.values()]) {
|
|
400
|
+
await snapshot.dispose();
|
|
401
|
+
}
|
|
402
|
+
this.sourceFileCache.clear();
|
|
403
|
+
}
|
|
404
|
+
finally {
|
|
405
|
+
await this.client.close(); // always close the underlying connection
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
async createModuleResolver(compilerOptions, options) {
|
|
410
|
+
await this.ensureInitialized();
|
|
411
|
+
const callback = options?.resolveModuleName
|
|
412
|
+
? registerModuleResolutionCallback(this.client, options.resolveModuleName, id => this.activeSnapshots.get(id))
|
|
413
|
+
: undefined;
|
|
414
|
+
try {
|
|
415
|
+
const id = await this.client.apiRequest("createModuleResolver", {
|
|
416
|
+
compilerOptions: prepareCompilerOptions(compilerOptions, this.getCurrentDirectory()),
|
|
417
|
+
moduleResolutions: options?.moduleResolutions,
|
|
418
|
+
resolveModuleNameCallback: callback?.name,
|
|
419
|
+
});
|
|
420
|
+
return new ModuleResolver(id, this.client, callback?.dispose);
|
|
421
|
+
}
|
|
422
|
+
catch (error) {
|
|
423
|
+
callback?.dispose();
|
|
424
|
+
throw error;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
clearSourceFileCache() {
|
|
428
|
+
this.sourceFileCache.clear();
|
|
429
|
+
}
|
|
430
|
+
async runWithTemporaryFileUpdate(baseSnapshot, file, newText, cb) {
|
|
431
|
+
await this.ensureInitialized();
|
|
432
|
+
if (this.activeSnapshots.get(baseSnapshot.id) !== baseSnapshot || baseSnapshot.isDisposed()) {
|
|
433
|
+
throw new Error("Cannot run a temporary file update on an inactive snapshot");
|
|
434
|
+
}
|
|
435
|
+
const snapshot = await baseSnapshot.update({
|
|
436
|
+
fileSystem: {
|
|
437
|
+
kind: "layer",
|
|
438
|
+
files: { [resolveFileName(file)]: newText },
|
|
439
|
+
},
|
|
440
|
+
ensurePrograms: true,
|
|
441
|
+
});
|
|
442
|
+
try {
|
|
443
|
+
await cb(snapshot);
|
|
444
|
+
}
|
|
445
|
+
finally {
|
|
446
|
+
await snapshot.dispose();
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* Returns a snapshot of collected timing information for requests made
|
|
451
|
+
* through this API instance: client-measured round-trip latency and bytes
|
|
452
|
+
* transferred, folded together with the server's own per-request processing
|
|
453
|
+
* time and an estimated transport overhead (round-trip minus server time).
|
|
454
|
+
*
|
|
455
|
+
* Fetching the snapshot issues a lightweight request to the server to
|
|
456
|
+
* retrieve its timing collection. Collection must be enabled via the
|
|
457
|
+
* `collectTiming` option; when it is not, the returned snapshot has
|
|
458
|
+
* `enabled: false` and zeroed totals.
|
|
459
|
+
*/
|
|
460
|
+
getTimingInfo() {
|
|
461
|
+
return this.client.getTimingInfo();
|
|
462
|
+
}
|
|
463
|
+
/** Clears all accumulated timing totals and recent-request history, on both the client and the server. */
|
|
464
|
+
resetTimingInfo() {
|
|
465
|
+
return this.client.resetTimingInfo();
|
|
466
|
+
}
|
|
467
|
+
/** Creates a program from current filesystem state. */
|
|
468
|
+
async createProgram(rootFiles, compilerOptions, createProgramOptions) {
|
|
469
|
+
await this.ensureInitialized();
|
|
470
|
+
const snapshot = await this.createSnapshot({
|
|
471
|
+
createPrograms: [{ rootFiles, compilerOptions, options: createProgramOptions }],
|
|
472
|
+
});
|
|
473
|
+
const program = snapshot.operation.createdPrograms[0];
|
|
474
|
+
if (!program) {
|
|
475
|
+
await snapshot.dispose();
|
|
476
|
+
throw new Error("createProgram did not return a project");
|
|
477
|
+
}
|
|
478
|
+
program.setOwnedSnapshot(snapshot);
|
|
479
|
+
return program;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
function sourceFileDescriptor(sourceFile) {
|
|
483
|
+
return {
|
|
484
|
+
fileName: sourceFile.fileName,
|
|
485
|
+
path: sourceFile.path,
|
|
486
|
+
contentHash: sourceFile.contentHash,
|
|
487
|
+
parseOptionsKey: sourceFile.parseOptionsKey,
|
|
488
|
+
scriptKind: sourceFile.scriptKind,
|
|
489
|
+
nodeId: sourceFile.nodeId,
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
function getRemoteSourceFile(node) {
|
|
493
|
+
if (!(node instanceof RemoteNode))
|
|
494
|
+
return undefined;
|
|
495
|
+
const file = node.getSourceFile();
|
|
496
|
+
return file instanceof RemoteSourceFile && file.api ? file : undefined;
|
|
497
|
+
}
|
|
498
|
+
function getNodeAPI(node) {
|
|
499
|
+
const api = getRemoteSourceFile(node)?.api;
|
|
500
|
+
if (!api)
|
|
501
|
+
return undefined;
|
|
502
|
+
if (!(api instanceof API))
|
|
503
|
+
throw new Error("Source file does not belong to the async API"); // @sync: if (!(api instanceof API)) throw new Error("Source file does not belong to the sync API");
|
|
504
|
+
return api;
|
|
505
|
+
}
|
|
506
|
+
/** Looks up a remote declaration's binder symbol through its API. Throws for non-remote declarations. */
|
|
507
|
+
export async function getSymbol(declaration) {
|
|
508
|
+
const api = getNodeAPI(declaration);
|
|
509
|
+
if (!api)
|
|
510
|
+
throw new Error("Source file not found for declaration");
|
|
511
|
+
return api.getSymbol(declaration);
|
|
512
|
+
}
|
|
513
|
+
// @sync-only-start
|
|
514
|
+
// export declare namespace getSymbol {
|
|
515
|
+
// function gen(declaration: Declaration): Generator<ProtocolRequest, Symbol, ProtocolResponse["result"]>;
|
|
516
|
+
// }
|
|
517
|
+
// getSymbol.gen = function* (declaration: Declaration): Generator<ProtocolRequest, Symbol, ProtocolResponse["result"]> {
|
|
518
|
+
// const api = getNodeAPI(declaration);
|
|
519
|
+
// if (!api) throw new Error("Source file not found for declaration");
|
|
520
|
+
// return yield* api.getSymbol.gen(declaration);
|
|
521
|
+
// };
|
|
522
|
+
// @sync-only-end
|
|
523
|
+
/** An independently retained source file and its disposable remote-lifetime lease. */
|
|
524
|
+
export class RetainedSourceFile {
|
|
525
|
+
sourceFile;
|
|
526
|
+
lease;
|
|
527
|
+
onDispose;
|
|
528
|
+
disposed = false;
|
|
529
|
+
disposePromise;
|
|
530
|
+
constructor(sourceFile, lease, onDispose) {
|
|
531
|
+
this.sourceFile = sourceFile;
|
|
532
|
+
this.lease = lease;
|
|
533
|
+
this.onDispose = onDispose;
|
|
534
|
+
}
|
|
535
|
+
[globalThis.Symbol.asyncDispose]() {
|
|
536
|
+
return this.dispose(); // @sync: this.dispose();
|
|
537
|
+
}
|
|
538
|
+
dispose() {
|
|
539
|
+
return this.disposePromise ??= this.disposeWorker();
|
|
540
|
+
}
|
|
541
|
+
async disposeWorker() {
|
|
542
|
+
if (this.disposed)
|
|
543
|
+
return;
|
|
544
|
+
const api = getNodeAPI(this.sourceFile);
|
|
545
|
+
if (!api)
|
|
546
|
+
throw new Error("Retained source file has no owning API");
|
|
547
|
+
this.disposed = true;
|
|
548
|
+
try {
|
|
549
|
+
await api.client.apiRequest("releaseSourceFile", { lease: this.lease });
|
|
550
|
+
}
|
|
551
|
+
finally {
|
|
552
|
+
this.onDispose();
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
export class InternalAPI {
|
|
557
|
+
client;
|
|
558
|
+
ensureInitialized;
|
|
559
|
+
/** @internal */
|
|
560
|
+
constructor(client, ensureInitialized) {
|
|
561
|
+
this.client = client;
|
|
562
|
+
this.ensureInitialized = ensureInitialized;
|
|
563
|
+
}
|
|
564
|
+
async startCPUProfile(dir) {
|
|
565
|
+
await this.ensureInitialized();
|
|
566
|
+
await this.client.apiRequest("startCPUProfile", { dir });
|
|
567
|
+
}
|
|
568
|
+
async stopCPUProfile() {
|
|
569
|
+
await this.ensureInitialized();
|
|
570
|
+
const result = await this.client.apiRequest("stopCPUProfile", null);
|
|
571
|
+
return result.file;
|
|
572
|
+
}
|
|
573
|
+
async saveHeapProfile(dir) {
|
|
574
|
+
await this.ensureInitialized();
|
|
575
|
+
const result = await this.client.apiRequest("saveHeapProfile", { dir });
|
|
576
|
+
return result.file;
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
export class Snapshot {
|
|
580
|
+
id;
|
|
581
|
+
operation;
|
|
582
|
+
projectMap;
|
|
583
|
+
toPath;
|
|
584
|
+
api;
|
|
585
|
+
disposed = false;
|
|
586
|
+
disposePromise;
|
|
587
|
+
onDispose;
|
|
588
|
+
snapshotRegistry;
|
|
589
|
+
projectDataMap;
|
|
590
|
+
updateSnapshot;
|
|
591
|
+
internal;
|
|
592
|
+
get client() {
|
|
593
|
+
return this.api.client;
|
|
594
|
+
}
|
|
595
|
+
constructor(data, toPath, api, onDispose, updateSnapshot, baseSnapshot) {
|
|
596
|
+
this.id = data.snapshot;
|
|
597
|
+
this.api = api;
|
|
598
|
+
this.toPath = toPath;
|
|
599
|
+
this.onDispose = onDispose;
|
|
600
|
+
this.updateSnapshot = updateSnapshot;
|
|
601
|
+
this.projectMap = new Map();
|
|
602
|
+
const projectDataMap = new Map(baseSnapshot?.projectDataMap);
|
|
603
|
+
for (const projectId of data.changes?.removedProjects ?? []) {
|
|
604
|
+
projectDataMap.delete(projectId);
|
|
605
|
+
}
|
|
606
|
+
for (const projectData of data.projects) {
|
|
607
|
+
projectDataMap.set(projectData.id, projectData);
|
|
608
|
+
}
|
|
609
|
+
this.projectDataMap = new Map([...projectDataMap].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0));
|
|
610
|
+
this.snapshotRegistry = new SnapshotObjectRegistry(this.id);
|
|
611
|
+
for (const projData of this.projectDataMap.values()) {
|
|
612
|
+
const project = new Project(projData, this.id, toPath, api, this.snapshotRegistry);
|
|
613
|
+
this.projectMap.set(projData.id, project);
|
|
614
|
+
}
|
|
615
|
+
this.operation = {
|
|
616
|
+
createdPrograms: data.operation.createdPrograms?.map(projectId => this.requireProject(projectId).program),
|
|
617
|
+
openedFiles: data.operation.openedFiles?.map(result => ({ project: this.requireProject(result.project) })),
|
|
618
|
+
};
|
|
619
|
+
this.internal = new SnapshotInternalAPI(this.id, api.client);
|
|
620
|
+
}
|
|
621
|
+
getProjects() {
|
|
622
|
+
this.ensureNotDisposed();
|
|
623
|
+
return [...this.projectMap.values()];
|
|
624
|
+
}
|
|
625
|
+
getConfiguredProject(configFileName) {
|
|
626
|
+
this.ensureNotDisposed();
|
|
627
|
+
const id = this.toPath(configFileName);
|
|
628
|
+
return this.projectMap.get(id);
|
|
629
|
+
}
|
|
630
|
+
getProject(projectId) {
|
|
631
|
+
this.ensureNotDisposed();
|
|
632
|
+
return this.projectMap.get(projectId);
|
|
633
|
+
}
|
|
634
|
+
getProgram(projectId) {
|
|
635
|
+
return this.getProject(projectId)?.program;
|
|
636
|
+
}
|
|
637
|
+
update(params) {
|
|
638
|
+
this.ensureNotDisposed();
|
|
639
|
+
return this.updateSnapshot(params);
|
|
640
|
+
}
|
|
641
|
+
/**
|
|
642
|
+
* Gets the default project for a given file from the configured projects and
|
|
643
|
+
* inferred project already loaded in the snapshot. Synthetic projects are not
|
|
644
|
+
* considered. Files that have been opened with `openFiles` are guaranteed to
|
|
645
|
+
* have a result.
|
|
646
|
+
*/
|
|
647
|
+
async getDefaultProjectForFile(file) {
|
|
648
|
+
this.ensureNotDisposed();
|
|
649
|
+
const data = await this.client.apiRequest("getDefaultProjectForFile", {
|
|
650
|
+
snapshot: this.id,
|
|
651
|
+
file,
|
|
652
|
+
});
|
|
653
|
+
if (!data)
|
|
654
|
+
return undefined;
|
|
655
|
+
return this.projectMap.get(data.id);
|
|
656
|
+
}
|
|
657
|
+
[globalThis.Symbol.asyncDispose]() {
|
|
658
|
+
return this.dispose(); // @sync: this.dispose();
|
|
659
|
+
}
|
|
660
|
+
dispose() {
|
|
661
|
+
return this.disposePromise ??= this.disposeWorker();
|
|
662
|
+
}
|
|
663
|
+
async disposeWorker() {
|
|
664
|
+
if (this.disposed)
|
|
665
|
+
return;
|
|
666
|
+
this.disposed = true;
|
|
667
|
+
for (const project of this.projectMap.values()) {
|
|
668
|
+
project.dispose();
|
|
669
|
+
}
|
|
670
|
+
this.projectMap.clear();
|
|
671
|
+
this.snapshotRegistry.clear();
|
|
672
|
+
try {
|
|
673
|
+
await this.client.apiRequest("release", { snapshot: this.id });
|
|
674
|
+
}
|
|
675
|
+
finally {
|
|
676
|
+
this.onDispose();
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
isDisposed() {
|
|
680
|
+
return this.disposed;
|
|
681
|
+
}
|
|
682
|
+
ensureNotDisposed() {
|
|
683
|
+
if (this.disposed) {
|
|
684
|
+
throw new Error("Snapshot is disposed");
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
requireProject(projectId) {
|
|
688
|
+
const project = this.projectMap.get(projectId);
|
|
689
|
+
if (!project) {
|
|
690
|
+
throw new Error(`Snapshot operation returned unknown project '${projectId}'`);
|
|
691
|
+
}
|
|
692
|
+
return project;
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
export class ModuleResolver {
|
|
696
|
+
id;
|
|
697
|
+
client;
|
|
698
|
+
disposeCallback;
|
|
699
|
+
disposed = false;
|
|
700
|
+
constructor(id, client, disposeCallback) {
|
|
701
|
+
this.id = id;
|
|
702
|
+
this.client = client;
|
|
703
|
+
this.disposeCallback = disposeCallback;
|
|
704
|
+
}
|
|
705
|
+
async resolveModuleName(moduleName, containingDirectory, resolutionMode, options) {
|
|
706
|
+
this.ensureNotDisposed();
|
|
707
|
+
if (options?.snapshot instanceof Snapshot && options.snapshot.isDisposed()) {
|
|
708
|
+
throw new Error("Snapshot is disposed");
|
|
709
|
+
}
|
|
710
|
+
return this.client.apiRequest("resolveModuleName", {
|
|
711
|
+
snapshot: options?.snapshot instanceof Snapshot ? options.snapshot.id : undefined,
|
|
712
|
+
inProgressSnapshot: typeof options?.snapshot === "number" ? -options.snapshot : undefined,
|
|
713
|
+
resolver: this.id,
|
|
714
|
+
moduleName,
|
|
715
|
+
containingDirectory,
|
|
716
|
+
resolutionMode,
|
|
717
|
+
});
|
|
718
|
+
}
|
|
719
|
+
[globalThis.Symbol.asyncDispose]() {
|
|
720
|
+
return this.dispose();
|
|
721
|
+
}
|
|
722
|
+
async dispose() {
|
|
723
|
+
if (this.disposed)
|
|
724
|
+
return;
|
|
725
|
+
await this.client.apiRequest("releaseModuleResolver", { resolver: this.id });
|
|
726
|
+
this.disposed = true;
|
|
727
|
+
this.disposeCallback?.();
|
|
728
|
+
}
|
|
729
|
+
/** @internal */
|
|
730
|
+
ensureNotDisposed() {
|
|
731
|
+
if (this.disposed)
|
|
732
|
+
throw new Error("ModuleResolver is disposed");
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
class SnapshotObjectRegistry {
|
|
736
|
+
symbols = new Map();
|
|
737
|
+
projectRegistries = new Map();
|
|
738
|
+
snapshotId;
|
|
739
|
+
constructor(snapshotId) {
|
|
740
|
+
this.snapshotId = snapshotId;
|
|
741
|
+
}
|
|
742
|
+
addProjectRegistry(registry) {
|
|
743
|
+
this.projectRegistries.set(registry.project.id, registry);
|
|
744
|
+
}
|
|
745
|
+
getOrCreateSymbol(data) {
|
|
746
|
+
const reference = data.reference;
|
|
747
|
+
if (reference.kind !== SymbolOwnerKind.Snapshot)
|
|
748
|
+
throw new Error(`Symbol ${reference.id} is not snapshot-owned`);
|
|
749
|
+
let symbol = this.symbols.get(reference.id);
|
|
750
|
+
if (!symbol) {
|
|
751
|
+
if (reference.snapshot !== this.snapshotId) {
|
|
752
|
+
throw new Error(`Symbol ${reference.id} belongs to snapshot ${reference.snapshot}, not ${this.snapshotId}`);
|
|
753
|
+
}
|
|
754
|
+
const registry = this.projectRegistries.get(reference.project);
|
|
755
|
+
if (!registry)
|
|
756
|
+
throw new Error(`Symbol ${reference.id} references unknown project '${reference.project}'`);
|
|
757
|
+
symbol = new Symbol(data, { kind: SymbolOwnerKind.Snapshot, registry });
|
|
758
|
+
this.symbols.set(reference.id, symbol);
|
|
759
|
+
}
|
|
760
|
+
return symbol;
|
|
761
|
+
}
|
|
762
|
+
getSymbol(id) {
|
|
763
|
+
return this.symbols.get(id);
|
|
764
|
+
}
|
|
765
|
+
clear() {
|
|
766
|
+
this.symbols.clear();
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
class ProjectObjectRegistry {
|
|
770
|
+
snapshotId;
|
|
771
|
+
project;
|
|
772
|
+
snapshotRegistry;
|
|
773
|
+
types = new Map();
|
|
774
|
+
signatures = new Map();
|
|
775
|
+
disposed = false;
|
|
776
|
+
get client() {
|
|
777
|
+
return this.project.api.client;
|
|
778
|
+
}
|
|
779
|
+
get sourceFileCache() {
|
|
780
|
+
return this.project.api.sourceFileCache;
|
|
781
|
+
}
|
|
782
|
+
constructor(snapshotId, project, snapshotRegistry) {
|
|
783
|
+
this.snapshotId = snapshotId;
|
|
784
|
+
this.project = project;
|
|
785
|
+
this.snapshotRegistry = snapshotRegistry;
|
|
786
|
+
snapshotRegistry.addProjectRegistry(this);
|
|
787
|
+
}
|
|
788
|
+
getOrCreateSymbol(data) {
|
|
789
|
+
this.ensureNotDisposed();
|
|
790
|
+
validateSymbolResponse(data);
|
|
791
|
+
const reference = data.reference;
|
|
792
|
+
if (reference.kind === SymbolOwnerKind.Snapshot) {
|
|
793
|
+
return this.snapshotRegistry.getOrCreateSymbol(data);
|
|
794
|
+
}
|
|
795
|
+
const record = this.sourceFileCache.getOrCreateRecord(reference.file, this.snapshotId, this.project.id);
|
|
796
|
+
return this.sourceFileCache.getOrCreateSymbol(record, reference.file, reference.id, () => new Symbol(data, {
|
|
797
|
+
kind: SymbolOwnerKind.File,
|
|
798
|
+
owner: { record, api: this.project.api },
|
|
799
|
+
}));
|
|
800
|
+
}
|
|
801
|
+
/** Find an already-interned symbol and retain its file record for this registry. */
|
|
802
|
+
getCachedSymbol(reference) {
|
|
803
|
+
this.ensureNotDisposed();
|
|
804
|
+
if (reference.file === undefined) {
|
|
805
|
+
return this.snapshotRegistry.getSymbol(reference.id);
|
|
806
|
+
}
|
|
807
|
+
const record = this.sourceFileCache.findRecord(reference.file);
|
|
808
|
+
const symbol = record?.symbolsById.get(reference.id);
|
|
809
|
+
if (record && symbol) {
|
|
810
|
+
this.sourceFileCache.retainRecord(record, this.snapshotId, this.project.id);
|
|
811
|
+
}
|
|
812
|
+
return symbol;
|
|
813
|
+
}
|
|
814
|
+
getOrCreateType(data) {
|
|
815
|
+
let type = this.types.get(data.id);
|
|
816
|
+
if (!type) {
|
|
817
|
+
type = new TypeObject(data, this);
|
|
818
|
+
this.types.set(data.id, type);
|
|
819
|
+
}
|
|
820
|
+
return type;
|
|
821
|
+
}
|
|
822
|
+
getType(id) {
|
|
823
|
+
return this.types.get(id);
|
|
824
|
+
}
|
|
825
|
+
createNodeHandle(handle) {
|
|
826
|
+
return new NodeHandle(handle, this.project);
|
|
827
|
+
}
|
|
828
|
+
getOrCreateSignature(data) {
|
|
829
|
+
let sig = this.signatures.get(data.id);
|
|
830
|
+
if (!sig) {
|
|
831
|
+
sig = new Signature(data, this.project, this);
|
|
832
|
+
this.signatures.set(data.id, sig);
|
|
833
|
+
}
|
|
834
|
+
return sig;
|
|
835
|
+
}
|
|
836
|
+
getSignature(id) {
|
|
837
|
+
return this.signatures.get(id);
|
|
838
|
+
}
|
|
839
|
+
clear() {
|
|
840
|
+
this.disposed = true;
|
|
841
|
+
this.types.clear();
|
|
842
|
+
this.signatures.clear();
|
|
843
|
+
}
|
|
844
|
+
ensureNotDisposed() {
|
|
845
|
+
if (this.disposed)
|
|
846
|
+
throw new Error("Project object registry is disposed");
|
|
847
|
+
}
|
|
848
|
+
async fetchOptionalType(source, method, handle) {
|
|
849
|
+
if (handle !== false) {
|
|
850
|
+
if (!handle)
|
|
851
|
+
return undefined;
|
|
852
|
+
const cached = this.getType(handle);
|
|
853
|
+
if (cached)
|
|
854
|
+
return cached;
|
|
855
|
+
}
|
|
856
|
+
const data = await this.client.apiRequest(method, {
|
|
857
|
+
snapshot: this.snapshotId,
|
|
858
|
+
project: this.project.id,
|
|
859
|
+
objectId: source.id,
|
|
860
|
+
});
|
|
861
|
+
if (!data)
|
|
862
|
+
return undefined;
|
|
863
|
+
return this.getOrCreateType(data);
|
|
864
|
+
}
|
|
865
|
+
async fetchType(source, method, handle) {
|
|
866
|
+
const result = await this.fetchOptionalType(source, method, handle);
|
|
867
|
+
if (result === undefined)
|
|
868
|
+
throw new Error(`${method} returned no type for ${source.constructor.name} ${source.id}`);
|
|
869
|
+
return result;
|
|
870
|
+
}
|
|
871
|
+
async fetchSymbol(source, method, reference) {
|
|
872
|
+
if (!reference)
|
|
873
|
+
return undefined;
|
|
874
|
+
const cached = this.getCachedSymbol(reference);
|
|
875
|
+
if (cached)
|
|
876
|
+
return cached;
|
|
877
|
+
const data = source instanceof Symbol
|
|
878
|
+
? await this.client.apiRequest(method, { symbol: source.reference })
|
|
879
|
+
: await this.client.apiRequest(method, {
|
|
880
|
+
snapshot: this.snapshotId,
|
|
881
|
+
project: this.project.id,
|
|
882
|
+
objectId: source.id,
|
|
883
|
+
});
|
|
884
|
+
if (!data)
|
|
885
|
+
throw new Error(`${method} returned null symbol for ${source.constructor.name} ${source.id}`);
|
|
886
|
+
return this.getOrCreateSymbol(data);
|
|
887
|
+
}
|
|
888
|
+
async fetchSignature(source, method, handle) {
|
|
889
|
+
if (!handle)
|
|
890
|
+
return undefined;
|
|
891
|
+
const cached = this.getSignature(handle);
|
|
892
|
+
if (cached)
|
|
893
|
+
return cached;
|
|
894
|
+
const data = await this.client.apiRequest(method, {
|
|
895
|
+
snapshot: this.snapshotId,
|
|
896
|
+
project: this.project.id,
|
|
897
|
+
objectId: source.id,
|
|
898
|
+
});
|
|
899
|
+
if (!data)
|
|
900
|
+
throw new Error(`${method} returned null signature for ${source.constructor.name} ${source.id}`);
|
|
901
|
+
return this.getOrCreateSignature(data);
|
|
902
|
+
}
|
|
903
|
+
async fetchTypes(source, method, handles) {
|
|
904
|
+
if (handles) {
|
|
905
|
+
const result = new Array(handles.length);
|
|
906
|
+
let allCached = true;
|
|
907
|
+
for (let i = 0; i < handles.length; i++) {
|
|
908
|
+
const cached = this.getType(handles[i]);
|
|
909
|
+
if (!cached) {
|
|
910
|
+
allCached = false;
|
|
911
|
+
break;
|
|
912
|
+
}
|
|
913
|
+
result[i] = cached;
|
|
914
|
+
}
|
|
915
|
+
if (allCached)
|
|
916
|
+
return result;
|
|
917
|
+
}
|
|
918
|
+
const typesData = await this.client.apiRequest(method, {
|
|
919
|
+
snapshot: this.snapshotId,
|
|
920
|
+
project: this.project.id,
|
|
921
|
+
objectId: source.id,
|
|
922
|
+
});
|
|
923
|
+
if (typesData == null)
|
|
924
|
+
return [];
|
|
925
|
+
else
|
|
926
|
+
return typesData.map(data => this.getOrCreateType(data));
|
|
927
|
+
}
|
|
928
|
+
async fetchSymbols(source, method, references) {
|
|
929
|
+
if (references) {
|
|
930
|
+
const result = new Array(references.length);
|
|
931
|
+
for (let i = 0; i < references.length; i++) {
|
|
932
|
+
const cached = this.getCachedSymbol(references[i]);
|
|
933
|
+
if (!cached) {
|
|
934
|
+
return this.fetchSymbolsFromServer(source, method);
|
|
935
|
+
}
|
|
936
|
+
result[i] = cached;
|
|
937
|
+
}
|
|
938
|
+
return result;
|
|
939
|
+
}
|
|
940
|
+
return this.fetchSymbolsFromServer(source, method);
|
|
941
|
+
}
|
|
942
|
+
async fetchSymbolsFromServer(source, method) {
|
|
943
|
+
const data = source instanceof Symbol
|
|
944
|
+
? await this.client.apiRequest(method, { symbol: source.reference })
|
|
945
|
+
: await this.client.apiRequest(method, {
|
|
946
|
+
snapshot: this.snapshotId,
|
|
947
|
+
project: this.project.id,
|
|
948
|
+
objectId: source.id,
|
|
949
|
+
});
|
|
950
|
+
return data?.map(symbol => this.getOrCreateSymbol(symbol)) ?? [];
|
|
951
|
+
}
|
|
952
|
+
// getBaseTypes is a checker-level endpoint keyed by `type` (not `objectId`),
|
|
953
|
+
// so it cannot go through fetchTypes. This helper reuses that server method.
|
|
954
|
+
async fetchBaseTypes(source) {
|
|
955
|
+
const typesData = await this.client.apiRequest("getBaseTypes", {
|
|
956
|
+
snapshot: this.snapshotId,
|
|
957
|
+
project: this.project.id,
|
|
958
|
+
type: source.id,
|
|
959
|
+
});
|
|
960
|
+
if (typesData == null)
|
|
961
|
+
return [];
|
|
962
|
+
return typesData.map(data => this.getOrCreateType(data));
|
|
963
|
+
}
|
|
964
|
+
async fetchPropertiesOfType(source) {
|
|
965
|
+
const data = await this.client.apiRequest("getPropertiesOfType", {
|
|
966
|
+
snapshot: this.snapshotId,
|
|
967
|
+
project: this.project.id,
|
|
968
|
+
type: source.id,
|
|
969
|
+
});
|
|
970
|
+
return data ? data.map(symbol => this.getOrCreateSymbol(symbol)) : [];
|
|
971
|
+
}
|
|
972
|
+
async fetchApparentPropertiesOfType(source) {
|
|
973
|
+
const data = await this.client.apiRequest("getApparentPropertiesOfType", {
|
|
974
|
+
snapshot: this.snapshotId,
|
|
975
|
+
project: this.project.id,
|
|
976
|
+
objectId: source.id,
|
|
977
|
+
});
|
|
978
|
+
return data ? data.map(symbol => this.getOrCreateSymbol(symbol)) : [];
|
|
979
|
+
}
|
|
980
|
+
async fetchPropertyOfType(source, name) {
|
|
981
|
+
const data = await this.client.apiRequest("getPropertyOfType", {
|
|
982
|
+
snapshot: this.snapshotId,
|
|
983
|
+
project: this.project.id,
|
|
984
|
+
type: source.id,
|
|
985
|
+
name,
|
|
986
|
+
});
|
|
987
|
+
return data ? this.getOrCreateSymbol(data) : undefined;
|
|
988
|
+
}
|
|
989
|
+
async fetchSignaturesOfType(source, kind) {
|
|
990
|
+
const data = await this.client.apiRequest("getSignaturesOfType", {
|
|
991
|
+
snapshot: this.snapshotId,
|
|
992
|
+
project: this.project.id,
|
|
993
|
+
type: source.id,
|
|
994
|
+
kind,
|
|
995
|
+
});
|
|
996
|
+
return data.map(signature => this.getOrCreateSignature(signature));
|
|
997
|
+
}
|
|
998
|
+
async fetchIndexInfosOfType(source) {
|
|
999
|
+
const data = await this.client.apiRequest("getIndexInfosOfType", {
|
|
1000
|
+
snapshot: this.snapshotId,
|
|
1001
|
+
project: this.project.id,
|
|
1002
|
+
type: source.id,
|
|
1003
|
+
});
|
|
1004
|
+
if (!data)
|
|
1005
|
+
return [];
|
|
1006
|
+
return data.map(info => ({
|
|
1007
|
+
keyType: this.getOrCreateType(info.keyType),
|
|
1008
|
+
valueType: this.getOrCreateType(info.valueType),
|
|
1009
|
+
isReadonly: info.isReadonly ?? false,
|
|
1010
|
+
declaration: info.declaration ? new NodeHandle(info.declaration, this.project) : undefined,
|
|
1011
|
+
}));
|
|
1012
|
+
}
|
|
1013
|
+
async fetchTypeParameterAtPosition(source, pos) {
|
|
1014
|
+
const data = await this.client.apiRequest("getTypeParameterAtPosition", {
|
|
1015
|
+
snapshot: this.snapshotId,
|
|
1016
|
+
project: this.project.id,
|
|
1017
|
+
signature: source.id,
|
|
1018
|
+
index: pos,
|
|
1019
|
+
});
|
|
1020
|
+
return this.getOrCreateType(data);
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
export class Project {
|
|
1024
|
+
/** @internal */
|
|
1025
|
+
api;
|
|
1026
|
+
id;
|
|
1027
|
+
configFileName;
|
|
1028
|
+
currentDirectory;
|
|
1029
|
+
dirty;
|
|
1030
|
+
parsedCommandLine;
|
|
1031
|
+
/** @deprecated Use `parsedCommandLine.options`. */
|
|
1032
|
+
compilerOptions;
|
|
1033
|
+
/** @deprecated Use `parsedCommandLine.fileNames`. */
|
|
1034
|
+
rootFiles;
|
|
1035
|
+
program;
|
|
1036
|
+
checker;
|
|
1037
|
+
languageService;
|
|
1038
|
+
snapshotId;
|
|
1039
|
+
constructor(data, snapshotId, toPath, api, snapshotRegistry) {
|
|
1040
|
+
this.id = data.id;
|
|
1041
|
+
this.api = api;
|
|
1042
|
+
this.configFileName = data.configFileName;
|
|
1043
|
+
this.currentDirectory = data.currentDirectory;
|
|
1044
|
+
this.dirty = data.dirty;
|
|
1045
|
+
if (!data.parsedCommandLine?.options) {
|
|
1046
|
+
throw new Error(`Project '${data.configFileName}' has no parsed command line`);
|
|
1047
|
+
}
|
|
1048
|
+
this.parsedCommandLine = data.parsedCommandLine;
|
|
1049
|
+
this.compilerOptions = this.parsedCommandLine.options;
|
|
1050
|
+
this.rootFiles = this.parsedCommandLine.fileNames;
|
|
1051
|
+
this.snapshotId = snapshotId;
|
|
1052
|
+
this.program = new Program(snapshotId, this, toPath);
|
|
1053
|
+
const objectRegistry = new ProjectObjectRegistry(snapshotId, this, snapshotRegistry);
|
|
1054
|
+
this.checker = new Checker(snapshotId, this, objectRegistry);
|
|
1055
|
+
this.languageService = new LanguageService(snapshotId, this, objectRegistry);
|
|
1056
|
+
}
|
|
1057
|
+
/** @deprecated Use `languageService.getImportAdderEdits`. */
|
|
1058
|
+
getImportAdderEdits(file, actions) {
|
|
1059
|
+
return this.languageService.getImportAdderEdits(file, actions);
|
|
1060
|
+
}
|
|
1061
|
+
/** @deprecated Use `languageService.getImportEditsForSymbols`. */
|
|
1062
|
+
getImportEditsForSymbols(file, symbols, options = {}) {
|
|
1063
|
+
return this.languageService.getImportEditsForSymbols(file, symbols, options);
|
|
1064
|
+
}
|
|
1065
|
+
dispose() {
|
|
1066
|
+
this.checker.dispose();
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
export class LanguageService {
|
|
1070
|
+
snapshotId;
|
|
1071
|
+
project;
|
|
1072
|
+
objectRegistry;
|
|
1073
|
+
get client() {
|
|
1074
|
+
return this.project.api.client;
|
|
1075
|
+
}
|
|
1076
|
+
constructor(snapshotId, project, objectRegistry) {
|
|
1077
|
+
this.snapshotId = snapshotId;
|
|
1078
|
+
this.project = project;
|
|
1079
|
+
this.objectRegistry = objectRegistry;
|
|
1080
|
+
}
|
|
1081
|
+
async getImportAdderEdits(file, actions) {
|
|
1082
|
+
const requestActions = actions.map(action => {
|
|
1083
|
+
switch (action.kind) {
|
|
1084
|
+
case "importSymbol":
|
|
1085
|
+
const importSymbolAction = {
|
|
1086
|
+
kind: "importSymbol",
|
|
1087
|
+
symbol: action.symbol.reference,
|
|
1088
|
+
};
|
|
1089
|
+
if (action.isValidTypeOnlyUseSite !== undefined) {
|
|
1090
|
+
importSymbolAction.isValidTypeOnlyUseSite = action.isValidTypeOnlyUseSite;
|
|
1091
|
+
}
|
|
1092
|
+
return importSymbolAction;
|
|
1093
|
+
default:
|
|
1094
|
+
return assertNever(action.kind);
|
|
1095
|
+
}
|
|
1096
|
+
});
|
|
1097
|
+
const data = await this.client.apiRequest("getImportAdderEdits", {
|
|
1098
|
+
snapshot: this.snapshotId,
|
|
1099
|
+
project: this.project.id,
|
|
1100
|
+
file,
|
|
1101
|
+
actions: requestActions,
|
|
1102
|
+
});
|
|
1103
|
+
return data ?? [];
|
|
1104
|
+
}
|
|
1105
|
+
async getImportEditsForSymbols(file, symbols, options = {}) {
|
|
1106
|
+
return this.getImportAdderEdits(file, symbols.map((symbol) => {
|
|
1107
|
+
if (options.isValidTypeOnlyUseSite !== undefined) {
|
|
1108
|
+
return {
|
|
1109
|
+
kind: "importSymbol",
|
|
1110
|
+
symbol,
|
|
1111
|
+
isValidTypeOnlyUseSite: options.isValidTypeOnlyUseSite,
|
|
1112
|
+
};
|
|
1113
|
+
}
|
|
1114
|
+
return {
|
|
1115
|
+
kind: "importSymbol",
|
|
1116
|
+
symbol,
|
|
1117
|
+
};
|
|
1118
|
+
}));
|
|
1119
|
+
}
|
|
1120
|
+
async getReferencedSymbolsForNode(node, position) {
|
|
1121
|
+
const data = await this.client.apiRequest("getReferencedSymbolsForNode", {
|
|
1122
|
+
snapshot: this.snapshotId,
|
|
1123
|
+
project: this.project.id,
|
|
1124
|
+
node: getNodeId(node),
|
|
1125
|
+
position,
|
|
1126
|
+
});
|
|
1127
|
+
return (data ?? []).map(entry => ({
|
|
1128
|
+
definition: new NodeHandle(entry.definition, this.project),
|
|
1129
|
+
symbol: entry.symbol ? this.objectRegistry.getOrCreateSymbol(entry.symbol) : undefined,
|
|
1130
|
+
references: (entry.references ?? []).map(h => new NodeHandle(h, this.project)),
|
|
1131
|
+
}));
|
|
1132
|
+
}
|
|
1133
|
+
async getSignatureUsage(signatureDecl) {
|
|
1134
|
+
const data = await this.client.apiRequest("getSignatureUsages", {
|
|
1135
|
+
snapshot: this.snapshotId,
|
|
1136
|
+
project: this.project.id,
|
|
1137
|
+
signatureDecl: getNodeId(signatureDecl),
|
|
1138
|
+
});
|
|
1139
|
+
return (data ?? []).map(entry => ({
|
|
1140
|
+
name: new NodeHandle(entry.name, this.project),
|
|
1141
|
+
call: entry.call ? new NodeHandle(entry.call, this.project) : undefined,
|
|
1142
|
+
}));
|
|
1143
|
+
}
|
|
1144
|
+
async getCompletionsAtPosition(document, position, options) {
|
|
1145
|
+
const data = await this.client.apiRequest("getCompletionsAtPosition", {
|
|
1146
|
+
snapshot: this.snapshotId,
|
|
1147
|
+
project: this.project.id,
|
|
1148
|
+
file: document,
|
|
1149
|
+
position,
|
|
1150
|
+
triggerCharacter: options?.triggerCharacter,
|
|
1151
|
+
includeSymbol: options?.includeSymbol,
|
|
1152
|
+
});
|
|
1153
|
+
if (!data)
|
|
1154
|
+
return undefined;
|
|
1155
|
+
return {
|
|
1156
|
+
isIncomplete: data.isIncomplete,
|
|
1157
|
+
entries: data.entries.map(e => ({
|
|
1158
|
+
...e,
|
|
1159
|
+
symbol: e.symbol ? this.objectRegistry.getOrCreateSymbol(e.symbol) : undefined,
|
|
1160
|
+
})),
|
|
1161
|
+
};
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
export class Program {
|
|
1165
|
+
/** @internal */
|
|
1166
|
+
snapshotId;
|
|
1167
|
+
id;
|
|
1168
|
+
project;
|
|
1169
|
+
toPath;
|
|
1170
|
+
decoder = new Wtf8Decoder();
|
|
1171
|
+
sourceFileMetadataCache = new Map();
|
|
1172
|
+
ownedSnapshot;
|
|
1173
|
+
disposePromise;
|
|
1174
|
+
get client() {
|
|
1175
|
+
return this.project.api.client;
|
|
1176
|
+
}
|
|
1177
|
+
get sourceFileCache() {
|
|
1178
|
+
return this.project.api.sourceFileCache;
|
|
1179
|
+
}
|
|
1180
|
+
constructor(snapshotId, project, toPath) {
|
|
1181
|
+
this.snapshotId = snapshotId;
|
|
1182
|
+
this.id = project.id;
|
|
1183
|
+
this.project = project;
|
|
1184
|
+
this.toPath = toPath;
|
|
1185
|
+
}
|
|
1186
|
+
getCurrentDirectory() {
|
|
1187
|
+
return this.project.currentDirectory;
|
|
1188
|
+
}
|
|
1189
|
+
getCanonicalFileName(fileName) {
|
|
1190
|
+
return this.project.api.getCanonicalFileName(fileName);
|
|
1191
|
+
}
|
|
1192
|
+
getNewLine() {
|
|
1193
|
+
return this.project.compilerOptions.newLine === NewLineKind.CRLF ? "\r\n" : "\n";
|
|
1194
|
+
}
|
|
1195
|
+
/** @internal */
|
|
1196
|
+
setOwnedSnapshot(snapshot) {
|
|
1197
|
+
this.ownedSnapshot = snapshot;
|
|
1198
|
+
}
|
|
1199
|
+
[globalThis.Symbol.asyncDispose]() {
|
|
1200
|
+
return this.dispose(); // @sync: this.dispose();
|
|
1201
|
+
}
|
|
1202
|
+
dispose() {
|
|
1203
|
+
return this.disposePromise ??= this.disposeWorker();
|
|
1204
|
+
}
|
|
1205
|
+
async disposeWorker() {
|
|
1206
|
+
const snapshot = this.ownedSnapshot;
|
|
1207
|
+
this.ownedSnapshot = undefined;
|
|
1208
|
+
if (snapshot)
|
|
1209
|
+
await snapshot.dispose();
|
|
1210
|
+
}
|
|
1211
|
+
getCompilerOptions() {
|
|
1212
|
+
return this.project.compilerOptions;
|
|
1213
|
+
}
|
|
1214
|
+
async getSourceFile(file) {
|
|
1215
|
+
const fileName = resolveFileName(file);
|
|
1216
|
+
const path = this.pathKeyForFileName(fileName);
|
|
1217
|
+
return this.getSourceFileWorker(file, path);
|
|
1218
|
+
}
|
|
1219
|
+
/**
|
|
1220
|
+
* Returns the source file for an already-canonical path.
|
|
1221
|
+
*
|
|
1222
|
+
* @internal
|
|
1223
|
+
*/
|
|
1224
|
+
getSourceFileByPath(path) {
|
|
1225
|
+
// The wire format is a string, but the cache key remains the supplied
|
|
1226
|
+
// PathKey and is never treated as a RootedPath.
|
|
1227
|
+
return this.getSourceFileWorker(path, path);
|
|
1228
|
+
}
|
|
1229
|
+
async getSourceFileWorker(file, path) {
|
|
1230
|
+
// Check if we already have a retained cache entry for this (snapshot, project) pair
|
|
1231
|
+
const retained = this.sourceFileCache.getRetained(path, this.snapshotId, this.project.id);
|
|
1232
|
+
if (retained) {
|
|
1233
|
+
return retained;
|
|
1234
|
+
}
|
|
1235
|
+
// Fetch from server
|
|
1236
|
+
const binaryData = await this.client.apiRequestBinary("getSourceFile", {
|
|
1237
|
+
snapshot: this.snapshotId,
|
|
1238
|
+
project: this.project.id,
|
|
1239
|
+
file,
|
|
1240
|
+
});
|
|
1241
|
+
if (!binaryData) {
|
|
1242
|
+
return undefined;
|
|
1243
|
+
}
|
|
1244
|
+
// Create a new RemoteSourceFile and cache it (set returns existing if hash matches)
|
|
1245
|
+
const decoded = new RemoteSourceFile(binaryData, this.decoder, this.client.getTimingCollector(), this.project.api);
|
|
1246
|
+
return this.sourceFileCache.set(decoded, this.snapshotId, this.project.id);
|
|
1247
|
+
}
|
|
1248
|
+
async getResolvedModule(file, moduleName, mode) {
|
|
1249
|
+
const result = await this.client.apiRequest("getResolvedModule", {
|
|
1250
|
+
snapshot: this.snapshotId,
|
|
1251
|
+
project: this.project.id,
|
|
1252
|
+
file,
|
|
1253
|
+
moduleName,
|
|
1254
|
+
mode,
|
|
1255
|
+
});
|
|
1256
|
+
return result ?? undefined;
|
|
1257
|
+
}
|
|
1258
|
+
async getModeForUsageLocation(file, usage) {
|
|
1259
|
+
return this.client.apiRequest("getModeForUsageLocation", {
|
|
1260
|
+
snapshot: this.snapshotId,
|
|
1261
|
+
project: this.project.id,
|
|
1262
|
+
file,
|
|
1263
|
+
usage: getNodeId(usage),
|
|
1264
|
+
});
|
|
1265
|
+
}
|
|
1266
|
+
async getModeForResolutionAtIndex(file, index) {
|
|
1267
|
+
return this.client.apiRequest("getModeForResolutionAtIndex", {
|
|
1268
|
+
snapshot: this.snapshotId,
|
|
1269
|
+
project: this.project.id,
|
|
1270
|
+
file,
|
|
1271
|
+
index,
|
|
1272
|
+
});
|
|
1273
|
+
}
|
|
1274
|
+
async getResolvedModuleFromModuleSpecifier(moduleSpecifier, sourceFile) {
|
|
1275
|
+
const result = await this.client.apiRequest("getResolvedModuleFromModuleSpecifier", {
|
|
1276
|
+
snapshot: this.snapshotId,
|
|
1277
|
+
project: this.project.id,
|
|
1278
|
+
moduleSpecifier: getNodeId(moduleSpecifier),
|
|
1279
|
+
sourceFile,
|
|
1280
|
+
});
|
|
1281
|
+
return result ?? undefined;
|
|
1282
|
+
}
|
|
1283
|
+
async getResolvedTypeReferenceDirective(file, typeDirectiveName, mode) {
|
|
1284
|
+
const result = await this.client.apiRequest("getResolvedTypeReferenceDirective", {
|
|
1285
|
+
snapshot: this.snapshotId,
|
|
1286
|
+
project: this.project.id,
|
|
1287
|
+
file,
|
|
1288
|
+
typeDirectiveName,
|
|
1289
|
+
mode,
|
|
1290
|
+
});
|
|
1291
|
+
return result ?? undefined;
|
|
1292
|
+
}
|
|
1293
|
+
async getResolvedTypeReferenceDirectiveFromTypeReferenceDirective(typeReferenceDirective, sourceFile) {
|
|
1294
|
+
const result = await this.client.apiRequest("getResolvedTypeReferenceDirectiveFromTypeReferenceDirective", {
|
|
1295
|
+
snapshot: this.snapshotId,
|
|
1296
|
+
project: this.project.id,
|
|
1297
|
+
sourceFile,
|
|
1298
|
+
typeDirectiveName: typeReferenceDirective.fileName,
|
|
1299
|
+
resolutionMode: typeReferenceDirective.resolutionMode,
|
|
1300
|
+
});
|
|
1301
|
+
return result ?? undefined;
|
|
1302
|
+
}
|
|
1303
|
+
async getSourceFileNames() {
|
|
1304
|
+
const data = await this.client.apiRequest("getSourceFileNames", {
|
|
1305
|
+
snapshot: this.snapshotId,
|
|
1306
|
+
project: this.project.id,
|
|
1307
|
+
});
|
|
1308
|
+
return data ?? [];
|
|
1309
|
+
}
|
|
1310
|
+
/**
|
|
1311
|
+
* Returns program-stored metadata for the given source file, or `undefined` if the file
|
|
1312
|
+
* is not part of the program. Metadata is fetched lazily per file and cached on this
|
|
1313
|
+
* `Program` instance.
|
|
1314
|
+
*/
|
|
1315
|
+
getSourceFileMetadata(file) {
|
|
1316
|
+
return this.getSourceFileMetadataByPath(this.pathKeyForFileName(resolveFileName(file)));
|
|
1317
|
+
}
|
|
1318
|
+
/**
|
|
1319
|
+
* Returns program-stored metadata for the source file at the given path, or `undefined`
|
|
1320
|
+
* if the file is not part of the program. Like {@link getSourceFileMetadata}, but skips
|
|
1321
|
+
* the file name to path conversion. Metadata is fetched lazily per file and cached on
|
|
1322
|
+
* this `Program` instance.
|
|
1323
|
+
*/
|
|
1324
|
+
getSourceFileMetadataByPath(path) {
|
|
1325
|
+
let metadata = this.sourceFileMetadataCache.get(path);
|
|
1326
|
+
if (metadata === undefined) {
|
|
1327
|
+
metadata = this.fetchSourceFileMetadata(path);
|
|
1328
|
+
this.sourceFileMetadataCache.set(path, metadata);
|
|
1329
|
+
}
|
|
1330
|
+
return metadata;
|
|
1331
|
+
}
|
|
1332
|
+
async fetchSourceFileMetadata(path) {
|
|
1333
|
+
// PathKey is serialized as a string; the server deliberately treats all
|
|
1334
|
+
// client-provided path text as untrusted input.
|
|
1335
|
+
const data = await this.client.apiRequest("getSourceFileMetadata", {
|
|
1336
|
+
snapshot: this.snapshotId,
|
|
1337
|
+
project: this.project.id,
|
|
1338
|
+
file: path,
|
|
1339
|
+
});
|
|
1340
|
+
return data ?? undefined;
|
|
1341
|
+
}
|
|
1342
|
+
pathKeyForFileName(fileName) {
|
|
1343
|
+
return this.toPath(fileName, this.project.currentDirectory);
|
|
1344
|
+
}
|
|
1345
|
+
/**
|
|
1346
|
+
* Returns whether the given source file was loaded as part of an external library
|
|
1347
|
+
* (e.g. a dependency resolved from `node_modules`). The underlying program metadata is
|
|
1348
|
+
* fetched lazily per file and cached on this `Program` instance.
|
|
1349
|
+
*/
|
|
1350
|
+
async isSourceFileFromExternalLibrary(file) {
|
|
1351
|
+
const metadata = await this.getSourceFileMetadataByPath(file.path);
|
|
1352
|
+
return metadata?.isFromExternalLibrary ?? false;
|
|
1353
|
+
}
|
|
1354
|
+
/**
|
|
1355
|
+
* Returns whether the given source file is a default library file (e.g. `lib.d.ts`).
|
|
1356
|
+
* The underlying program metadata is fetched lazily per file and cached on this
|
|
1357
|
+
* `Program` instance.
|
|
1358
|
+
*/
|
|
1359
|
+
async isSourceFileDefaultLibrary(file) {
|
|
1360
|
+
const metadata = await this.getSourceFileMetadataByPath(file.path);
|
|
1361
|
+
return metadata?.isDefaultLibrary ?? false;
|
|
1362
|
+
}
|
|
1363
|
+
/**
|
|
1364
|
+
* Get all config source file names associated with this program's project config.
|
|
1365
|
+
* Includes the root config file and any extended config files.
|
|
1366
|
+
*/
|
|
1367
|
+
async getConfigFileNames() {
|
|
1368
|
+
const data = await this.client.apiRequest("getConfigFileNames", {
|
|
1369
|
+
snapshot: this.snapshotId,
|
|
1370
|
+
project: this.project.id,
|
|
1371
|
+
});
|
|
1372
|
+
return data ?? [];
|
|
1373
|
+
}
|
|
1374
|
+
/**
|
|
1375
|
+
* Get a config source file by file name/URI.
|
|
1376
|
+
* This can return the project's root tsconfig file or one of its extended config files.
|
|
1377
|
+
*/
|
|
1378
|
+
async getConfigSourceFile(file) {
|
|
1379
|
+
const binaryData = await this.client.apiRequestBinary("getConfigSourceFile", {
|
|
1380
|
+
snapshot: this.snapshotId,
|
|
1381
|
+
project: this.project.id,
|
|
1382
|
+
file,
|
|
1383
|
+
});
|
|
1384
|
+
if (!binaryData) {
|
|
1385
|
+
return undefined;
|
|
1386
|
+
}
|
|
1387
|
+
return new RemoteSourceFile(binaryData, this.decoder, undefined, this.project.api);
|
|
1388
|
+
}
|
|
1389
|
+
/**
|
|
1390
|
+
* Get syntactic (parse) diagnostics for specific files or all files.
|
|
1391
|
+
* @param file - Optional file(s) to get diagnostics for. If omitted, returns diagnostics for all files.
|
|
1392
|
+
*/
|
|
1393
|
+
async getSyntacticDiagnostics(file) {
|
|
1394
|
+
const files = file === undefined ? undefined
|
|
1395
|
+
: Array.isArray(file) ? file
|
|
1396
|
+
: [file];
|
|
1397
|
+
const data = await this.client.apiRequest("getSyntacticDiagnostics", {
|
|
1398
|
+
snapshot: this.snapshotId,
|
|
1399
|
+
project: this.project.id,
|
|
1400
|
+
files,
|
|
1401
|
+
});
|
|
1402
|
+
return data ?? [];
|
|
1403
|
+
}
|
|
1404
|
+
/**
|
|
1405
|
+
* Get binder diagnostics for specific files or all files.
|
|
1406
|
+
* @param file - Optional file(s) to get diagnostics for. If omitted, returns diagnostics for all files.
|
|
1407
|
+
*/
|
|
1408
|
+
async getBindDiagnostics(file) {
|
|
1409
|
+
const files = file === undefined ? undefined
|
|
1410
|
+
: Array.isArray(file) ? file
|
|
1411
|
+
: [file];
|
|
1412
|
+
const data = await this.client.apiRequest("getBindDiagnostics", {
|
|
1413
|
+
snapshot: this.snapshotId,
|
|
1414
|
+
project: this.project.id,
|
|
1415
|
+
files,
|
|
1416
|
+
});
|
|
1417
|
+
return data ?? [];
|
|
1418
|
+
}
|
|
1419
|
+
/**
|
|
1420
|
+
* Get semantic (type-check) diagnostics for specific files or all files.
|
|
1421
|
+
* @param file - Optional file(s) to get diagnostics for. If omitted, returns diagnostics for all files.
|
|
1422
|
+
*/
|
|
1423
|
+
async getSemanticDiagnostics(file) {
|
|
1424
|
+
const files = file === undefined ? undefined
|
|
1425
|
+
: Array.isArray(file) ? file
|
|
1426
|
+
: [file];
|
|
1427
|
+
const data = await this.client.apiRequest("getSemanticDiagnostics", {
|
|
1428
|
+
snapshot: this.snapshotId,
|
|
1429
|
+
project: this.project.id,
|
|
1430
|
+
files,
|
|
1431
|
+
});
|
|
1432
|
+
return data ?? [];
|
|
1433
|
+
}
|
|
1434
|
+
/**
|
|
1435
|
+
* Get suggestion diagnostics for specific files or all files.
|
|
1436
|
+
* @param file - Optional file(s) to get diagnostics for. If omitted, returns diagnostics for all files.
|
|
1437
|
+
*/
|
|
1438
|
+
async getSuggestionDiagnostics(file) {
|
|
1439
|
+
const files = file === undefined ? undefined
|
|
1440
|
+
: Array.isArray(file) ? file
|
|
1441
|
+
: [file];
|
|
1442
|
+
const data = await this.client.apiRequest("getSuggestionDiagnostics", {
|
|
1443
|
+
snapshot: this.snapshotId,
|
|
1444
|
+
project: this.project.id,
|
|
1445
|
+
files,
|
|
1446
|
+
});
|
|
1447
|
+
return data ?? [];
|
|
1448
|
+
}
|
|
1449
|
+
/**
|
|
1450
|
+
* Get declaration emit diagnostics for specific files or all files.
|
|
1451
|
+
* @param file - Optional file(s) to get diagnostics for. If omitted, returns diagnostics for all files.
|
|
1452
|
+
*/
|
|
1453
|
+
async getDeclarationDiagnostics(file) {
|
|
1454
|
+
const files = file === undefined ? undefined
|
|
1455
|
+
: Array.isArray(file) ? file
|
|
1456
|
+
: [file];
|
|
1457
|
+
const data = await this.client.apiRequest("getDeclarationDiagnostics", {
|
|
1458
|
+
snapshot: this.snapshotId,
|
|
1459
|
+
project: this.project.id,
|
|
1460
|
+
files,
|
|
1461
|
+
});
|
|
1462
|
+
return data ?? [];
|
|
1463
|
+
}
|
|
1464
|
+
/**
|
|
1465
|
+
* Get program-wide diagnostics for the project, including compiler options diagnostics.
|
|
1466
|
+
*/
|
|
1467
|
+
async getProgramDiagnostics() {
|
|
1468
|
+
const data = await this.client.apiRequest("getProgramDiagnostics", {
|
|
1469
|
+
snapshot: this.snapshotId,
|
|
1470
|
+
project: this.project.id,
|
|
1471
|
+
});
|
|
1472
|
+
return data ?? [];
|
|
1473
|
+
}
|
|
1474
|
+
/**
|
|
1475
|
+
* Get global (non-file-specific) semantic diagnostics for the project.
|
|
1476
|
+
*/
|
|
1477
|
+
async getGlobalDiagnostics() {
|
|
1478
|
+
const data = await this.client.apiRequest("getGlobalDiagnostics", {
|
|
1479
|
+
snapshot: this.snapshotId,
|
|
1480
|
+
project: this.project.id,
|
|
1481
|
+
});
|
|
1482
|
+
return data ?? [];
|
|
1483
|
+
}
|
|
1484
|
+
/**
|
|
1485
|
+
* Get config file parsing diagnostics for the project.
|
|
1486
|
+
*/
|
|
1487
|
+
async getConfigFileParsingDiagnostics() {
|
|
1488
|
+
const data = await this.client.apiRequest("getConfigFileParsingDiagnostics", {
|
|
1489
|
+
snapshot: this.snapshotId,
|
|
1490
|
+
project: this.project.id,
|
|
1491
|
+
});
|
|
1492
|
+
return data ?? [];
|
|
1493
|
+
}
|
|
1494
|
+
/**
|
|
1495
|
+
* Emits files to the configured filesystem. Layer and host filesystems are
|
|
1496
|
+
* written through; full filesystems remain immutable and return emitted
|
|
1497
|
+
* files in {@link EmitResult.fileSystem}.
|
|
1498
|
+
*/
|
|
1499
|
+
async emit(emitOnly) {
|
|
1500
|
+
const response = await this.client.apiRequest("emit", {
|
|
1501
|
+
snapshot: this.snapshotId,
|
|
1502
|
+
project: this.project.id,
|
|
1503
|
+
emitOnly,
|
|
1504
|
+
});
|
|
1505
|
+
const fileSystem = response.emittedFilesContents.length
|
|
1506
|
+
? {
|
|
1507
|
+
kind: "layer",
|
|
1508
|
+
files: Object.fromEntries(response.emittedFiles.map((fileName, index) => [fileName, response.emittedFilesContents[index]])),
|
|
1509
|
+
}
|
|
1510
|
+
: undefined;
|
|
1511
|
+
return {
|
|
1512
|
+
emitSkipped: response.emitSkipped,
|
|
1513
|
+
diagnostics: response.diagnostics,
|
|
1514
|
+
emittedFiles: response.emittedFiles,
|
|
1515
|
+
fileSystem,
|
|
1516
|
+
};
|
|
1517
|
+
}
|
|
1518
|
+
/**
|
|
1519
|
+
* Emits files and returns their contents without writing to the filesystem.
|
|
1520
|
+
*/
|
|
1521
|
+
async emitToString(emitOnly) {
|
|
1522
|
+
const response = await this.client.apiRequest("emitToString", {
|
|
1523
|
+
snapshot: this.snapshotId,
|
|
1524
|
+
project: this.project.id,
|
|
1525
|
+
emitOnly,
|
|
1526
|
+
});
|
|
1527
|
+
return toEmitOutput(response);
|
|
1528
|
+
}
|
|
1529
|
+
/**
|
|
1530
|
+
* Gets JavaScript output for selected files regardless of project `noEmit`, `emitDeclarationOnly`, and `noEmitOnError` settings.
|
|
1531
|
+
*/
|
|
1532
|
+
async getJavaScriptEmit(files) {
|
|
1533
|
+
const response = await this.client.apiRequest("getJavaScriptEmit", {
|
|
1534
|
+
snapshot: this.snapshotId,
|
|
1535
|
+
project: this.project.id,
|
|
1536
|
+
files,
|
|
1537
|
+
});
|
|
1538
|
+
return toEmitOutput(response);
|
|
1539
|
+
}
|
|
1540
|
+
/**
|
|
1541
|
+
* Gets declaration output for selected files regardless of project `noEmit`, `declaration`, `emitDeclarationOnly`, and `noEmitOnError` settings.
|
|
1542
|
+
*/
|
|
1543
|
+
async getDeclarationEmit(files) {
|
|
1544
|
+
const response = await this.client.apiRequest("getDeclarationEmit", {
|
|
1545
|
+
snapshot: this.snapshotId,
|
|
1546
|
+
project: this.project.id,
|
|
1547
|
+
files,
|
|
1548
|
+
});
|
|
1549
|
+
return toEmitOutput(response);
|
|
1550
|
+
}
|
|
1551
|
+
getProject() {
|
|
1552
|
+
return this.project;
|
|
1553
|
+
}
|
|
1554
|
+
}
|
|
1555
|
+
export class BuildOrchestrator {
|
|
1556
|
+
client;
|
|
1557
|
+
id;
|
|
1558
|
+
disposed = false;
|
|
1559
|
+
disposePromise;
|
|
1560
|
+
onDispose;
|
|
1561
|
+
constructor(client, orchestratorResponse, onDispose) {
|
|
1562
|
+
this.client = client;
|
|
1563
|
+
this.id = orchestratorResponse.buildOrchestratorID;
|
|
1564
|
+
this.onDispose = onDispose;
|
|
1565
|
+
}
|
|
1566
|
+
[globalThis.Symbol.asyncDispose]() {
|
|
1567
|
+
return this.dispose(); // @sync: this.dispose();
|
|
1568
|
+
}
|
|
1569
|
+
dispose() {
|
|
1570
|
+
return this.disposePromise ??= this.disposeWorker();
|
|
1571
|
+
}
|
|
1572
|
+
async disposeWorker() {
|
|
1573
|
+
if (this.disposed)
|
|
1574
|
+
return;
|
|
1575
|
+
this.disposed = true;
|
|
1576
|
+
try {
|
|
1577
|
+
await this.client.apiRequest("disposeBuildOrchestrator", {
|
|
1578
|
+
buildOrchestratorID: this.id,
|
|
1579
|
+
});
|
|
1580
|
+
}
|
|
1581
|
+
finally {
|
|
1582
|
+
this.onDispose();
|
|
1583
|
+
}
|
|
1584
|
+
}
|
|
1585
|
+
async build(project) {
|
|
1586
|
+
this.ensureNotDisposed();
|
|
1587
|
+
const response = await this.client.apiRequest("build", {
|
|
1588
|
+
buildOrchestratorID: this.id,
|
|
1589
|
+
...(project !== undefined ? { project } : {}),
|
|
1590
|
+
});
|
|
1591
|
+
return response;
|
|
1592
|
+
}
|
|
1593
|
+
async buildReferences(project) {
|
|
1594
|
+
this.ensureNotDisposed();
|
|
1595
|
+
const response = await this.client.apiRequest("buildReferences", {
|
|
1596
|
+
buildOrchestratorID: this.id,
|
|
1597
|
+
project,
|
|
1598
|
+
});
|
|
1599
|
+
return response;
|
|
1600
|
+
}
|
|
1601
|
+
async clean(project) {
|
|
1602
|
+
this.ensureNotDisposed();
|
|
1603
|
+
const response = await this.client.apiRequest("cleanBuild", {
|
|
1604
|
+
buildOrchestratorID: this.id,
|
|
1605
|
+
...(project !== undefined ? { project } : {}),
|
|
1606
|
+
});
|
|
1607
|
+
return response;
|
|
1608
|
+
}
|
|
1609
|
+
async cleanReferences(project) {
|
|
1610
|
+
this.ensureNotDisposed();
|
|
1611
|
+
const response = await this.client.apiRequest("cleanReferences", {
|
|
1612
|
+
buildOrchestratorID: this.id,
|
|
1613
|
+
...(project !== undefined ? { project } : {}),
|
|
1614
|
+
});
|
|
1615
|
+
return response;
|
|
1616
|
+
}
|
|
1617
|
+
isDisposed() {
|
|
1618
|
+
return this.disposed;
|
|
1619
|
+
}
|
|
1620
|
+
ensureNotDisposed() {
|
|
1621
|
+
if (this.disposed) {
|
|
1622
|
+
throw new Error("Build orchestrator is disposed");
|
|
1623
|
+
}
|
|
1624
|
+
}
|
|
1625
|
+
}
|
|
1626
|
+
function toEmitOutput(response) {
|
|
1627
|
+
const outputFiles = new Map();
|
|
1628
|
+
for (const { fileName, ...outputFile } of response.outputFiles) {
|
|
1629
|
+
outputFiles.set(fileName, outputFile);
|
|
1630
|
+
}
|
|
1631
|
+
return {
|
|
1632
|
+
emitSkipped: response.emitSkipped,
|
|
1633
|
+
diagnostics: response.diagnostics,
|
|
1634
|
+
outputFiles,
|
|
1635
|
+
};
|
|
1636
|
+
}
|
|
1637
|
+
export class Checker {
|
|
1638
|
+
snapshotId;
|
|
1639
|
+
project;
|
|
1640
|
+
objectRegistry;
|
|
1641
|
+
wellKnownSymbols;
|
|
1642
|
+
wellKnownSignatures;
|
|
1643
|
+
get client() {
|
|
1644
|
+
return this.project.api.client;
|
|
1645
|
+
}
|
|
1646
|
+
constructor(snapshotId, project, objectRegistry) {
|
|
1647
|
+
this.snapshotId = snapshotId;
|
|
1648
|
+
this.project = project;
|
|
1649
|
+
this.objectRegistry = objectRegistry;
|
|
1650
|
+
}
|
|
1651
|
+
dispose() {
|
|
1652
|
+
this.objectRegistry.clear();
|
|
1653
|
+
}
|
|
1654
|
+
/** Get the merged symbol, or the original symbol if it has not been merged. */
|
|
1655
|
+
async getMergedSymbol(symbol) {
|
|
1656
|
+
const data = await this.client.apiRequest("getMergedSymbol", {
|
|
1657
|
+
snapshot: this.snapshotId,
|
|
1658
|
+
project: this.project.id,
|
|
1659
|
+
symbol: symbol.reference,
|
|
1660
|
+
});
|
|
1661
|
+
return this.objectRegistry.getOrCreateSymbol(data);
|
|
1662
|
+
}
|
|
1663
|
+
/**
|
|
1664
|
+
* Get a node's merged symbol. For a declaration, prefer
|
|
1665
|
+
* {@link Checker.getSymbolOfDeclaration} for a non-nullable result.
|
|
1666
|
+
*/
|
|
1667
|
+
async getSymbolOfNode(node) {
|
|
1668
|
+
const data = await this.client.apiRequest("getSymbolOfNode", {
|
|
1669
|
+
snapshot: this.snapshotId,
|
|
1670
|
+
project: this.project.id,
|
|
1671
|
+
location: getNodeId(node),
|
|
1672
|
+
});
|
|
1673
|
+
return data ? this.objectRegistry.getOrCreateSymbol(data) : undefined;
|
|
1674
|
+
}
|
|
1675
|
+
/** Get a declaration's merged symbol. */
|
|
1676
|
+
async getSymbolOfDeclaration(node) {
|
|
1677
|
+
const data = await this.client.apiRequest("getSymbolOfDeclarationForChecker", {
|
|
1678
|
+
snapshot: this.snapshotId,
|
|
1679
|
+
project: this.project.id,
|
|
1680
|
+
location: getNodeId(node),
|
|
1681
|
+
});
|
|
1682
|
+
// Declarations normally have symbols, but preserve unexpected null results at runtime.
|
|
1683
|
+
return (data && this.objectRegistry.getOrCreateSymbol(data));
|
|
1684
|
+
}
|
|
1685
|
+
/** Get a symbol's merged parent, if any. */
|
|
1686
|
+
async getParentOfSymbol(symbol) {
|
|
1687
|
+
const data = await this.client.apiRequest("getParentOfSymbolForChecker", {
|
|
1688
|
+
snapshot: this.snapshotId,
|
|
1689
|
+
project: this.project.id,
|
|
1690
|
+
symbol: symbol.reference,
|
|
1691
|
+
});
|
|
1692
|
+
return data ? this.objectRegistry.getOrCreateSymbol(data) : undefined;
|
|
1693
|
+
}
|
|
1694
|
+
async getSymbolAtLocation(nodeOrNodes) {
|
|
1695
|
+
if (Array.isArray(nodeOrNodes)) {
|
|
1696
|
+
const data = await this.client.apiRequest("getSymbolsAtLocations", {
|
|
1697
|
+
snapshot: this.snapshotId,
|
|
1698
|
+
project: this.project.id,
|
|
1699
|
+
locations: nodeOrNodes.map(node => getNodeId(node)),
|
|
1700
|
+
});
|
|
1701
|
+
return data.map(d => d ? this.objectRegistry.getOrCreateSymbol(d) : undefined);
|
|
1702
|
+
}
|
|
1703
|
+
const data = await this.client.apiRequest("getSymbolAtLocation", {
|
|
1704
|
+
snapshot: this.snapshotId,
|
|
1705
|
+
project: this.project.id,
|
|
1706
|
+
location: getNodeId(nodeOrNodes),
|
|
1707
|
+
});
|
|
1708
|
+
return data ? this.objectRegistry.getOrCreateSymbol(data) : undefined;
|
|
1709
|
+
}
|
|
1710
|
+
async getSymbolAtPosition(file, positionOrPositions) {
|
|
1711
|
+
if (typeof positionOrPositions === "number") {
|
|
1712
|
+
const data = await this.client.apiRequest("getSymbolAtPosition", {
|
|
1713
|
+
snapshot: this.snapshotId,
|
|
1714
|
+
project: this.project.id,
|
|
1715
|
+
file,
|
|
1716
|
+
position: positionOrPositions,
|
|
1717
|
+
});
|
|
1718
|
+
return data ? this.objectRegistry.getOrCreateSymbol(data) : undefined;
|
|
1719
|
+
}
|
|
1720
|
+
const data = await this.client.apiRequest("getSymbolsAtPositions", {
|
|
1721
|
+
snapshot: this.snapshotId,
|
|
1722
|
+
project: this.project.id,
|
|
1723
|
+
file,
|
|
1724
|
+
positions: positionOrPositions,
|
|
1725
|
+
});
|
|
1726
|
+
return data.map(d => d ? this.objectRegistry.getOrCreateSymbol(d) : undefined);
|
|
1727
|
+
}
|
|
1728
|
+
async getSymbolOfSourceFile(fileOrFiles) {
|
|
1729
|
+
if (Array.isArray(fileOrFiles)) {
|
|
1730
|
+
const data = await this.client.apiRequest("getSymbolsOfSourceFiles", {
|
|
1731
|
+
snapshot: this.snapshotId,
|
|
1732
|
+
project: this.project.id,
|
|
1733
|
+
files: fileOrFiles,
|
|
1734
|
+
});
|
|
1735
|
+
return data.map(d => d ? this.objectRegistry.getOrCreateSymbol(d) : undefined);
|
|
1736
|
+
}
|
|
1737
|
+
const data = await this.client.apiRequest("getSymbolOfSourceFile", {
|
|
1738
|
+
snapshot: this.snapshotId,
|
|
1739
|
+
project: this.project.id,
|
|
1740
|
+
file: fileOrFiles,
|
|
1741
|
+
});
|
|
1742
|
+
return data ? this.objectRegistry.getOrCreateSymbol(data) : undefined;
|
|
1743
|
+
}
|
|
1744
|
+
async getTypeOfSymbol(symbolOrSymbols) {
|
|
1745
|
+
if (Array.isArray(symbolOrSymbols)) {
|
|
1746
|
+
const data = await this.client.apiRequest("getTypesOfSymbols", {
|
|
1747
|
+
snapshot: this.snapshotId,
|
|
1748
|
+
project: this.project.id,
|
|
1749
|
+
symbols: symbolOrSymbols.map(symbol => symbol.reference),
|
|
1750
|
+
});
|
|
1751
|
+
return data.map(d => this.objectRegistry.getOrCreateType(d));
|
|
1752
|
+
}
|
|
1753
|
+
const data = await this.client.apiRequest("getTypeOfSymbol", {
|
|
1754
|
+
snapshot: this.snapshotId,
|
|
1755
|
+
project: this.project.id,
|
|
1756
|
+
symbol: symbolOrSymbols.reference,
|
|
1757
|
+
});
|
|
1758
|
+
return this.objectRegistry.getOrCreateType(data);
|
|
1759
|
+
}
|
|
1760
|
+
/**
|
|
1761
|
+
* Get the declared type of a symbol. Always returns a type; for symbols whose
|
|
1762
|
+
* declared type cannot be determined the checker yields the error type (use
|
|
1763
|
+
* {@link Type.isErrorType} to detect it).
|
|
1764
|
+
*/
|
|
1765
|
+
async getDeclaredTypeOfSymbol(symbol) {
|
|
1766
|
+
const data = await this.client.apiRequest("getDeclaredTypeOfSymbol", {
|
|
1767
|
+
snapshot: this.snapshotId,
|
|
1768
|
+
project: this.project.id,
|
|
1769
|
+
symbol: symbol.reference,
|
|
1770
|
+
});
|
|
1771
|
+
return this.objectRegistry.getOrCreateType(data);
|
|
1772
|
+
}
|
|
1773
|
+
/**
|
|
1774
|
+
* Get the type of a symbol, excluding the missing type when
|
|
1775
|
+
* `exactOptionalPropertyTypes: true` is set; for symbols whose
|
|
1776
|
+
* type cannot be determined the checker yields the error type
|
|
1777
|
+
* (use {@link Type.isErrorType} to detect it).
|
|
1778
|
+
*/
|
|
1779
|
+
async getNonMissingTypeOfSymbol(symbol) {
|
|
1780
|
+
const data = await this.client.apiRequest("getNonMissingTypeOfSymbol", {
|
|
1781
|
+
snapshot: this.snapshotId,
|
|
1782
|
+
project: this.project.id,
|
|
1783
|
+
symbol: symbol.reference,
|
|
1784
|
+
});
|
|
1785
|
+
return this.objectRegistry.getOrCreateType(data);
|
|
1786
|
+
}
|
|
1787
|
+
async getReferencesToSymbolInFile(file, symbol) {
|
|
1788
|
+
const data = await this.client.apiRequest("getReferencesToSymbolInFile", {
|
|
1789
|
+
snapshot: this.snapshotId,
|
|
1790
|
+
project: this.project.id,
|
|
1791
|
+
file,
|
|
1792
|
+
symbol: symbol.reference,
|
|
1793
|
+
});
|
|
1794
|
+
return (data ?? []).map(h => new NodeHandle(h, this.project));
|
|
1795
|
+
}
|
|
1796
|
+
/** @deprecated Use `project.languageService.getReferencedSymbolsForNode`. */
|
|
1797
|
+
getReferencedSymbolsForNode(node, position) {
|
|
1798
|
+
return this.project.languageService.getReferencedSymbolsForNode(node, position);
|
|
1799
|
+
}
|
|
1800
|
+
/** @deprecated Use `project.languageService.getSignatureUsage`. */
|
|
1801
|
+
getSignatureUsage(signatureDecl) {
|
|
1802
|
+
return this.project.languageService.getSignatureUsage(signatureDecl);
|
|
1803
|
+
}
|
|
1804
|
+
/** @deprecated Use `project.languageService.getCompletionsAtPosition`. */
|
|
1805
|
+
getCompletionsAtPosition(document, position, options) {
|
|
1806
|
+
return this.project.languageService.getCompletionsAtPosition(document, position, options);
|
|
1807
|
+
}
|
|
1808
|
+
async getTypeAtLocation(nodeOrNodes) {
|
|
1809
|
+
if (Array.isArray(nodeOrNodes)) {
|
|
1810
|
+
const data = await this.client.apiRequest("getTypeAtLocations", {
|
|
1811
|
+
snapshot: this.snapshotId,
|
|
1812
|
+
project: this.project.id,
|
|
1813
|
+
locations: nodeOrNodes.map(node => getNodeId(node)),
|
|
1814
|
+
});
|
|
1815
|
+
return data.map(d => this.objectRegistry.getOrCreateType(d));
|
|
1816
|
+
}
|
|
1817
|
+
const data = await this.client.apiRequest("getTypeAtLocation", {
|
|
1818
|
+
snapshot: this.snapshotId,
|
|
1819
|
+
project: this.project.id,
|
|
1820
|
+
location: getNodeId(nodeOrNodes),
|
|
1821
|
+
});
|
|
1822
|
+
return this.objectRegistry.getOrCreateType(data);
|
|
1823
|
+
}
|
|
1824
|
+
async getSignaturesOfType(type, kind) {
|
|
1825
|
+
return kind === SignatureKind.Call ? type.getCallSignatures() : type.getConstructSignatures();
|
|
1826
|
+
}
|
|
1827
|
+
/**
|
|
1828
|
+
* Get the resolved signature of a call-like expression. Always returns a
|
|
1829
|
+
* signature; when a call cannot be resolved the checker yields the unknown
|
|
1830
|
+
* signature (use {@link Checker.isUnknownSignature} to detect it).
|
|
1831
|
+
*/
|
|
1832
|
+
async getResolvedSignature(node) {
|
|
1833
|
+
const data = await this.client.apiRequest("getResolvedSignature", {
|
|
1834
|
+
snapshot: this.snapshotId,
|
|
1835
|
+
project: this.project.id,
|
|
1836
|
+
location: getNodeId(node),
|
|
1837
|
+
});
|
|
1838
|
+
return this.objectRegistry.getOrCreateSignature(data);
|
|
1839
|
+
}
|
|
1840
|
+
async getTypeAtPosition(file, positionOrPositions) {
|
|
1841
|
+
if (typeof positionOrPositions === "number") {
|
|
1842
|
+
const data = await this.client.apiRequest("getTypeAtPosition", {
|
|
1843
|
+
snapshot: this.snapshotId,
|
|
1844
|
+
project: this.project.id,
|
|
1845
|
+
file,
|
|
1846
|
+
position: positionOrPositions,
|
|
1847
|
+
});
|
|
1848
|
+
return data ? this.objectRegistry.getOrCreateType(data) : undefined;
|
|
1849
|
+
}
|
|
1850
|
+
const data = await this.client.apiRequest("getTypesAtPositions", {
|
|
1851
|
+
snapshot: this.snapshotId,
|
|
1852
|
+
project: this.project.id,
|
|
1853
|
+
file,
|
|
1854
|
+
positions: positionOrPositions,
|
|
1855
|
+
});
|
|
1856
|
+
return data.map(d => d ? this.objectRegistry.getOrCreateType(d) : undefined);
|
|
1857
|
+
}
|
|
1858
|
+
async resolveName(name, meaning, location, excludeGlobals) {
|
|
1859
|
+
// Distinguish Node (has `kind`) from DocumentPosition (has `document` and `position`)
|
|
1860
|
+
const isNode = location && "kind" in location;
|
|
1861
|
+
const data = await this.client.apiRequest("resolveName", {
|
|
1862
|
+
snapshot: this.snapshotId,
|
|
1863
|
+
project: this.project.id,
|
|
1864
|
+
name,
|
|
1865
|
+
meaning,
|
|
1866
|
+
location: isNode ? getNodeId(location) : undefined,
|
|
1867
|
+
file: !isNode && location ? location.document : undefined,
|
|
1868
|
+
position: !isNode && location ? location.position : undefined,
|
|
1869
|
+
excludeGlobals,
|
|
1870
|
+
});
|
|
1871
|
+
return data ? this.objectRegistry.getOrCreateSymbol(data) : undefined;
|
|
1872
|
+
}
|
|
1873
|
+
/**
|
|
1874
|
+
* Returns all symbols with the given meaning that are visible at `location`.
|
|
1875
|
+
*/
|
|
1876
|
+
async getSymbolsInScope(location, meaning) {
|
|
1877
|
+
// Distinguish Node (has `kind`) from DocumentPosition (has `document` and `position`)
|
|
1878
|
+
const isNode = "kind" in location;
|
|
1879
|
+
const data = await this.client.apiRequest("getSymbolsInScope", {
|
|
1880
|
+
snapshot: this.snapshotId,
|
|
1881
|
+
project: this.project.id,
|
|
1882
|
+
meaning,
|
|
1883
|
+
location: isNode ? getNodeId(location) : undefined,
|
|
1884
|
+
file: isNode ? undefined : location.document,
|
|
1885
|
+
position: isNode ? undefined : location.position,
|
|
1886
|
+
});
|
|
1887
|
+
return data ? data.map(d => this.objectRegistry.getOrCreateSymbol(d)) : [];
|
|
1888
|
+
}
|
|
1889
|
+
async getResolvedSymbol(node) {
|
|
1890
|
+
const text = node.text;
|
|
1891
|
+
if (!text)
|
|
1892
|
+
return undefined;
|
|
1893
|
+
return this.resolveName(text, SymbolFlags.Value | SymbolFlags.ExportValue, node);
|
|
1894
|
+
}
|
|
1895
|
+
async getContextualType(node) {
|
|
1896
|
+
const data = await this.client.apiRequest("getContextualType", {
|
|
1897
|
+
snapshot: this.snapshotId,
|
|
1898
|
+
project: this.project.id,
|
|
1899
|
+
location: getNodeId(node),
|
|
1900
|
+
});
|
|
1901
|
+
return data ? this.objectRegistry.getOrCreateType(data) : undefined;
|
|
1902
|
+
}
|
|
1903
|
+
async getContextualTypeForArgumentAtIndex(node, argIndex) {
|
|
1904
|
+
const data = await this.client.apiRequest("getContextualTypeForArgument", {
|
|
1905
|
+
snapshot: this.snapshotId,
|
|
1906
|
+
project: this.project.id,
|
|
1907
|
+
location: getNodeId(node),
|
|
1908
|
+
index: argIndex,
|
|
1909
|
+
});
|
|
1910
|
+
return data ? this.objectRegistry.getOrCreateType(data) : undefined;
|
|
1911
|
+
}
|
|
1912
|
+
async getAwaitedType(type) {
|
|
1913
|
+
const data = await this.client.apiRequest("getAwaitedType", {
|
|
1914
|
+
snapshot: this.snapshotId,
|
|
1915
|
+
project: this.project.id,
|
|
1916
|
+
type: type.id,
|
|
1917
|
+
});
|
|
1918
|
+
return data ? this.objectRegistry.getOrCreateType(data) : undefined;
|
|
1919
|
+
}
|
|
1920
|
+
/** Get the base type of a literal type (e.g. `number` for `42`). Always returns a type. */
|
|
1921
|
+
async getBaseTypeOfLiteralType(type) {
|
|
1922
|
+
const data = await this.client.apiRequest("getBaseTypeOfLiteralType", {
|
|
1923
|
+
snapshot: this.snapshotId,
|
|
1924
|
+
project: this.project.id,
|
|
1925
|
+
type: type.id,
|
|
1926
|
+
});
|
|
1927
|
+
return this.objectRegistry.getOrCreateType(data);
|
|
1928
|
+
}
|
|
1929
|
+
/** Get the type with `null` and `undefined` removed. Always returns a type. */
|
|
1930
|
+
async getNonNullableType(type) {
|
|
1931
|
+
return type.getNonNullableType();
|
|
1932
|
+
}
|
|
1933
|
+
/**
|
|
1934
|
+
* Get the type for a type node. Always returns a type; for type nodes whose
|
|
1935
|
+
* type cannot be determined the checker yields the error type (use
|
|
1936
|
+
* {@link Type.isErrorType} to detect it).
|
|
1937
|
+
*/
|
|
1938
|
+
async getTypeFromTypeNode(node) {
|
|
1939
|
+
const data = await this.client.apiRequest("getTypeFromTypeNode", {
|
|
1940
|
+
snapshot: this.snapshotId,
|
|
1941
|
+
project: this.project.id,
|
|
1942
|
+
location: getNodeId(node),
|
|
1943
|
+
});
|
|
1944
|
+
return this.objectRegistry.getOrCreateType(data);
|
|
1945
|
+
}
|
|
1946
|
+
/** Get the widened type. Always returns a type. */
|
|
1947
|
+
async getWidenedType(type) {
|
|
1948
|
+
const data = await this.client.apiRequest("getWidenedType", {
|
|
1949
|
+
snapshot: this.snapshotId,
|
|
1950
|
+
project: this.project.id,
|
|
1951
|
+
type: type.id,
|
|
1952
|
+
});
|
|
1953
|
+
return this.objectRegistry.getOrCreateType(data);
|
|
1954
|
+
}
|
|
1955
|
+
/**
|
|
1956
|
+
* Get the type of the parameter at the given index in a signature. Always
|
|
1957
|
+
* returns a type; an out-of-range index yields the `any` type.
|
|
1958
|
+
*/
|
|
1959
|
+
async getParameterType(signature, index) {
|
|
1960
|
+
const data = await this.client.apiRequest("getParameterType", {
|
|
1961
|
+
snapshot: this.snapshotId,
|
|
1962
|
+
project: this.project.id,
|
|
1963
|
+
signature: signature.id,
|
|
1964
|
+
index,
|
|
1965
|
+
});
|
|
1966
|
+
return this.objectRegistry.getOrCreateType(data);
|
|
1967
|
+
}
|
|
1968
|
+
async isArrayLikeType(type) {
|
|
1969
|
+
return this.client.apiRequest("isArrayLikeType", {
|
|
1970
|
+
snapshot: this.snapshotId,
|
|
1971
|
+
project: this.project.id,
|
|
1972
|
+
type: type.id,
|
|
1973
|
+
});
|
|
1974
|
+
}
|
|
1975
|
+
async isTypeAssignableTo(source, target) {
|
|
1976
|
+
return this.client.apiRequest("isTypeAssignableTo", {
|
|
1977
|
+
snapshot: this.snapshotId,
|
|
1978
|
+
project: this.project.id,
|
|
1979
|
+
source: source.id,
|
|
1980
|
+
target: target.id,
|
|
1981
|
+
});
|
|
1982
|
+
}
|
|
1983
|
+
async getShorthandAssignmentValueSymbol(node) {
|
|
1984
|
+
const data = await this.client.apiRequest("getShorthandAssignmentValueSymbol", {
|
|
1985
|
+
snapshot: this.snapshotId,
|
|
1986
|
+
project: this.project.id,
|
|
1987
|
+
location: getNodeId(node),
|
|
1988
|
+
});
|
|
1989
|
+
return data ? this.objectRegistry.getOrCreateSymbol(data) : undefined;
|
|
1990
|
+
}
|
|
1991
|
+
/**
|
|
1992
|
+
* Get the type of a symbol as narrowed at a specific location. Always returns
|
|
1993
|
+
* a type; for symbols whose type cannot be determined the checker yields the
|
|
1994
|
+
* error type (use {@link Type.isErrorType} to detect it).
|
|
1995
|
+
*/
|
|
1996
|
+
async getTypeOfSymbolAtLocation(symbol, location) {
|
|
1997
|
+
const data = await this.client.apiRequest("getTypeOfSymbolAtLocation", {
|
|
1998
|
+
snapshot: this.snapshotId,
|
|
1999
|
+
project: this.project.id,
|
|
2000
|
+
symbol: symbol.reference,
|
|
2001
|
+
location: getNodeId(location),
|
|
2002
|
+
});
|
|
2003
|
+
return this.objectRegistry.getOrCreateType(data);
|
|
2004
|
+
}
|
|
2005
|
+
async getIntrinsicType(method) {
|
|
2006
|
+
const data = await this.client.apiRequest(method, {
|
|
2007
|
+
snapshot: this.snapshotId,
|
|
2008
|
+
project: this.project.id,
|
|
2009
|
+
});
|
|
2010
|
+
return this.objectRegistry.getOrCreateType(data);
|
|
2011
|
+
}
|
|
2012
|
+
async getAnyType() {
|
|
2013
|
+
return this.getIntrinsicType("getAnyType");
|
|
2014
|
+
}
|
|
2015
|
+
async getStringType() {
|
|
2016
|
+
return this.getIntrinsicType("getStringType");
|
|
2017
|
+
}
|
|
2018
|
+
async getNumberType() {
|
|
2019
|
+
return this.getIntrinsicType("getNumberType");
|
|
2020
|
+
}
|
|
2021
|
+
async getBooleanType() {
|
|
2022
|
+
return this.getIntrinsicType("getBooleanType");
|
|
2023
|
+
}
|
|
2024
|
+
async getVoidType() {
|
|
2025
|
+
return this.getIntrinsicType("getVoidType");
|
|
2026
|
+
}
|
|
2027
|
+
async getUndefinedType() {
|
|
2028
|
+
return this.getIntrinsicType("getUndefinedType");
|
|
2029
|
+
}
|
|
2030
|
+
async getNullType() {
|
|
2031
|
+
return this.getIntrinsicType("getNullType");
|
|
2032
|
+
}
|
|
2033
|
+
async getNeverType() {
|
|
2034
|
+
return this.getIntrinsicType("getNeverType");
|
|
2035
|
+
}
|
|
2036
|
+
async getUnknownType() {
|
|
2037
|
+
return this.getIntrinsicType("getUnknownType");
|
|
2038
|
+
}
|
|
2039
|
+
async getBigIntType() {
|
|
2040
|
+
return this.getIntrinsicType("getBigIntType");
|
|
2041
|
+
}
|
|
2042
|
+
async getESSymbolType() {
|
|
2043
|
+
return this.getIntrinsicType("getESSymbolType");
|
|
2044
|
+
}
|
|
2045
|
+
async getNonPrimitiveType() {
|
|
2046
|
+
return this.getIntrinsicType("getNonPrimitiveType");
|
|
2047
|
+
}
|
|
2048
|
+
async typeToTypeNode(type, enclosingDeclaration, flags) {
|
|
2049
|
+
const binaryData = await this.client.apiRequestBinary("typeToTypeNode", {
|
|
2050
|
+
snapshot: this.snapshotId,
|
|
2051
|
+
project: this.project.id,
|
|
2052
|
+
type: type.id,
|
|
2053
|
+
location: enclosingDeclaration ? getNodeId(enclosingDeclaration) : undefined,
|
|
2054
|
+
flags,
|
|
2055
|
+
});
|
|
2056
|
+
if (!binaryData)
|
|
2057
|
+
return undefined;
|
|
2058
|
+
return decodeNode(binaryData);
|
|
2059
|
+
}
|
|
2060
|
+
async signatureToSignatureDeclaration(signature, kind, enclosingDeclaration, flags) {
|
|
2061
|
+
const binaryData = await this.client.apiRequestBinary("signatureToSignatureDeclaration", {
|
|
2062
|
+
snapshot: this.snapshotId,
|
|
2063
|
+
project: this.project.id,
|
|
2064
|
+
signature: signature.id,
|
|
2065
|
+
kind,
|
|
2066
|
+
location: enclosingDeclaration ? getNodeId(enclosingDeclaration) : undefined,
|
|
2067
|
+
flags,
|
|
2068
|
+
});
|
|
2069
|
+
if (!binaryData)
|
|
2070
|
+
return undefined;
|
|
2071
|
+
return decodeNode(binaryData);
|
|
2072
|
+
}
|
|
2073
|
+
async typeToString(type, enclosingDeclaration, flags) {
|
|
2074
|
+
const result = await this.client.apiRequest("typeToString", {
|
|
2075
|
+
snapshot: this.snapshotId,
|
|
2076
|
+
project: this.project.id,
|
|
2077
|
+
type: type.id,
|
|
2078
|
+
location: enclosingDeclaration ? getNodeId(enclosingDeclaration) : undefined,
|
|
2079
|
+
flags,
|
|
2080
|
+
});
|
|
2081
|
+
if (typeof result !== "string")
|
|
2082
|
+
throw new TypeError("typeToString returned a non-string result");
|
|
2083
|
+
return result;
|
|
2084
|
+
}
|
|
2085
|
+
async isContextSensitive(node) {
|
|
2086
|
+
return this.client.apiRequest("isContextSensitive", {
|
|
2087
|
+
snapshot: this.snapshotId,
|
|
2088
|
+
project: this.project.id,
|
|
2089
|
+
location: getNodeId(node),
|
|
2090
|
+
});
|
|
2091
|
+
}
|
|
2092
|
+
async isArrayType(type) {
|
|
2093
|
+
return this.client.apiRequest("isArrayType", {
|
|
2094
|
+
snapshot: this.snapshotId,
|
|
2095
|
+
project: this.project.id,
|
|
2096
|
+
type: type.id,
|
|
2097
|
+
});
|
|
2098
|
+
}
|
|
2099
|
+
async isTupleType(type) {
|
|
2100
|
+
return type.isTupleType();
|
|
2101
|
+
}
|
|
2102
|
+
async isTupleTypeTarget(type) {
|
|
2103
|
+
return type.isTupleTypeTarget();
|
|
2104
|
+
}
|
|
2105
|
+
/**
|
|
2106
|
+
* The following symbols are considered read-only:
|
|
2107
|
+
* - Properties with a `readonly` modifier
|
|
2108
|
+
* - Variables declared with `const`
|
|
2109
|
+
* - Get accessors without matching set accessors
|
|
2110
|
+
* - Enum members
|
|
2111
|
+
* - `Object.defineProperty` assignments with `writable: false` or no setter
|
|
2112
|
+
* - Unions and intersections of the above
|
|
2113
|
+
*/
|
|
2114
|
+
async isReadonlySymbol(symbol) {
|
|
2115
|
+
return this.client.apiRequest("isReadonlySymbol", {
|
|
2116
|
+
snapshot: this.snapshotId,
|
|
2117
|
+
project: this.project.id,
|
|
2118
|
+
symbol: symbol.reference,
|
|
2119
|
+
});
|
|
2120
|
+
}
|
|
2121
|
+
/** Get the return type of a signature. Always returns a type. */
|
|
2122
|
+
async getReturnTypeOfSignature(signature) {
|
|
2123
|
+
return signature.getReturnType();
|
|
2124
|
+
}
|
|
2125
|
+
/**
|
|
2126
|
+
* Get the rest type of a signature. Always returns a type; a signature with
|
|
2127
|
+
* no rest parameter yields the `any` type.
|
|
2128
|
+
*/
|
|
2129
|
+
async getRestTypeOfSignature(signature) {
|
|
2130
|
+
const data = await this.client.apiRequest("getRestTypeOfSignature", {
|
|
2131
|
+
snapshot: this.snapshotId,
|
|
2132
|
+
project: this.project.id,
|
|
2133
|
+
signature: signature.id,
|
|
2134
|
+
});
|
|
2135
|
+
return this.objectRegistry.getOrCreateType(data);
|
|
2136
|
+
}
|
|
2137
|
+
async getTypePredicateOfSignature(signature) {
|
|
2138
|
+
const data = await this.client.apiRequest("getTypePredicateOfSignature", {
|
|
2139
|
+
snapshot: this.snapshotId,
|
|
2140
|
+
project: this.project.id,
|
|
2141
|
+
signature: signature.id,
|
|
2142
|
+
});
|
|
2143
|
+
if (!data)
|
|
2144
|
+
return undefined;
|
|
2145
|
+
return {
|
|
2146
|
+
kind: data.kind,
|
|
2147
|
+
parameterIndex: data.parameterIndex,
|
|
2148
|
+
parameterName: data.parameterName,
|
|
2149
|
+
type: data.type ? this.objectRegistry.getOrCreateType(data.type) : undefined,
|
|
2150
|
+
};
|
|
2151
|
+
}
|
|
2152
|
+
/**
|
|
2153
|
+
* Get the base types of a class or interface type. A type with no base types
|
|
2154
|
+
* yields an empty array.
|
|
2155
|
+
*/
|
|
2156
|
+
async getBaseTypes(type) {
|
|
2157
|
+
return await type.getBaseTypes() ?? [];
|
|
2158
|
+
}
|
|
2159
|
+
/** Get the apparent type of a type. Always returns a type. */
|
|
2160
|
+
async getApparentType(type) {
|
|
2161
|
+
return type.getApparentType();
|
|
2162
|
+
}
|
|
2163
|
+
/** Get the reduced type of a type. Always returns a type. */
|
|
2164
|
+
async getReducedType(type) {
|
|
2165
|
+
return type.getReducedType();
|
|
2166
|
+
}
|
|
2167
|
+
async getPropertiesOfType(type) {
|
|
2168
|
+
return type.getProperties();
|
|
2169
|
+
}
|
|
2170
|
+
async getIndexInfosOfType(type) {
|
|
2171
|
+
return type.getIndexInfos();
|
|
2172
|
+
}
|
|
2173
|
+
async getIndexInfoOfType(type, kind) {
|
|
2174
|
+
const data = await this.client.apiRequest("getIndexInfoOfType", {
|
|
2175
|
+
snapshot: this.snapshotId,
|
|
2176
|
+
project: this.project.id,
|
|
2177
|
+
type: type.id,
|
|
2178
|
+
kind,
|
|
2179
|
+
});
|
|
2180
|
+
return data ? {
|
|
2181
|
+
keyType: this.objectRegistry.getOrCreateType(data.keyType),
|
|
2182
|
+
valueType: this.objectRegistry.getOrCreateType(data.valueType),
|
|
2183
|
+
isReadonly: data.isReadonly ?? false,
|
|
2184
|
+
declaration: data.declaration ? new NodeHandle(data.declaration, this.project) : undefined,
|
|
2185
|
+
} : undefined;
|
|
2186
|
+
}
|
|
2187
|
+
async getIndexTypeOfType(type, kind) {
|
|
2188
|
+
return kind === IndexKind.String ? type.getStringIndexType() : type.getNumberIndexType();
|
|
2189
|
+
}
|
|
2190
|
+
async getTypeOfPropertyOfType(type, propertyName) {
|
|
2191
|
+
const data = await this.client.apiRequest("getTypeOfPropertyOfType", {
|
|
2192
|
+
snapshot: this.snapshotId,
|
|
2193
|
+
project: this.project.id,
|
|
2194
|
+
type: type.id,
|
|
2195
|
+
name: propertyName,
|
|
2196
|
+
});
|
|
2197
|
+
return data ? this.objectRegistry.getOrCreateType(data) : undefined;
|
|
2198
|
+
}
|
|
2199
|
+
/**
|
|
2200
|
+
* Get the constraint of a type parameter (the `T` in `<U extends T>`), or
|
|
2201
|
+
* undefined if it has none.
|
|
2202
|
+
*/
|
|
2203
|
+
async getConstraintOfTypeParameter(type) {
|
|
2204
|
+
return type.getConstraint();
|
|
2205
|
+
}
|
|
2206
|
+
async getDefaultFromTypeParameter(type) {
|
|
2207
|
+
return type.getDefault();
|
|
2208
|
+
}
|
|
2209
|
+
async getBaseConstraintOfType(type) {
|
|
2210
|
+
const data = await this.client.apiRequest("getBaseConstraintOfType", {
|
|
2211
|
+
snapshot: this.snapshotId,
|
|
2212
|
+
project: this.project.id,
|
|
2213
|
+
type: type.id,
|
|
2214
|
+
});
|
|
2215
|
+
return data ? this.objectRegistry.getOrCreateType(data) : undefined;
|
|
2216
|
+
}
|
|
2217
|
+
async getPropertyOfType(type, name) {
|
|
2218
|
+
const data = await this.client.apiRequest("getPropertyOfType", {
|
|
2219
|
+
snapshot: this.snapshotId,
|
|
2220
|
+
project: this.project.id,
|
|
2221
|
+
type: type.id,
|
|
2222
|
+
name,
|
|
2223
|
+
});
|
|
2224
|
+
return data ? this.objectRegistry.getOrCreateSymbol(data) : undefined;
|
|
2225
|
+
}
|
|
2226
|
+
async getConstantValue(node) {
|
|
2227
|
+
const data = await this.client.apiRequest("getConstantValue", {
|
|
2228
|
+
snapshot: this.snapshotId,
|
|
2229
|
+
project: this.project.id,
|
|
2230
|
+
location: getNodeId(node),
|
|
2231
|
+
});
|
|
2232
|
+
if (!data || (typeof data.value !== "string" && typeof data.value !== "number")) {
|
|
2233
|
+
return undefined;
|
|
2234
|
+
}
|
|
2235
|
+
if (data.isNumber && typeof data.value === "string") {
|
|
2236
|
+
if (data.value === "+Infinity") {
|
|
2237
|
+
return Infinity;
|
|
2238
|
+
}
|
|
2239
|
+
else if (data.value === "-Infinity") {
|
|
2240
|
+
return -Infinity;
|
|
2241
|
+
}
|
|
2242
|
+
return NaN;
|
|
2243
|
+
}
|
|
2244
|
+
return data.value;
|
|
2245
|
+
}
|
|
2246
|
+
/** Get the signature of a function-like declaration. Always returns a signature. */
|
|
2247
|
+
async getSignatureFromDeclaration(node) {
|
|
2248
|
+
const data = await this.client.apiRequest("getSignatureFromDeclaration", {
|
|
2249
|
+
snapshot: this.snapshotId,
|
|
2250
|
+
project: this.project.id,
|
|
2251
|
+
location: getNodeId(node),
|
|
2252
|
+
});
|
|
2253
|
+
return this.objectRegistry.getOrCreateSignature(data);
|
|
2254
|
+
}
|
|
2255
|
+
async getExportSpecifierLocalTargetSymbol(node) {
|
|
2256
|
+
const data = await this.client.apiRequest("getExportSpecifierLocalTargetSymbol", {
|
|
2257
|
+
snapshot: this.snapshotId,
|
|
2258
|
+
project: this.project.id,
|
|
2259
|
+
location: getNodeId(node),
|
|
2260
|
+
});
|
|
2261
|
+
return data ? this.objectRegistry.getOrCreateSymbol(data) : undefined;
|
|
2262
|
+
}
|
|
2263
|
+
/**
|
|
2264
|
+
* Follow all aliases to get the original symbol. Always returns a symbol; for
|
|
2265
|
+
* an unresolved alias the checker yields the unknown symbol (use
|
|
2266
|
+
* {@link Checker.isUnknownSymbol} to detect it).
|
|
2267
|
+
*/
|
|
2268
|
+
async getAliasedSymbol(symbol) {
|
|
2269
|
+
const data = await this.client.apiRequest("getAliasedSymbol", {
|
|
2270
|
+
snapshot: this.snapshotId,
|
|
2271
|
+
project: this.project.id,
|
|
2272
|
+
symbol: symbol.reference,
|
|
2273
|
+
});
|
|
2274
|
+
return this.objectRegistry.getOrCreateSymbol(data);
|
|
2275
|
+
}
|
|
2276
|
+
/**
|
|
2277
|
+
* Get the fully qualified name of a symbol, walking up its parent chain
|
|
2278
|
+
* (e.g. `"/path/to/module".Namespace.Name`).
|
|
2279
|
+
*/
|
|
2280
|
+
async getFullyQualifiedName(symbol) {
|
|
2281
|
+
return this.client.apiRequest("getFullyQualifiedName", {
|
|
2282
|
+
snapshot: this.snapshotId,
|
|
2283
|
+
project: this.project.id,
|
|
2284
|
+
symbol: symbol.reference,
|
|
2285
|
+
});
|
|
2286
|
+
}
|
|
2287
|
+
async getImmediateAliasedSymbol(symbol) {
|
|
2288
|
+
const data = await this.client.apiRequest("getImmediateAliasedSymbol", {
|
|
2289
|
+
snapshot: this.snapshotId,
|
|
2290
|
+
project: this.project.id,
|
|
2291
|
+
symbol: symbol.reference,
|
|
2292
|
+
});
|
|
2293
|
+
return data ? this.objectRegistry.getOrCreateSymbol(data) : undefined;
|
|
2294
|
+
}
|
|
2295
|
+
/**
|
|
2296
|
+
* Get the target symbol if instantiated, or the provided symbol otherwise.
|
|
2297
|
+
*/
|
|
2298
|
+
async getTargetSymbol(symbol) {
|
|
2299
|
+
if (symbol.checkFlags & CheckFlags.Instantiated) {
|
|
2300
|
+
const data = await this.client.apiRequest("getTargetSymbol", {
|
|
2301
|
+
snapshot: this.snapshotId,
|
|
2302
|
+
project: this.project.id,
|
|
2303
|
+
symbol: symbol.reference,
|
|
2304
|
+
});
|
|
2305
|
+
return this.objectRegistry.getOrCreateSymbol(data);
|
|
2306
|
+
}
|
|
2307
|
+
return symbol;
|
|
2308
|
+
}
|
|
2309
|
+
async getExportSymbolOfSymbol(symbol) {
|
|
2310
|
+
const data = await this.client.apiRequest("getExportSymbolOfSymbolForChecker", {
|
|
2311
|
+
snapshot: this.snapshotId,
|
|
2312
|
+
project: this.project.id,
|
|
2313
|
+
symbol: symbol.reference,
|
|
2314
|
+
});
|
|
2315
|
+
return this.objectRegistry.getOrCreateSymbol(data);
|
|
2316
|
+
}
|
|
2317
|
+
/**
|
|
2318
|
+
* Fetch (once, then cache) the handle ids of the per-checker singleton
|
|
2319
|
+
* symbols (unknown, undefined, arguments). These ids are stable for the life
|
|
2320
|
+
* of the project's checker, so identity checks against them are local after
|
|
2321
|
+
* the first call.
|
|
2322
|
+
*/
|
|
2323
|
+
getWellKnownSymbols() {
|
|
2324
|
+
return this.wellKnownSymbols ??= this.client.apiRequest("getWellKnownSymbols", {
|
|
2325
|
+
snapshot: this.snapshotId,
|
|
2326
|
+
project: this.project.id,
|
|
2327
|
+
});
|
|
2328
|
+
}
|
|
2329
|
+
/**
|
|
2330
|
+
* Returns `true` if the symbol is the checker's "unknown" symbol (e.g. the
|
|
2331
|
+
* result of {@link Checker.getAliasedSymbol} on an unresolved alias).
|
|
2332
|
+
*/
|
|
2333
|
+
async isUnknownSymbol(symbol) {
|
|
2334
|
+
return symbol.id === (await this.getWellKnownSymbols()).unknown;
|
|
2335
|
+
}
|
|
2336
|
+
/**
|
|
2337
|
+
* Returns `true` if the symbol is the checker's "undefined" symbol.
|
|
2338
|
+
*/
|
|
2339
|
+
async isUndefinedSymbol(symbol) {
|
|
2340
|
+
return symbol.id === (await this.getWellKnownSymbols()).undefined;
|
|
2341
|
+
}
|
|
2342
|
+
/**
|
|
2343
|
+
* Returns `true` if the symbol is the checker's "arguments" symbol.
|
|
2344
|
+
*/
|
|
2345
|
+
async isArgumentsSymbol(symbol) {
|
|
2346
|
+
return symbol.id === (await this.getWellKnownSymbols()).arguments;
|
|
2347
|
+
}
|
|
2348
|
+
/**
|
|
2349
|
+
* Fetch (once, then cache) the handle id of the per-checker unknown
|
|
2350
|
+
* signature. This id is stable for the life of the project's checker, so
|
|
2351
|
+
* identity checks against it are local after the first call.
|
|
2352
|
+
*/
|
|
2353
|
+
getWellKnownSignatures() {
|
|
2354
|
+
return this.wellKnownSignatures ??= this.client.apiRequest("getWellKnownSignatures", {
|
|
2355
|
+
snapshot: this.snapshotId,
|
|
2356
|
+
project: this.project.id,
|
|
2357
|
+
});
|
|
2358
|
+
}
|
|
2359
|
+
/**
|
|
2360
|
+
* Returns `true` if the signature is the checker's "unknown" signature (e.g.
|
|
2361
|
+
* the result of {@link Checker.getResolvedSignature} on a call that cannot be
|
|
2362
|
+
* resolved).
|
|
2363
|
+
*/
|
|
2364
|
+
async isUnknownSignature(signature) {
|
|
2365
|
+
return signature.id === (await this.getWellKnownSignatures()).unknown;
|
|
2366
|
+
}
|
|
2367
|
+
async getExportsOfModule(symbol) {
|
|
2368
|
+
const data = await this.client.apiRequest("getExportsOfModule", {
|
|
2369
|
+
snapshot: this.snapshotId,
|
|
2370
|
+
project: this.project.id,
|
|
2371
|
+
symbol: symbol.reference,
|
|
2372
|
+
});
|
|
2373
|
+
return data ? data.map(d => this.objectRegistry.getOrCreateSymbol(d)) : [];
|
|
2374
|
+
}
|
|
2375
|
+
async getMemberInModuleExports(symbol, name) {
|
|
2376
|
+
const data = await this.client.apiRequest("getMemberInModuleExports", {
|
|
2377
|
+
snapshot: this.snapshotId,
|
|
2378
|
+
project: this.project.id,
|
|
2379
|
+
symbol: symbol.reference,
|
|
2380
|
+
name,
|
|
2381
|
+
});
|
|
2382
|
+
return data ? this.objectRegistry.getOrCreateSymbol(data) : undefined;
|
|
2383
|
+
}
|
|
2384
|
+
async getJsDocTagsOfSymbol(symbol) {
|
|
2385
|
+
const data = await this.client.apiRequest("getJsDocTags", {
|
|
2386
|
+
snapshot: this.snapshotId,
|
|
2387
|
+
project: this.project.id,
|
|
2388
|
+
symbol: symbol.reference,
|
|
2389
|
+
});
|
|
2390
|
+
return data ?? [];
|
|
2391
|
+
}
|
|
2392
|
+
async getDocumentationCommentOfSymbol(symbol) {
|
|
2393
|
+
return this.client.apiRequest("getDocumentationComment", {
|
|
2394
|
+
snapshot: this.snapshotId,
|
|
2395
|
+
project: this.project.id,
|
|
2396
|
+
symbol: symbol.reference,
|
|
2397
|
+
});
|
|
2398
|
+
}
|
|
2399
|
+
/**
|
|
2400
|
+
* Get the type arguments of a type reference (e.g. the `string` in `Array<string>`).
|
|
2401
|
+
*/
|
|
2402
|
+
async getTypeArguments(type) {
|
|
2403
|
+
const data = await this.client.apiRequest("getTypeArguments", {
|
|
2404
|
+
snapshot: this.snapshotId,
|
|
2405
|
+
project: this.project.id,
|
|
2406
|
+
type: type.id,
|
|
2407
|
+
});
|
|
2408
|
+
return data ? data.map(d => this.objectRegistry.getOrCreateType(d)) : [];
|
|
2409
|
+
}
|
|
2410
|
+
}
|
|
2411
|
+
export class Printer {
|
|
2412
|
+
client;
|
|
2413
|
+
constructor(client) {
|
|
2414
|
+
this.client = client;
|
|
2415
|
+
}
|
|
2416
|
+
async printNode(node, options = {}) {
|
|
2417
|
+
const encoded = encodeNode(node);
|
|
2418
|
+
const base64 = uint8ArrayToBase64(encoded);
|
|
2419
|
+
return this.client.apiRequest("printNode", {
|
|
2420
|
+
data: base64,
|
|
2421
|
+
preserveSourceNewlines: options.preserveSourceNewlines,
|
|
2422
|
+
neverAsciiEscape: options.neverAsciiEscape,
|
|
2423
|
+
terminateUnterminatedLiterals: options.terminateUnterminatedLiterals,
|
|
2424
|
+
});
|
|
2425
|
+
}
|
|
2426
|
+
async printFile(sourceFile, options = {}) {
|
|
2427
|
+
const encoded = encodeNode(sourceFile);
|
|
2428
|
+
const base64 = uint8ArrayToBase64(encoded);
|
|
2429
|
+
return this.client.apiRequest("printNode", {
|
|
2430
|
+
data: base64,
|
|
2431
|
+
preserveSourceNewlines: options.preserveSourceNewlines,
|
|
2432
|
+
neverAsciiEscape: options.neverAsciiEscape,
|
|
2433
|
+
terminateUnterminatedLiterals: options.terminateUnterminatedLiterals,
|
|
2434
|
+
});
|
|
2435
|
+
}
|
|
2436
|
+
}
|
|
2437
|
+
export class SnapshotInternalAPI {
|
|
2438
|
+
snapshotId;
|
|
2439
|
+
client;
|
|
2440
|
+
constructor(snapshotId, client) {
|
|
2441
|
+
this.snapshotId = snapshotId;
|
|
2442
|
+
this.client = client;
|
|
2443
|
+
}
|
|
2444
|
+
/**
|
|
2445
|
+
* Format a synthesized node with the correct indentation for insertion at a
|
|
2446
|
+
* specific position in an existing source file.
|
|
2447
|
+
*
|
|
2448
|
+
* @param node The synthesized AST node to format.
|
|
2449
|
+
* @param file The target file where the node will be inserted.
|
|
2450
|
+
* @param position The UTF-16 code-unit offset in the target file for insertion.
|
|
2451
|
+
* @returns The formatted text of the node, indented for the insertion position.
|
|
2452
|
+
*/
|
|
2453
|
+
async formatNodeForInsertion(node, file, position) {
|
|
2454
|
+
const data = await this.client.apiRequest("getDefaultProjectForFile", {
|
|
2455
|
+
snapshot: this.snapshotId,
|
|
2456
|
+
file,
|
|
2457
|
+
});
|
|
2458
|
+
if (!data) {
|
|
2459
|
+
throw new Error(`No project found for file: ${typeof file === "string" ? file : file.uri}`);
|
|
2460
|
+
}
|
|
2461
|
+
const encoded = encodeNode(node);
|
|
2462
|
+
const base64 = uint8ArrayToBase64(encoded);
|
|
2463
|
+
return this.client.apiRequest("formatNodeForInsertion", {
|
|
2464
|
+
snapshot: this.snapshotId,
|
|
2465
|
+
project: data.id,
|
|
2466
|
+
file,
|
|
2467
|
+
position,
|
|
2468
|
+
data: base64,
|
|
2469
|
+
});
|
|
2470
|
+
}
|
|
2471
|
+
}
|
|
2472
|
+
export class NodeHandle {
|
|
2473
|
+
/**
|
|
2474
|
+
* The project this handle was produced in, used as the default for {@link resolve}.
|
|
2475
|
+
* Node handles are only meaningful within a project's program, so the producing project
|
|
2476
|
+
* is remembered so callers don't have to pass it explicitly.
|
|
2477
|
+
*/
|
|
2478
|
+
canonicalProject;
|
|
2479
|
+
/** The owning source file of a file-owned symbol's declaration. */
|
|
2480
|
+
fileOwner;
|
|
2481
|
+
index;
|
|
2482
|
+
kind;
|
|
2483
|
+
path;
|
|
2484
|
+
constructor(handle, canonicalProject, fileOwner) {
|
|
2485
|
+
const parsed = parseNodeHandleFromCompiler(handle);
|
|
2486
|
+
this.index = parsed.index;
|
|
2487
|
+
this.kind = parsed.kind;
|
|
2488
|
+
this.path = parsed.path;
|
|
2489
|
+
this.canonicalProject = canonicalProject;
|
|
2490
|
+
this.fileOwner = fileOwner;
|
|
2491
|
+
}
|
|
2492
|
+
/**
|
|
2493
|
+
* Resolve this handle to the actual AST node by fetching the source file from a project
|
|
2494
|
+
* and looking up the node by index. If no project is passed, the project that produced
|
|
2495
|
+
* the handle is used. Declarations of file-owned symbols identify an exact source file and
|
|
2496
|
+
* resolve through it, independently of any project.
|
|
2497
|
+
*/
|
|
2498
|
+
async resolve(project = this.canonicalProject) {
|
|
2499
|
+
if (this.fileOwner) {
|
|
2500
|
+
const sourceFile = this.fileOwner.record.file ?? await this.fetchOwnerFile(this.fileOwner);
|
|
2501
|
+
return sourceFile.getOrCreateNodeAtIndex(this.index);
|
|
2502
|
+
}
|
|
2503
|
+
if (!project)
|
|
2504
|
+
throw new Error(`Node handle for '${this.path}' has no project context`);
|
|
2505
|
+
const sourceFile = await project.program.getSourceFileByPath(this.path);
|
|
2506
|
+
if (!sourceFile) {
|
|
2507
|
+
return undefined;
|
|
2508
|
+
}
|
|
2509
|
+
return sourceFile.getOrCreateNodeAtIndex(this.index);
|
|
2510
|
+
}
|
|
2511
|
+
async fetchOwnerFile(fileOwner) {
|
|
2512
|
+
const data = await fileOwner.api.client.apiRequestBinary("getCachedSourceFile", { file: fileOwner.record.descriptor });
|
|
2513
|
+
if (!data)
|
|
2514
|
+
throw new Error(`Source file '${fileOwner.record.descriptor.fileName}' is not available`);
|
|
2515
|
+
return fileOwner.api.sourceFileCache.attachFile(fileOwner.record, new RemoteSourceFile(data, new Wtf8Decoder(), fileOwner.api.client.getTimingCollector(), fileOwner.api));
|
|
2516
|
+
}
|
|
2517
|
+
}
|
|
2518
|
+
export class Symbol {
|
|
2519
|
+
storage;
|
|
2520
|
+
get id() {
|
|
2521
|
+
return this.reference.id;
|
|
2522
|
+
}
|
|
2523
|
+
/** The escaped (`__String`) name, used as the key in member/export tables. */
|
|
2524
|
+
escapedName;
|
|
2525
|
+
/** The display name (escaped underscores removed). */
|
|
2526
|
+
name;
|
|
2527
|
+
flags;
|
|
2528
|
+
checkFlags;
|
|
2529
|
+
/** @internal */
|
|
2530
|
+
reference;
|
|
2531
|
+
declarations;
|
|
2532
|
+
valueDeclaration;
|
|
2533
|
+
parent;
|
|
2534
|
+
exportSymbol;
|
|
2535
|
+
membersCache;
|
|
2536
|
+
exportsCache;
|
|
2537
|
+
constructor(data, storage) {
|
|
2538
|
+
if (data.reference.kind !== storage.kind)
|
|
2539
|
+
throw new Error(`Symbol ${data.reference.id} has mismatched ownership and storage`);
|
|
2540
|
+
this.storage = storage;
|
|
2541
|
+
this.reference = data.reference;
|
|
2542
|
+
this.escapedName = data.name;
|
|
2543
|
+
this.name = unescapeLeadingUnderscores(data.name);
|
|
2544
|
+
this.flags = data.flags;
|
|
2545
|
+
this.checkFlags = data.checkFlags;
|
|
2546
|
+
// A file-owned symbol has no canonical project; its declarations resolve through its file.
|
|
2547
|
+
const project = storage.kind === SymbolOwnerKind.Snapshot ? storage.registry.project : undefined;
|
|
2548
|
+
const fileOwner = storage.kind === SymbolOwnerKind.File ? storage.owner : undefined;
|
|
2549
|
+
this.declarations = (data.declarations ?? []).map(handle => new NodeHandle(handle, project, fileOwner));
|
|
2550
|
+
this.valueDeclaration = data.valueDeclaration
|
|
2551
|
+
? new NodeHandle(data.valueDeclaration, project, fileOwner)
|
|
2552
|
+
: undefined;
|
|
2553
|
+
if (data.parent !== undefined)
|
|
2554
|
+
this.parent = data.parent;
|
|
2555
|
+
if (data.exportSymbol !== undefined)
|
|
2556
|
+
this.exportSymbol = data.exportSymbol;
|
|
2557
|
+
}
|
|
2558
|
+
async getParent() {
|
|
2559
|
+
if (!this.parent)
|
|
2560
|
+
return undefined;
|
|
2561
|
+
return this.fetchSymbol("getParentOfSymbol", this.parent);
|
|
2562
|
+
}
|
|
2563
|
+
/**
|
|
2564
|
+
* Get this symbol's members keyed by escaped name. The result is cached on
|
|
2565
|
+
* the symbol, so repeated calls do not round-trip to the server.
|
|
2566
|
+
*/
|
|
2567
|
+
getMembers() {
|
|
2568
|
+
return this.membersCache ??= this.fetchSymbolTable("getMembersOfSymbol");
|
|
2569
|
+
}
|
|
2570
|
+
/**
|
|
2571
|
+
* Get this symbol's exports keyed by escaped name. The result is cached on
|
|
2572
|
+
* the symbol, so repeated calls do not round-trip to the server.
|
|
2573
|
+
*/
|
|
2574
|
+
getExports() {
|
|
2575
|
+
return this.exportsCache ??= this.fetchSymbolTable("getExportsOfSymbol");
|
|
2576
|
+
}
|
|
2577
|
+
async fetchSymbolTable(method) {
|
|
2578
|
+
const symbols = await this.fetchSymbols(method);
|
|
2579
|
+
const table = new Map();
|
|
2580
|
+
for (const symbol of symbols) {
|
|
2581
|
+
table.set(symbol.escapedName, symbol);
|
|
2582
|
+
}
|
|
2583
|
+
return table;
|
|
2584
|
+
}
|
|
2585
|
+
async getExportSymbol() {
|
|
2586
|
+
if (!this.exportSymbol)
|
|
2587
|
+
return this;
|
|
2588
|
+
return this.fetchSymbol("getExportSymbolOfSymbol", this.exportSymbol);
|
|
2589
|
+
}
|
|
2590
|
+
async getJsDocTags(checker) {
|
|
2591
|
+
return checker.getJsDocTagsOfSymbol(this);
|
|
2592
|
+
}
|
|
2593
|
+
async getDocumentationComment(checker) {
|
|
2594
|
+
return checker.getDocumentationCommentOfSymbol(this);
|
|
2595
|
+
}
|
|
2596
|
+
async fetchSymbol(method, reference) {
|
|
2597
|
+
if (this.storage.kind === SymbolOwnerKind.Snapshot) {
|
|
2598
|
+
return this.storage.registry.fetchSymbol(this, method, reference);
|
|
2599
|
+
}
|
|
2600
|
+
const fileOwner = this.storage.owner;
|
|
2601
|
+
// A file-owned symbol's relationships are always owned by the same file.
|
|
2602
|
+
const cached = reference.file === fileOwner.record.descriptor.nodeId ? fileOwner.record.symbolsById.get(reference.id) : undefined;
|
|
2603
|
+
if (cached)
|
|
2604
|
+
return cached;
|
|
2605
|
+
const data = await fileOwner.api.client.apiRequest(method, { symbol: this.reference });
|
|
2606
|
+
if (!data)
|
|
2607
|
+
throw new Error(`${method} returned null symbol for Symbol ${this.id}`);
|
|
2608
|
+
return this.internFileSymbol(fileOwner, data);
|
|
2609
|
+
}
|
|
2610
|
+
async fetchSymbols(method) {
|
|
2611
|
+
if (this.storage.kind === SymbolOwnerKind.Snapshot) {
|
|
2612
|
+
return this.storage.registry.fetchSymbols(this, method);
|
|
2613
|
+
}
|
|
2614
|
+
const fileOwner = this.storage.owner;
|
|
2615
|
+
const data = await fileOwner.api.client.apiRequest(method, { symbol: this.reference });
|
|
2616
|
+
return data?.map(symbol => this.internFileSymbol(fileOwner, symbol)) ?? [];
|
|
2617
|
+
}
|
|
2618
|
+
internFileSymbol(fileOwner, data) {
|
|
2619
|
+
validateSymbolResponse(data);
|
|
2620
|
+
const reference = data.reference;
|
|
2621
|
+
if (reference.kind !== SymbolOwnerKind.File)
|
|
2622
|
+
throw new Error(`Symbol ${reference.id} is not file-owned`);
|
|
2623
|
+
return fileOwner.api.sourceFileCache.getOrCreateSymbol(fileOwner.record, reference.file, reference.id, () => new Symbol(data, { kind: SymbolOwnerKind.File, owner: fileOwner }));
|
|
2624
|
+
}
|
|
2625
|
+
}
|
|
2626
|
+
class TypeObject {
|
|
2627
|
+
objectRegistry;
|
|
2628
|
+
// Fields included in TypeResponse. References to other objects are stored as IDs
|
|
2629
|
+
// and resolved lazily via the object registry.
|
|
2630
|
+
id;
|
|
2631
|
+
flags;
|
|
2632
|
+
objectFlags;
|
|
2633
|
+
symbol;
|
|
2634
|
+
value;
|
|
2635
|
+
intrinsicName;
|
|
2636
|
+
isThisType;
|
|
2637
|
+
freshType;
|
|
2638
|
+
regularType;
|
|
2639
|
+
target;
|
|
2640
|
+
tupleType;
|
|
2641
|
+
typeParameters;
|
|
2642
|
+
outerTypeParameters;
|
|
2643
|
+
localTypeParameters;
|
|
2644
|
+
thisType;
|
|
2645
|
+
aliasTypeArguments;
|
|
2646
|
+
aliasSymbol;
|
|
2647
|
+
elementFlags;
|
|
2648
|
+
fixedLength;
|
|
2649
|
+
readonly;
|
|
2650
|
+
labeledElementDeclarations;
|
|
2651
|
+
texts;
|
|
2652
|
+
objectType;
|
|
2653
|
+
indexType;
|
|
2654
|
+
checkType;
|
|
2655
|
+
extendsType;
|
|
2656
|
+
baseType;
|
|
2657
|
+
substConstraint;
|
|
2658
|
+
typeParameter;
|
|
2659
|
+
constraintType;
|
|
2660
|
+
nameType;
|
|
2661
|
+
templateType;
|
|
2662
|
+
// Cached results of lazy fetches, not included in TypeResponse
|
|
2663
|
+
// (typically because they require some amount of computation or
|
|
2664
|
+
// could cause an arbitrarily large number of types to be cached
|
|
2665
|
+
// on the server for ID-based lookup). `false` is a sentinel value
|
|
2666
|
+
// indicating a fetch has not yet occurred.
|
|
2667
|
+
trueType;
|
|
2668
|
+
falseType;
|
|
2669
|
+
constraint;
|
|
2670
|
+
default;
|
|
2671
|
+
nonNullableType;
|
|
2672
|
+
apparentType;
|
|
2673
|
+
reducedType;
|
|
2674
|
+
properties;
|
|
2675
|
+
apparentProperties;
|
|
2676
|
+
callSignatures;
|
|
2677
|
+
constructSignatures;
|
|
2678
|
+
indexInfos;
|
|
2679
|
+
baseTypes;
|
|
2680
|
+
types;
|
|
2681
|
+
stringIndexType;
|
|
2682
|
+
numberIndexType;
|
|
2683
|
+
constructor(data, objectRegistry) {
|
|
2684
|
+
this.objectRegistry = objectRegistry;
|
|
2685
|
+
this.id = data.id;
|
|
2686
|
+
this.flags = data.flags;
|
|
2687
|
+
if (data.objectFlags !== undefined)
|
|
2688
|
+
this.objectFlags = data.objectFlags;
|
|
2689
|
+
if (data.symbol !== undefined)
|
|
2690
|
+
this.symbol = data.symbol;
|
|
2691
|
+
if (data.value != null) {
|
|
2692
|
+
// BigInt literal values are serialized as decimal strings (e.g. "-123") because
|
|
2693
|
+
// JSON cannot represent bigint. Decode them back into a real bigint here.
|
|
2694
|
+
const value = data.value;
|
|
2695
|
+
if (data.flags & TypeFlags.BigIntLiteral) {
|
|
2696
|
+
this.value = BigInt(value);
|
|
2697
|
+
}
|
|
2698
|
+
// JSON cannot represent infinities, so the API serializes them as strings.
|
|
2699
|
+
else if (data.flags & TypeFlags.NumberLiteral && typeof value === "string") {
|
|
2700
|
+
if (value === "+Infinity") {
|
|
2701
|
+
this.value = Infinity;
|
|
2702
|
+
}
|
|
2703
|
+
else if (value === "-Infinity") {
|
|
2704
|
+
this.value = -Infinity;
|
|
2705
|
+
}
|
|
2706
|
+
else {
|
|
2707
|
+
this.value = NaN;
|
|
2708
|
+
}
|
|
2709
|
+
}
|
|
2710
|
+
else {
|
|
2711
|
+
this.value = value;
|
|
2712
|
+
}
|
|
2713
|
+
}
|
|
2714
|
+
if (data.intrinsicName !== undefined)
|
|
2715
|
+
this.intrinsicName = data.intrinsicName;
|
|
2716
|
+
if (data.isThisType !== undefined)
|
|
2717
|
+
this.isThisType = data.isThisType;
|
|
2718
|
+
if (data.freshType !== undefined)
|
|
2719
|
+
this.freshType = data.freshType;
|
|
2720
|
+
if (data.regularType !== undefined)
|
|
2721
|
+
this.regularType = data.regularType;
|
|
2722
|
+
if (data.target !== undefined)
|
|
2723
|
+
this.target = data.target;
|
|
2724
|
+
this.tupleType = data.isTupleType ?? false;
|
|
2725
|
+
this.typeParameters = data.typeParameters ?? [];
|
|
2726
|
+
this.outerTypeParameters = data.outerTypeParameters ?? [];
|
|
2727
|
+
this.localTypeParameters = data.localTypeParameters ?? [];
|
|
2728
|
+
if (data.thisType !== undefined)
|
|
2729
|
+
this.thisType = data.thisType;
|
|
2730
|
+
this.aliasTypeArguments = data.aliasTypeArguments ?? [];
|
|
2731
|
+
if (data.aliasSymbol !== undefined)
|
|
2732
|
+
this.aliasSymbol = data.aliasSymbol;
|
|
2733
|
+
if (data.fixedLength !== undefined) {
|
|
2734
|
+
this.elementFlags = data.elementFlags ?? [];
|
|
2735
|
+
this.fixedLength = data.fixedLength;
|
|
2736
|
+
}
|
|
2737
|
+
if (data.readonly !== undefined)
|
|
2738
|
+
this.readonly = data.readonly;
|
|
2739
|
+
if (data.labeledElementDeclarations !== undefined) {
|
|
2740
|
+
this.labeledElementDeclarations = data.labeledElementDeclarations.map(handle => handle ? objectRegistry.createNodeHandle(handle) : undefined);
|
|
2741
|
+
}
|
|
2742
|
+
if (data.texts !== undefined)
|
|
2743
|
+
this.texts = data.texts;
|
|
2744
|
+
if (data.objectType !== undefined)
|
|
2745
|
+
this.objectType = data.objectType;
|
|
2746
|
+
if (data.indexType !== undefined)
|
|
2747
|
+
this.indexType = data.indexType;
|
|
2748
|
+
if (data.checkType !== undefined)
|
|
2749
|
+
this.checkType = data.checkType;
|
|
2750
|
+
if (data.extendsType !== undefined)
|
|
2751
|
+
this.extendsType = data.extendsType;
|
|
2752
|
+
if (data.baseType !== undefined)
|
|
2753
|
+
this.baseType = data.baseType;
|
|
2754
|
+
if (data.substConstraint !== undefined)
|
|
2755
|
+
this.substConstraint = data.substConstraint;
|
|
2756
|
+
if (data.typeParameter !== undefined)
|
|
2757
|
+
this.typeParameter = data.typeParameter;
|
|
2758
|
+
if (data.constraintType !== undefined)
|
|
2759
|
+
this.constraintType = data.constraintType;
|
|
2760
|
+
if (data.nameType !== undefined)
|
|
2761
|
+
this.nameType = data.nameType;
|
|
2762
|
+
if (data.templateType !== undefined)
|
|
2763
|
+
this.templateType = data.templateType;
|
|
2764
|
+
this.trueType = false;
|
|
2765
|
+
this.falseType = false;
|
|
2766
|
+
this.constraint = false;
|
|
2767
|
+
this.default = false;
|
|
2768
|
+
this.nonNullableType = false;
|
|
2769
|
+
this.apparentType = false;
|
|
2770
|
+
this.reducedType = false;
|
|
2771
|
+
this.properties = false;
|
|
2772
|
+
this.apparentProperties = false;
|
|
2773
|
+
this.callSignatures = false;
|
|
2774
|
+
this.constructSignatures = false;
|
|
2775
|
+
this.indexInfos = false;
|
|
2776
|
+
this.baseTypes = false;
|
|
2777
|
+
this.types = false;
|
|
2778
|
+
this.stringIndexType = false;
|
|
2779
|
+
this.numberIndexType = false;
|
|
2780
|
+
}
|
|
2781
|
+
async getSymbol() {
|
|
2782
|
+
return this.objectRegistry.fetchSymbol(this, "getSymbolOfType", this.symbol);
|
|
2783
|
+
}
|
|
2784
|
+
async getProperties() {
|
|
2785
|
+
if (this.properties === false) {
|
|
2786
|
+
this.properties = await this.objectRegistry.fetchPropertiesOfType(this);
|
|
2787
|
+
}
|
|
2788
|
+
return this.properties;
|
|
2789
|
+
}
|
|
2790
|
+
getProperty(propertyName) {
|
|
2791
|
+
return this.objectRegistry.fetchPropertyOfType(this, propertyName);
|
|
2792
|
+
}
|
|
2793
|
+
async getApparentProperties() {
|
|
2794
|
+
if (this.apparentProperties === false) {
|
|
2795
|
+
this.apparentProperties = await this.objectRegistry.fetchApparentPropertiesOfType(this);
|
|
2796
|
+
}
|
|
2797
|
+
return this.apparentProperties;
|
|
2798
|
+
}
|
|
2799
|
+
async getCallSignatures() {
|
|
2800
|
+
if (this.callSignatures === false) {
|
|
2801
|
+
this.callSignatures = await this.objectRegistry.fetchSignaturesOfType(this, SignatureKind.Call);
|
|
2802
|
+
}
|
|
2803
|
+
return this.callSignatures;
|
|
2804
|
+
}
|
|
2805
|
+
async getConstructSignatures() {
|
|
2806
|
+
if (this.constructSignatures === false) {
|
|
2807
|
+
this.constructSignatures = await this.objectRegistry.fetchSignaturesOfType(this, SignatureKind.Construct);
|
|
2808
|
+
}
|
|
2809
|
+
return this.constructSignatures;
|
|
2810
|
+
}
|
|
2811
|
+
async getNonNullableType() {
|
|
2812
|
+
const result = await this.objectRegistry.fetchType(this, "getNonNullableType", this.nonNullableType);
|
|
2813
|
+
this.nonNullableType = result.id;
|
|
2814
|
+
return result;
|
|
2815
|
+
}
|
|
2816
|
+
async getStringIndexType() {
|
|
2817
|
+
if (this.stringIndexType === false) {
|
|
2818
|
+
this.stringIndexType = await this.getStringIndexTypeWorker();
|
|
2819
|
+
}
|
|
2820
|
+
return this.stringIndexType;
|
|
2821
|
+
}
|
|
2822
|
+
async getStringIndexTypeWorker() {
|
|
2823
|
+
const infos = await this.getIndexInfos();
|
|
2824
|
+
return infos.find(info => (info.keyType.flags & TypeFlags.String) !== 0)?.valueType;
|
|
2825
|
+
}
|
|
2826
|
+
async getNumberIndexType() {
|
|
2827
|
+
if (this.numberIndexType === false) {
|
|
2828
|
+
this.numberIndexType = await this.getNumberIndexTypeWorker();
|
|
2829
|
+
}
|
|
2830
|
+
return this.numberIndexType;
|
|
2831
|
+
}
|
|
2832
|
+
async getNumberIndexTypeWorker() {
|
|
2833
|
+
const infos = await this.getIndexInfos();
|
|
2834
|
+
return infos.find(info => (info.keyType.flags & TypeFlags.Number) !== 0)?.valueType;
|
|
2835
|
+
}
|
|
2836
|
+
async getApparentType() {
|
|
2837
|
+
const result = await this.objectRegistry.fetchType(this, "getApparentType", this.apparentType);
|
|
2838
|
+
this.apparentType = result.id;
|
|
2839
|
+
return result;
|
|
2840
|
+
}
|
|
2841
|
+
async getReducedType() {
|
|
2842
|
+
const result = await this.objectRegistry.fetchType(this, "getReducedType", this.reducedType);
|
|
2843
|
+
this.reducedType = result.id;
|
|
2844
|
+
return result;
|
|
2845
|
+
}
|
|
2846
|
+
async getIndexInfos() {
|
|
2847
|
+
if (this.indexInfos === false) {
|
|
2848
|
+
this.indexInfos = await this.objectRegistry.fetchIndexInfosOfType(this);
|
|
2849
|
+
}
|
|
2850
|
+
return this.indexInfos;
|
|
2851
|
+
}
|
|
2852
|
+
async getAliasSymbol() {
|
|
2853
|
+
return this.objectRegistry.fetchSymbol(this, "getAliasSymbolOfType", this.aliasSymbol);
|
|
2854
|
+
}
|
|
2855
|
+
async getTarget() {
|
|
2856
|
+
return this.objectRegistry.fetchType(this, "getTargetOfType", this.target);
|
|
2857
|
+
}
|
|
2858
|
+
async getFreshType() {
|
|
2859
|
+
return this.objectRegistry.fetchOptionalType(this, "getFreshTypeOfType", this.freshType);
|
|
2860
|
+
}
|
|
2861
|
+
async getRegularType() {
|
|
2862
|
+
return this.objectRegistry.fetchOptionalType(this, "getRegularTypeOfType", this.regularType);
|
|
2863
|
+
}
|
|
2864
|
+
async getTypes() {
|
|
2865
|
+
// Only union, intersection, and template literal types have constituent
|
|
2866
|
+
// types; any other kind has none, so return undefined rather than sending
|
|
2867
|
+
// a request the server cannot satisfy.
|
|
2868
|
+
if (!(this.flags & (TypeFlags.UnionOrIntersection | TypeFlags.TemplateLiteral))) {
|
|
2869
|
+
return undefined;
|
|
2870
|
+
}
|
|
2871
|
+
if (this.types === false) {
|
|
2872
|
+
this.types = await this.objectRegistry.fetchTypes(this, "getTypesOfType");
|
|
2873
|
+
}
|
|
2874
|
+
return this.types;
|
|
2875
|
+
}
|
|
2876
|
+
async getTypeParameters() {
|
|
2877
|
+
return this.objectRegistry.fetchTypes(this, "getTypeParametersOfType", this.typeParameters);
|
|
2878
|
+
}
|
|
2879
|
+
async getOuterTypeParameters() {
|
|
2880
|
+
return this.objectRegistry.fetchTypes(this, "getOuterTypeParametersOfType", this.outerTypeParameters);
|
|
2881
|
+
}
|
|
2882
|
+
async getLocalTypeParameters() {
|
|
2883
|
+
return this.objectRegistry.fetchTypes(this, "getLocalTypeParametersOfType", this.localTypeParameters);
|
|
2884
|
+
}
|
|
2885
|
+
async getThisType() {
|
|
2886
|
+
return this.objectRegistry.fetchOptionalType(this, "getThisTypeOfType", this.thisType);
|
|
2887
|
+
}
|
|
2888
|
+
async getAliasTypeArguments() {
|
|
2889
|
+
return this.objectRegistry.fetchTypes(this, "getAliasTypeArgumentsOfType", this.aliasTypeArguments);
|
|
2890
|
+
}
|
|
2891
|
+
async getTypeParameter() {
|
|
2892
|
+
return this.objectRegistry.fetchType(this, "getTypeParameterOfMappedType", this.typeParameter);
|
|
2893
|
+
}
|
|
2894
|
+
async getConstraintType() {
|
|
2895
|
+
return this.objectRegistry.fetchType(this, "getConstraintTypeOfMappedType", this.constraintType);
|
|
2896
|
+
}
|
|
2897
|
+
async getNameType() {
|
|
2898
|
+
return this.objectRegistry.fetchOptionalType(this, "getNameTypeOfMappedType", this.nameType);
|
|
2899
|
+
}
|
|
2900
|
+
async getTemplateType() {
|
|
2901
|
+
return this.objectRegistry.fetchType(this, "getTemplateTypeOfMappedType", this.templateType);
|
|
2902
|
+
}
|
|
2903
|
+
async getObjectType() {
|
|
2904
|
+
return this.objectRegistry.fetchType(this, "getObjectTypeOfType", this.objectType);
|
|
2905
|
+
}
|
|
2906
|
+
async getIndexType() {
|
|
2907
|
+
return this.objectRegistry.fetchType(this, "getIndexTypeOfType", this.indexType);
|
|
2908
|
+
}
|
|
2909
|
+
async getCheckType() {
|
|
2910
|
+
return this.objectRegistry.fetchType(this, "getCheckTypeOfType", this.checkType);
|
|
2911
|
+
}
|
|
2912
|
+
async getExtendsType() {
|
|
2913
|
+
return this.objectRegistry.fetchType(this, "getExtendsTypeOfType", this.extendsType);
|
|
2914
|
+
}
|
|
2915
|
+
async getBaseType() {
|
|
2916
|
+
return this.objectRegistry.fetchType(this, "getBaseTypeOfType", this.baseType);
|
|
2917
|
+
}
|
|
2918
|
+
async getConstraint() {
|
|
2919
|
+
// Type parameters resolve their constraint lazily through the checker,
|
|
2920
|
+
// whereas substitution types carry a preloaded constraint handle.
|
|
2921
|
+
if (this.flags & TypeFlags.TypeParameter) {
|
|
2922
|
+
const result = await this.objectRegistry.fetchOptionalType(this, "getConstraintOfTypeParameter", this.constraint);
|
|
2923
|
+
this.constraint = result ? result.id : 0;
|
|
2924
|
+
return result;
|
|
2925
|
+
}
|
|
2926
|
+
return this.objectRegistry.fetchType(this, "getConstraintOfType", this.substConstraint);
|
|
2927
|
+
}
|
|
2928
|
+
async getDefault() {
|
|
2929
|
+
const result = await this.objectRegistry.fetchOptionalType(this, "getDefaultFromTypeParameter", this.default);
|
|
2930
|
+
this.default = result ? result.id : 0;
|
|
2931
|
+
return result;
|
|
2932
|
+
}
|
|
2933
|
+
async getTrueType() {
|
|
2934
|
+
const result = await this.objectRegistry.fetchType(this, "getTrueTypeOfConditionalType", this.trueType);
|
|
2935
|
+
this.trueType = result.id;
|
|
2936
|
+
return result;
|
|
2937
|
+
}
|
|
2938
|
+
async getFalseType() {
|
|
2939
|
+
const result = await this.objectRegistry.fetchType(this, "getFalseTypeOfConditionalType", this.falseType);
|
|
2940
|
+
this.falseType = result.id;
|
|
2941
|
+
return result;
|
|
2942
|
+
}
|
|
2943
|
+
/**
|
|
2944
|
+
* Get the base types of this type. Returns `undefined` for any type that is
|
|
2945
|
+
* not a class or interface.
|
|
2946
|
+
*/
|
|
2947
|
+
async getBaseTypes() {
|
|
2948
|
+
if (!this.isClassOrInterface()) {
|
|
2949
|
+
return undefined;
|
|
2950
|
+
}
|
|
2951
|
+
if (this.baseTypes === false) {
|
|
2952
|
+
this.baseTypes = await this.objectRegistry.fetchBaseTypes(this);
|
|
2953
|
+
}
|
|
2954
|
+
return this.baseTypes;
|
|
2955
|
+
}
|
|
2956
|
+
isClassOrInterface() {
|
|
2957
|
+
return isClassOrInterfaceType(this);
|
|
2958
|
+
}
|
|
2959
|
+
isUnionType() {
|
|
2960
|
+
return isUnionType(this);
|
|
2961
|
+
}
|
|
2962
|
+
isIntersectionType() {
|
|
2963
|
+
return isIntersectionType(this);
|
|
2964
|
+
}
|
|
2965
|
+
isObjectType() {
|
|
2966
|
+
return isObjectType(this);
|
|
2967
|
+
}
|
|
2968
|
+
isIntrinsicType() {
|
|
2969
|
+
return isIntrinsicType(this);
|
|
2970
|
+
}
|
|
2971
|
+
isErrorType() {
|
|
2972
|
+
return isErrorType(this);
|
|
2973
|
+
}
|
|
2974
|
+
isLiteralType() {
|
|
2975
|
+
return isLiteralType(this);
|
|
2976
|
+
}
|
|
2977
|
+
isStringLiteralType() {
|
|
2978
|
+
return isStringLiteralType(this);
|
|
2979
|
+
}
|
|
2980
|
+
isNumberLiteralType() {
|
|
2981
|
+
return isNumberLiteralType(this);
|
|
2982
|
+
}
|
|
2983
|
+
isBigIntLiteralType() {
|
|
2984
|
+
return isBigIntLiteralType(this);
|
|
2985
|
+
}
|
|
2986
|
+
isBooleanLiteralType() {
|
|
2987
|
+
return isBooleanLiteralType(this);
|
|
2988
|
+
}
|
|
2989
|
+
isTypeReference() {
|
|
2990
|
+
return isTypeReference(this);
|
|
2991
|
+
}
|
|
2992
|
+
isTupleType() {
|
|
2993
|
+
return this.tupleType;
|
|
2994
|
+
}
|
|
2995
|
+
isTupleTypeTarget() {
|
|
2996
|
+
return this.fixedLength !== undefined;
|
|
2997
|
+
}
|
|
2998
|
+
isIndexType() {
|
|
2999
|
+
return isIndexType(this);
|
|
3000
|
+
}
|
|
3001
|
+
isIndexedAccessType() {
|
|
3002
|
+
return isIndexedAccessType(this);
|
|
3003
|
+
}
|
|
3004
|
+
isConditionalType() {
|
|
3005
|
+
return isConditionalType(this);
|
|
3006
|
+
}
|
|
3007
|
+
isSubstitutionType() {
|
|
3008
|
+
return isSubstitutionType(this);
|
|
3009
|
+
}
|
|
3010
|
+
isTemplateLiteralType() {
|
|
3011
|
+
return isTemplateLiteralType(this);
|
|
3012
|
+
}
|
|
3013
|
+
isStringMappingType() {
|
|
3014
|
+
return isStringMappingType(this);
|
|
3015
|
+
}
|
|
3016
|
+
isTypeParameter() {
|
|
3017
|
+
return isTypeParameter(this);
|
|
3018
|
+
}
|
|
3019
|
+
isMappedType() {
|
|
3020
|
+
return !!(this.flags & TypeFlags.Object) && !!(this.objectFlags & ObjectFlags.Mapped);
|
|
3021
|
+
}
|
|
3022
|
+
}
|
|
3023
|
+
export function isUnionType(type) {
|
|
3024
|
+
return (type.flags & TypeFlags.Union) !== 0;
|
|
3025
|
+
}
|
|
3026
|
+
export function isIntersectionType(type) {
|
|
3027
|
+
return (type.flags & TypeFlags.Intersection) !== 0;
|
|
3028
|
+
}
|
|
3029
|
+
export function isObjectType(type) {
|
|
3030
|
+
return (type.flags & TypeFlags.Object) !== 0;
|
|
3031
|
+
}
|
|
3032
|
+
export function isClassOrInterfaceType(type) {
|
|
3033
|
+
return isObjectType(type) && (type.objectFlags & ObjectFlags.ClassOrInterface) !== 0;
|
|
3034
|
+
}
|
|
3035
|
+
export function isIntrinsicType(type) {
|
|
3036
|
+
return (type.flags & TypeFlags.Intrinsic) !== 0;
|
|
3037
|
+
}
|
|
3038
|
+
/**
|
|
3039
|
+
* Whether this is the error type — the placeholder the checker produces when a
|
|
3040
|
+
* type cannot be determined (e.g. an unresolved reference). It is an intrinsic
|
|
3041
|
+
* type named `"error"` (this covers both the singleton error type and the
|
|
3042
|
+
* per-alias error types manufactured for unresolved type alias references).
|
|
3043
|
+
*/
|
|
3044
|
+
export function isErrorType(type) {
|
|
3045
|
+
return isIntrinsicType(type) && type.intrinsicName === "error";
|
|
3046
|
+
}
|
|
3047
|
+
export function isLiteralType(type) {
|
|
3048
|
+
return (type.flags & TypeFlags.Literal) !== 0;
|
|
3049
|
+
}
|
|
3050
|
+
export function isStringLiteralType(type) {
|
|
3051
|
+
return (type.flags & TypeFlags.StringLiteral) !== 0;
|
|
3052
|
+
}
|
|
3053
|
+
export function isNumberLiteralType(type) {
|
|
3054
|
+
return (type.flags & TypeFlags.NumberLiteral) !== 0;
|
|
3055
|
+
}
|
|
3056
|
+
export function isBigIntLiteralType(type) {
|
|
3057
|
+
return (type.flags & TypeFlags.BigIntLiteral) !== 0;
|
|
3058
|
+
}
|
|
3059
|
+
export function isBooleanLiteralType(type) {
|
|
3060
|
+
return (type.flags & TypeFlags.BooleanLiteral) !== 0;
|
|
3061
|
+
}
|
|
3062
|
+
export function isTypeReference(type) {
|
|
3063
|
+
return isObjectType(type) && (type.objectFlags & ObjectFlags.Reference) !== 0;
|
|
3064
|
+
}
|
|
3065
|
+
export function isTupleType(type) {
|
|
3066
|
+
return type.isTupleType();
|
|
3067
|
+
}
|
|
3068
|
+
export function isTupleTypeTarget(type) {
|
|
3069
|
+
return type.isTupleTypeTarget();
|
|
3070
|
+
}
|
|
3071
|
+
export function isIndexType(type) {
|
|
3072
|
+
return (type.flags & TypeFlags.Index) !== 0;
|
|
3073
|
+
}
|
|
3074
|
+
export function isIndexedAccessType(type) {
|
|
3075
|
+
return (type.flags & TypeFlags.IndexedAccess) !== 0;
|
|
3076
|
+
}
|
|
3077
|
+
export function isConditionalType(type) {
|
|
3078
|
+
return (type.flags & TypeFlags.Conditional) !== 0;
|
|
3079
|
+
}
|
|
3080
|
+
export function isSubstitutionType(type) {
|
|
3081
|
+
return (type.flags & TypeFlags.Substitution) !== 0;
|
|
3082
|
+
}
|
|
3083
|
+
export function isTemplateLiteralType(type) {
|
|
3084
|
+
return (type.flags & TypeFlags.TemplateLiteral) !== 0;
|
|
3085
|
+
}
|
|
3086
|
+
export function isStringMappingType(type) {
|
|
3087
|
+
return (type.flags & TypeFlags.StringMapping) !== 0;
|
|
3088
|
+
}
|
|
3089
|
+
export function isTypeParameter(type) {
|
|
3090
|
+
return (type.flags & TypeFlags.TypeParameter) !== 0;
|
|
3091
|
+
}
|
|
3092
|
+
export class Signature {
|
|
3093
|
+
flags;
|
|
3094
|
+
objectRegistry;
|
|
3095
|
+
id;
|
|
3096
|
+
declaration;
|
|
3097
|
+
typeParameters;
|
|
3098
|
+
parameters;
|
|
3099
|
+
thisParameter;
|
|
3100
|
+
target;
|
|
3101
|
+
returnType;
|
|
3102
|
+
constructor(data, project, objectRegistry) {
|
|
3103
|
+
this.id = data.id;
|
|
3104
|
+
this.flags = data.flags;
|
|
3105
|
+
this.objectRegistry = objectRegistry;
|
|
3106
|
+
this.declaration = data.declaration ? new NodeHandle(data.declaration, project) : undefined;
|
|
3107
|
+
this.typeParameters = data.typeParameters ?? [];
|
|
3108
|
+
this.parameters = data.parameters ?? [];
|
|
3109
|
+
this.thisParameter = data.thisParameter;
|
|
3110
|
+
this.target = data.target;
|
|
3111
|
+
this.returnType = false;
|
|
3112
|
+
}
|
|
3113
|
+
async getTypeParameters() {
|
|
3114
|
+
return this.objectRegistry.fetchTypes(this, "getTypeParametersOfSignature", this.typeParameters);
|
|
3115
|
+
}
|
|
3116
|
+
async getParameters() {
|
|
3117
|
+
return this.objectRegistry.fetchSymbols(this, "getParametersOfSignature", this.parameters);
|
|
3118
|
+
}
|
|
3119
|
+
async getThisParameter() {
|
|
3120
|
+
return this.objectRegistry.fetchSymbol(this, "getThisParameterOfSignature", this.thisParameter);
|
|
3121
|
+
}
|
|
3122
|
+
async getTarget() {
|
|
3123
|
+
return this.objectRegistry.fetchSignature(this, "getTargetOfSignature", this.target);
|
|
3124
|
+
}
|
|
3125
|
+
async getReturnType() {
|
|
3126
|
+
const result = await this.objectRegistry.fetchType(this, "getReturnTypeOfSignature", this.returnType);
|
|
3127
|
+
this.returnType = result.id;
|
|
3128
|
+
return result;
|
|
3129
|
+
}
|
|
3130
|
+
getTypeParameterAtPosition(pos) {
|
|
3131
|
+
return this.objectRegistry.fetchTypeParameterAtPosition(this, pos);
|
|
3132
|
+
}
|
|
3133
|
+
get hasRestParameter() {
|
|
3134
|
+
return (this.flags & SignatureFlags.HasRestParameter) !== 0;
|
|
3135
|
+
}
|
|
3136
|
+
get isConstruct() {
|
|
3137
|
+
return (this.flags & SignatureFlags.Construct) !== 0;
|
|
3138
|
+
}
|
|
3139
|
+
get isAbstract() {
|
|
3140
|
+
return (this.flags & SignatureFlags.Abstract) !== 0;
|
|
3141
|
+
}
|
|
3142
|
+
}
|
|
3143
|
+
//# sourceMappingURL=api.js.map
|