Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions packages/typescript/src/api/async/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,22 @@ import { TypeFormatFlags } from "../../../enums/typeFormatFlags.js";
import { TypePredicateKind } from "../../../enums/typePredicateKind.js";
import {
type __String,
type ArrayLiteralExpression,
type CallLikeExpression,
type Declaration,
type Expression,
type FileReference,
type Identifier,
type ImportTypeNode,
type IndexSignatureDeclaration,
ModifierFlags,
type NamedTupleMember,
type Node,
type ObjectLiteralExpression,
type ParameterDeclaration,
type PathKey,
type PropertyAccessExpression,
type QualifiedName,
type RootedDirectoryPath,
type RootedFilePath,
type SourceFile,
Expand Down Expand Up @@ -2331,6 +2336,63 @@ function encodeNumberLiteralValue(value: number): number | string {
}

export class Checker {
/** Get the original symbols underlying a synthetic, instantiated, or mapped property. */
async getRootSymbols(symbol: Symbol): Promise<readonly Symbol[]> {
const data = await this.client.apiRequest("getRootSymbols", {
snapshot: this.snapshotId,
project: this.project.handle,
symbol: symbol.reference,
});
return data ? data.map(symbol => this.objectRegistry.getOrCreateSymbol(symbol)) : [];
}

/** Get inferred or explicit signature type arguments; empty when the signature has no instantiation. */
async getTypeArgumentsForResolvedSignature(signature: Signature): Promise<readonly Type[]> {
return signature.getTypeArguments();
}

/** Get the source type of an object/array assignment pattern, including nested patterns and for-of initializers. */
async getTypeOfAssignmentPattern(node: ObjectLiteralExpression | ArrayLiteralExpression): Promise<Type | undefined> {
const data = await this.client.apiRequest("getTypeOfAssignmentPattern", {
snapshot: this.snapshotId,
project: this.project.handle,
location: getNodeRequestHandle(node),
});
return data ? this.objectRegistry.getOrCreateType(data) : undefined;
}

/** Get the distinct constructor parameter and instance property symbols of a parameter property. */
async getSymbolsOfParameterPropertyDeclaration(node: ParameterDeclaration): Promise<{ parameter: Symbol; property: Symbol; }> {
const data = await this.client.apiRequest("getSymbolsOfParameterPropertyDeclaration", {
snapshot: this.snapshotId,
project: this.project.handle,
location: getNodeRequestHandle(node),
});
return {
parameter: this.objectRegistry.getOrCreateSymbol(data.parameter),
property: this.objectRegistry.getOrCreateSymbol(data.property),
};
}

/** Whether the named property exists and is accessible at this access location. */
async isValidPropertyAccess(node: PropertyAccessExpression | QualifiedName | ImportTypeNode, propertyName: string): Promise<boolean> {
return this.client.apiRequest("isValidPropertyAccess", {
snapshot: this.snapshotId,
project: this.project.handle,
location: getNodeRequestHandle(node),
propertyName,
});
}

/** Whether a parameter may be omitted, including defaults and untyped IIFE parameters. */
async isOptionalParameter(node: ParameterDeclaration): Promise<boolean> {
return this.client.apiRequest("isOptionalParameter", {
snapshot: this.snapshotId,
project: this.project.handle,
location: getNodeRequestHandle(node),
});
}

private snapshotId: number;
private project: Project;
private objectRegistry: ProjectObjectRegistry;
Expand Down Expand Up @@ -4114,6 +4176,7 @@ export class Signature {
readonly thisParameter?: CompactSymbolReference | undefined;
readonly target?: number | undefined;
private returnType: number | false;
private typeArguments: readonly number[] | false;

constructor(data: SignatureResponse, project: Project, objectRegistry: ProjectObjectRegistry) {
this.id = data.id;
Expand All @@ -4127,6 +4190,7 @@ export class Signature {
this.thisParameter = data.thisParameter;
this.target = data.target;
this.returnType = false;
this.typeArguments = false;
}

get declaration(): NodeHandle<Declaration> | undefined {
Expand All @@ -4140,6 +4204,13 @@ export class Signature {
return this.objectRegistry.fetchTypes(this, "getTypeParametersOfSignature", this.typeParameters) as Promise<readonly TypeParameter[]>;
}

/** Get inferred or explicit type arguments; empty when this signature has no instantiation. */
async getTypeArguments(): Promise<readonly Type[]> {
const result = await this.objectRegistry.fetchTypes(this, "getTypeArgumentsForResolvedSignature", this.typeArguments || undefined);
this.typeArguments = result.map(type => type.id);
return result;
}

async getParameters(): Promise<readonly Symbol[]> {
return this.objectRegistry.fetchSymbols(this, "getParametersOfSignature", this.parameters);
}
Expand Down
44 changes: 37 additions & 7 deletions packages/typescript/src/api/proto.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,14 @@ export interface APIMethodInfo {
getNameTypeOfMappedType: APIMethod<GetTypePropertyParams, TypeResponse | null>;
getTemplateTypeOfMappedType: APIMethod<GetTypePropertyParams, TypeResponse>;
getTypeParametersOfSignature: APIMethod<GetSignaturePropertyParams, TypeResponse[] | null>;
getTypeArgumentsForResolvedSignature: APIMethod<GetSignaturePropertyParams, TypeResponse[]>;
getParametersOfSignature: APIMethod<GetSignaturePropertyParams, SymbolResponse[] | null>;
getThisParameterOfSignature: APIMethod<GetSignaturePropertyParams, SymbolResponse | null>;
getTargetOfSignature: APIMethod<GetSignaturePropertyParams, SignatureResponse | null>;
isOptionalParameter: APIMethod<CheckerNodeParams, boolean>;
getTypeOfAssignmentPattern: APIMethod<CheckerNodeParams, TypeResponse | null>;
isValidPropertyAccess: APIMethod<IsValidPropertyAccessParams, boolean>;
getSymbolsOfParameterPropertyDeclaration: APIMethod<CheckerNodeParams, ParameterPropertySymbolsResponse>;
getContextualType: APIMethod<GetContextualTypeParams, TypeResponse | null>;
getContextualTypeForArgument: APIMethod<GetContextualTypeForArgumentParams, TypeResponse | null>;
getAwaitedType: APIMethod<CheckerTypeParams, TypeResponse | null>;
Expand Down Expand Up @@ -179,6 +184,7 @@ export interface APIMethodInfo {
getImmediateAliasedSymbol: APIMethod<CheckerSymbolParams, SymbolResponse | null>;
getTargetSymbol: APIMethod<CheckerSymbolParams, SymbolResponse>;
getMergedSymbol: APIMethod<CheckerSymbolParams, SymbolResponse>;
getRootSymbols: APIMethod<CheckerSymbolParams, SymbolResponse[]>;
getSymbolOfNode: APIMethod<CheckerNodeParams, SymbolResponse | null>;
getSymbolOfDeclarationForChecker: APIMethod<CheckerNodeParams, SymbolResponse | null>;
getParentOfSymbolForChecker: APIMethod<CheckerSymbolParams, SymbolResponse | null>;
Expand Down Expand Up @@ -798,6 +804,25 @@ export interface GetSignaturePropertyParams {
objectId: number;
}

/** CheckerNodeParams are parameters for checker methods that operate on a node location. */
export interface CheckerNodeParams {
snapshot: number;
project: number;
location: string;
}

export interface IsValidPropertyAccessParams {
snapshot: number;
project: number;
location: string;
propertyName: string;
}

export interface ParameterPropertySymbolsResponse {
parameter: SymbolResponse;
property: SymbolResponse;
}

/** GetContextualTypeParams returns the contextual type for a node. */
export interface GetContextualTypeParams {
snapshot: number;
Expand Down Expand Up @@ -864,13 +889,6 @@ export interface GetIntrinsicTypeParams {
project: number;
}

/** CheckerNodeParams are parameters for checker methods that operate on a node location. */
export interface CheckerNodeParams {
snapshot: number;
project: number;
location: string;
}

export interface GetPrivateIdentifierPropertyOfTypeParams {
snapshot: number;
project: number;
Expand Down Expand Up @@ -1321,6 +1339,7 @@ export interface BatchRequest {
| "getResolvedTypeReferenceDirectiveFromTypeReferenceDirective"
| "getRestTypeOfSignature"
| "getReturnTypeOfSignature"
| "getRootSymbols"
| "getSemanticDiagnostics"
| "getShorthandAssignmentValueSymbol"
| "getSignatureFromDeclaration"
Expand All @@ -1342,6 +1361,7 @@ export interface BatchRequest {
| "getSymbolsAtLocations"
| "getSymbolsAtPositions"
| "getSymbolsInScope"
| "getSymbolsOfParameterPropertyDeclaration"
| "getSymbolsOfSourceFiles"
| "getSyntacticDiagnostics"
| "getTargetOfSignature"
Expand All @@ -1353,10 +1373,12 @@ export interface BatchRequest {
| "getTrueType"
| "getTrueTypeOfConditionalType"
| "getTypeArguments"
| "getTypeArgumentsForResolvedSignature"
| "getTypeAtLocation"
| "getTypeAtLocations"
| "getTypeAtPosition"
| "getTypeFromTypeNode"
| "getTypeOfAssignmentPattern"
| "getTypeOfPropertyOfType"
| "getTypeOfSymbol"
| "getTypeOfSymbolAtLocation"
Expand All @@ -1379,8 +1401,10 @@ export interface BatchRequest {
| "isArrayType"
| "isContextSensitive"
| "isImplementationOfOverload"
| "isOptionalParameter"
| "isReadonlySymbol"
| "isTypeAssignableTo"
| "isValidPropertyAccess"
| "parseCommandLine"
| "parseConfigFile"
| "parseConfigFileTextToJson"
Expand Down Expand Up @@ -1516,6 +1540,7 @@ export interface BatchResponse {
| "getResolvedTypeReferenceDirectiveFromTypeReferenceDirective"
| "getRestTypeOfSignature"
| "getReturnTypeOfSignature"
| "getRootSymbols"
| "getSemanticDiagnostics"
| "getShorthandAssignmentValueSymbol"
| "getSignatureFromDeclaration"
Expand All @@ -1537,6 +1562,7 @@ export interface BatchResponse {
| "getSymbolsAtLocations"
| "getSymbolsAtPositions"
| "getSymbolsInScope"
| "getSymbolsOfParameterPropertyDeclaration"
| "getSymbolsOfSourceFiles"
| "getSyntacticDiagnostics"
| "getTargetOfSignature"
Expand All @@ -1548,10 +1574,12 @@ export interface BatchResponse {
| "getTrueType"
| "getTrueTypeOfConditionalType"
| "getTypeArguments"
| "getTypeArgumentsForResolvedSignature"
| "getTypeAtLocation"
| "getTypeAtLocations"
| "getTypeAtPosition"
| "getTypeFromTypeNode"
| "getTypeOfAssignmentPattern"
| "getTypeOfPropertyOfType"
| "getTypeOfSymbol"
| "getTypeOfSymbolAtLocation"
Expand All @@ -1574,8 +1602,10 @@ export interface BatchResponse {
| "isArrayType"
| "isContextSensitive"
| "isImplementationOfOverload"
| "isOptionalParameter"
| "isReadonlySymbol"
| "isTypeAssignableTo"
| "isValidPropertyAccess"
| "parseCommandLine"
| "parseConfigFile"
| "parseConfigFileTextToJson"
Expand Down
Loading
Loading