Skip to content

Commit bfc3663

Browse files
authored
Add missing APIs required for WebStorm integration. (#4113)
1 parent 23d1c94 commit bfc3663

11 files changed

Lines changed: 1129 additions & 6 deletions

File tree

_packages/native-preview/src/api/async/api.ts

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,14 @@ import type {
6767
AssertsThisTypePredicate,
6868
ConditionalType,
6969
Diagnostic,
70+
FreshableType,
7071
IdentifierTypePredicate,
7172
IndexedAccessType,
7273
IndexInfo,
7374
IndexType,
7475
InterfaceType,
7576
IntersectionType,
77+
IntrinsicType,
7678
LiteralType,
7779
ObjectType,
7880
StringMappingType,
@@ -91,7 +93,7 @@ import type {
9193

9294
export { DiagnosticCategory, ElementFlags, ModifierFlags, NodeBuilderFlags, ObjectFlags, SignatureFlags, SignatureKind, SymbolFlags, TypeFlags, TypePredicateKind };
9395
export type { APIOptions, ClientSocketOptions, ClientSpawnOptions, DocumentIdentifier, DocumentPosition, LSPConnectionOptions };
94-
export type { AssertsIdentifierTypePredicate, AssertsThisTypePredicate, ConditionalType, Diagnostic, IdentifierTypePredicate, IndexedAccessType, IndexInfo, IndexType, InterfaceType, IntersectionType, LiteralType, ObjectType, StringMappingType, SubstitutionType, TemplateLiteralType, ThisTypePredicate, TupleType, Type, TypeParameter, TypePredicate, TypePredicateBase, TypeReference, UnionOrIntersectionType, UnionType };
96+
export type { AssertsIdentifierTypePredicate, AssertsThisTypePredicate, ConditionalType, Diagnostic, FreshableType, IdentifierTypePredicate, IndexedAccessType, IndexInfo, IndexType, InterfaceType, IntersectionType, IntrinsicType, LiteralType, ObjectType, StringMappingType, SubstitutionType, TemplateLiteralType, ThisTypePredicate, TupleType, Type, TypeParameter, TypePredicate, TypePredicateBase, TypeReference, UnionOrIntersectionType, UnionType };
9597
export { documentURIToFileName, fileNameToDocumentURI } from "../path.ts";
9698

9799
/** Type alias for the snapshot-scoped object registry */
@@ -689,6 +691,15 @@ export class Checker {
689691
});
690692
}
691693

694+
async isTypeAssignableTo(source: Type, target: Type): Promise<boolean> {
695+
return this.client.apiRequest<boolean>("isTypeAssignableTo", {
696+
snapshot: this.snapshotId,
697+
project: this.projectId,
698+
source: source.id,
699+
target: target.id,
700+
});
701+
}
702+
692703
async getShorthandAssignmentValueSymbol(node: Node): Promise<Symbol | undefined> {
693704
const data = await this.client.apiRequest<SymbolResponse | null>("getShorthandAssignmentValueSymbol", {
694705
snapshot: this.snapshotId,
@@ -980,10 +991,16 @@ class TypeObject implements Type {
980991
readonly flags: TypeFlags;
981992
readonly objectFlags!: ObjectFlags;
982993
readonly value!: string | number | boolean;
994+
readonly intrinsicName!: string;
995+
readonly isThisType!: boolean;
996+
readonly freshType!: number;
997+
readonly regularType!: number;
983998
readonly target!: number;
984999
readonly typeParameters!: readonly number[];
9851000
readonly outerTypeParameters!: readonly number[];
9861001
readonly localTypeParameters!: readonly number[];
1002+
readonly aliasTypeArguments!: readonly number[];
1003+
readonly aliasSymbol!: number;
9871004
readonly elementFlags!: readonly ElementFlags[];
9881005
readonly fixedLength!: number;
9891006
readonly readonly!: boolean;
@@ -1004,10 +1021,16 @@ class TypeObject implements Type {
10041021
this.flags = data.flags;
10051022
if (data.objectFlags !== undefined) this.objectFlags = data.objectFlags;
10061023
if (data.value !== undefined) this.value = data.value;
1024+
if (data.intrinsicName !== undefined) this.intrinsicName = data.intrinsicName;
1025+
if (data.isThisType !== undefined) this.isThisType = data.isThisType;
1026+
if (data.freshType !== undefined) this.freshType = data.freshType;
1027+
if (data.regularType !== undefined) this.regularType = data.regularType;
10071028
if (data.target !== undefined) this.target = data.target;
10081029
if (data.typeParameters !== undefined) this.typeParameters = data.typeParameters;
10091030
if (data.outerTypeParameters !== undefined) this.outerTypeParameters = data.outerTypeParameters;
10101031
if (data.localTypeParameters !== undefined) this.localTypeParameters = data.localTypeParameters;
1032+
if (data.aliasTypeArguments !== undefined) this.aliasTypeArguments = data.aliasTypeArguments;
1033+
if (data.aliasSymbol !== undefined) this.aliasSymbol = data.aliasSymbol;
10111034
if (data.elementFlags !== undefined) this.elementFlags = data.elementFlags;
10121035
if (data.fixedLength !== undefined) this.fixedLength = data.fixedLength;
10131036
if (data.readonly !== undefined) this.readonly = data.readonly;
@@ -1025,6 +1048,14 @@ class TypeObject implements Type {
10251048
return data ? this.objectRegistry.getOrCreateSymbol(data) : undefined;
10261049
}
10271050

1051+
async getAliasSymbol(): Promise<Symbol | undefined> {
1052+
if (!this.aliasSymbol) return undefined;
1053+
const cached = this.objectRegistry.getSymbol(this.aliasSymbol);
1054+
if (cached) return cached;
1055+
const data = await this.client.apiRequest<SymbolResponse | null>("getAliasSymbolOfType", { snapshot: this.snapshotId, type: this.id });
1056+
return data ? this.objectRegistry.getOrCreateSymbol(data) : undefined;
1057+
}
1058+
10281059
private async fetchType(handle: number | undefined, method: string): Promise<Type> {
10291060
const cached = handle !== undefined ? this.objectRegistry.getType(handle) : undefined;
10301061
if (cached) return cached as Type;
@@ -1042,6 +1073,22 @@ class TypeObject implements Type {
10421073
return this.fetchType(this.target, "getTargetOfType");
10431074
}
10441075

1076+
async getFreshType(): Promise<FreshableType | undefined> {
1077+
if (!this.freshType) return undefined;
1078+
const cached = this.objectRegistry.getType(this.freshType);
1079+
if (cached) return cached as FreshableType;
1080+
const data = await this.client.apiRequest<TypeResponse | null>("getFreshTypeOfType", { snapshot: this.snapshotId, type: this.id });
1081+
return data ? this.objectRegistry.getOrCreateType(data) as FreshableType : undefined;
1082+
}
1083+
1084+
async getRegularType(): Promise<FreshableType | undefined> {
1085+
if (!this.regularType) return undefined;
1086+
const cached = this.objectRegistry.getType(this.regularType);
1087+
if (cached) return cached as FreshableType;
1088+
const data = await this.client.apiRequest<TypeResponse | null>("getRegularTypeOfType", { snapshot: this.snapshotId, type: this.id });
1089+
return data ? this.objectRegistry.getOrCreateType(data) as FreshableType : undefined;
1090+
}
1091+
10451092
async getTypes(): Promise<readonly Type[]> {
10461093
return this.fetchTypes("getTypesOfType");
10471094
}
@@ -1058,6 +1105,10 @@ class TypeObject implements Type {
10581105
return this.fetchTypes("getLocalTypeParametersOfType");
10591106
}
10601107

1108+
async getAliasTypeArguments(): Promise<readonly Type[]> {
1109+
return this.fetchTypes("getAliasTypeArgumentsOfType");
1110+
}
1111+
10611112
async getObjectType(): Promise<Type> {
10621113
return this.fetchType(this.objectType, "getObjectTypeOfType");
10631114
}

_packages/native-preview/src/api/async/types.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,26 @@ export interface Type {
2525

2626
/** Get the symbol associated with this type, if any */
2727
getSymbol(): Promise<Symbol | undefined>;
28+
29+
/** Get the type arguments of the type alias this type was instantiated from, if any */
30+
getAliasTypeArguments(): Promise<readonly Type[]>;
31+
32+
/** Get the symbol of the type alias this type was instantiated from, if any */
33+
getAliasSymbol(): Promise<Symbol | undefined>;
34+
}
35+
36+
/**
37+
* Freshable types (TypeFlags.Freshable) - literal types (TypeFlags.Literal) and computed enum types (TypeFlags.Enum).
38+
*/
39+
export interface FreshableType extends Type {
40+
/** Get the fresh version of this type, if any */
41+
getFreshType(): Promise<FreshableType | undefined>;
42+
/** Get the regular (non-fresh) version of this type, if any */
43+
getRegularType(): Promise<FreshableType | undefined>;
2844
}
2945

3046
/** Literal types: StringLiteral, NumberLiteral, BigIntLiteral, BooleanLiteral */
31-
export interface LiteralType extends Type {
47+
export interface LiteralType extends FreshableType {
3248
/** The literal value */
3349
readonly value: string | number | boolean;
3450
}
@@ -81,6 +97,8 @@ export interface IntersectionType extends UnionOrIntersectionType {
8197

8298
/** Type parameters (TypeFlags.TypeParameter) */
8399
export interface TypeParameter extends Type {
100+
/** True if this is the synthetic `this` type of an interface, class, or tuple */
101+
readonly isThisType?: boolean;
84102
}
85103

86104
/** Index types — keyof T (TypeFlags.Index) */
@@ -125,6 +143,12 @@ export interface StringMappingType extends Type {
125143
getTarget(): Promise<Type>;
126144
}
127145

146+
/** Intrinsic types — any, unknown, string, number, bigint, symbol, void, undefined, null, never, object (TypeFlags.Intrinsic) */
147+
export interface IntrinsicType extends Type {
148+
/** The intrinsic type name (e.g. "any", "string", "never") */
149+
readonly intrinsicName: string;
150+
}
151+
128152
/** Base for all type predicates */
129153
export interface TypePredicateBase {
130154
readonly kind: TypePredicateKind;

_packages/native-preview/src/api/objectRegistry.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ export class ObjectRegistry<
7070
return this.types.get(id);
7171
}
7272

73+
getSymbol(id: number): TSymbol | undefined {
74+
return this.symbols.get(id);
75+
}
76+
7377
getOrCreateSignature(data: SignatureResponse): TSignature {
7478
let signature = this.signatures.get(data.id);
7579
if (signature) {

_packages/native-preview/src/api/proto.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ export interface TypeResponse {
140140
flags: number;
141141
objectFlags?: number;
142142
value?: string | number | boolean;
143+
freshType?: number;
144+
regularType?: number;
143145
target?: number;
144146
typeParameters?: number[];
145147
outerTypeParameters?: number[];
@@ -154,6 +156,10 @@ export interface TypeResponse {
154156
baseType?: number;
155157
substConstraint?: number;
156158
texts?: string[];
159+
intrinsicName?: string;
160+
isThisType?: boolean;
161+
aliasTypeArguments?: number[];
162+
aliasSymbol?: number;
157163
symbol?: number;
158164
}
159165

_packages/native-preview/src/api/sync/api.ts

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,14 @@ import type {
7575
AssertsThisTypePredicate,
7676
ConditionalType,
7777
Diagnostic,
78+
FreshableType,
7879
IdentifierTypePredicate,
7980
IndexedAccessType,
8081
IndexInfo,
8182
IndexType,
8283
InterfaceType,
8384
IntersectionType,
85+
IntrinsicType,
8486
LiteralType,
8587
ObjectType,
8688
StringMappingType,
@@ -99,7 +101,7 @@ import type {
99101

100102
export { DiagnosticCategory, ElementFlags, ModifierFlags, NodeBuilderFlags, ObjectFlags, SignatureFlags, SignatureKind, SymbolFlags, TypeFlags, TypePredicateKind };
101103
export type { APIOptions, ClientSocketOptions, ClientSpawnOptions, DocumentIdentifier, DocumentPosition, LSPConnectionOptions };
102-
export type { AssertsIdentifierTypePredicate, AssertsThisTypePredicate, ConditionalType, Diagnostic, IdentifierTypePredicate, IndexedAccessType, IndexInfo, IndexType, InterfaceType, IntersectionType, LiteralType, ObjectType, StringMappingType, SubstitutionType, TemplateLiteralType, ThisTypePredicate, TupleType, Type, TypeParameter, TypePredicate, TypePredicateBase, TypeReference, UnionOrIntersectionType, UnionType };
104+
export type { AssertsIdentifierTypePredicate, AssertsThisTypePredicate, ConditionalType, Diagnostic, FreshableType, IdentifierTypePredicate, IndexedAccessType, IndexInfo, IndexType, InterfaceType, IntersectionType, IntrinsicType, LiteralType, ObjectType, StringMappingType, SubstitutionType, TemplateLiteralType, ThisTypePredicate, TupleType, Type, TypeParameter, TypePredicate, TypePredicateBase, TypeReference, UnionOrIntersectionType, UnionType };
103105
export { documentURIToFileName, fileNameToDocumentURI } from "../path.ts";
104106

105107
/** Type alias for the snapshot-scoped object registry */
@@ -697,6 +699,15 @@ export class Checker {
697699
});
698700
}
699701

702+
isTypeAssignableTo(source: Type, target: Type): boolean {
703+
return this.client.apiRequest<boolean>("isTypeAssignableTo", {
704+
snapshot: this.snapshotId,
705+
project: this.projectId,
706+
source: source.id,
707+
target: target.id,
708+
});
709+
}
710+
700711
getShorthandAssignmentValueSymbol(node: Node): Symbol | undefined {
701712
const data = this.client.apiRequest<SymbolResponse | null>("getShorthandAssignmentValueSymbol", {
702713
snapshot: this.snapshotId,
@@ -988,10 +999,16 @@ class TypeObject implements Type {
988999
readonly flags: TypeFlags;
9891000
readonly objectFlags!: ObjectFlags;
9901001
readonly value!: string | number | boolean;
1002+
readonly intrinsicName!: string;
1003+
readonly isThisType!: boolean;
1004+
readonly freshType!: number;
1005+
readonly regularType!: number;
9911006
readonly target!: number;
9921007
readonly typeParameters!: readonly number[];
9931008
readonly outerTypeParameters!: readonly number[];
9941009
readonly localTypeParameters!: readonly number[];
1010+
readonly aliasTypeArguments!: readonly number[];
1011+
readonly aliasSymbol!: number;
9951012
readonly elementFlags!: readonly ElementFlags[];
9961013
readonly fixedLength!: number;
9971014
readonly readonly!: boolean;
@@ -1012,10 +1029,16 @@ class TypeObject implements Type {
10121029
this.flags = data.flags;
10131030
if (data.objectFlags !== undefined) this.objectFlags = data.objectFlags;
10141031
if (data.value !== undefined) this.value = data.value;
1032+
if (data.intrinsicName !== undefined) this.intrinsicName = data.intrinsicName;
1033+
if (data.isThisType !== undefined) this.isThisType = data.isThisType;
1034+
if (data.freshType !== undefined) this.freshType = data.freshType;
1035+
if (data.regularType !== undefined) this.regularType = data.regularType;
10151036
if (data.target !== undefined) this.target = data.target;
10161037
if (data.typeParameters !== undefined) this.typeParameters = data.typeParameters;
10171038
if (data.outerTypeParameters !== undefined) this.outerTypeParameters = data.outerTypeParameters;
10181039
if (data.localTypeParameters !== undefined) this.localTypeParameters = data.localTypeParameters;
1040+
if (data.aliasTypeArguments !== undefined) this.aliasTypeArguments = data.aliasTypeArguments;
1041+
if (data.aliasSymbol !== undefined) this.aliasSymbol = data.aliasSymbol;
10191042
if (data.elementFlags !== undefined) this.elementFlags = data.elementFlags;
10201043
if (data.fixedLength !== undefined) this.fixedLength = data.fixedLength;
10211044
if (data.readonly !== undefined) this.readonly = data.readonly;
@@ -1033,6 +1056,14 @@ class TypeObject implements Type {
10331056
return data ? this.objectRegistry.getOrCreateSymbol(data) : undefined;
10341057
}
10351058

1059+
getAliasSymbol(): Symbol | undefined {
1060+
if (!this.aliasSymbol) return undefined;
1061+
const cached = this.objectRegistry.getSymbol(this.aliasSymbol);
1062+
if (cached) return cached;
1063+
const data = this.client.apiRequest<SymbolResponse | null>("getAliasSymbolOfType", { snapshot: this.snapshotId, type: this.id });
1064+
return data ? this.objectRegistry.getOrCreateSymbol(data) : undefined;
1065+
}
1066+
10361067
private fetchType(handle: number | undefined, method: string): Type {
10371068
const cached = handle !== undefined ? this.objectRegistry.getType(handle) : undefined;
10381069
if (cached) return cached as Type;
@@ -1050,6 +1081,22 @@ class TypeObject implements Type {
10501081
return this.fetchType(this.target, "getTargetOfType");
10511082
}
10521083

1084+
getFreshType(): FreshableType | undefined {
1085+
if (!this.freshType) return undefined;
1086+
const cached = this.objectRegistry.getType(this.freshType);
1087+
if (cached) return cached as FreshableType;
1088+
const data = this.client.apiRequest<TypeResponse | null>("getFreshTypeOfType", { snapshot: this.snapshotId, type: this.id });
1089+
return data ? this.objectRegistry.getOrCreateType(data) as FreshableType : undefined;
1090+
}
1091+
1092+
getRegularType(): FreshableType | undefined {
1093+
if (!this.regularType) return undefined;
1094+
const cached = this.objectRegistry.getType(this.regularType);
1095+
if (cached) return cached as FreshableType;
1096+
const data = this.client.apiRequest<TypeResponse | null>("getRegularTypeOfType", { snapshot: this.snapshotId, type: this.id });
1097+
return data ? this.objectRegistry.getOrCreateType(data) as FreshableType : undefined;
1098+
}
1099+
10531100
getTypes(): readonly Type[] {
10541101
return this.fetchTypes("getTypesOfType");
10551102
}
@@ -1066,6 +1113,10 @@ class TypeObject implements Type {
10661113
return this.fetchTypes("getLocalTypeParametersOfType");
10671114
}
10681115

1116+
getAliasTypeArguments(): readonly Type[] {
1117+
return this.fetchTypes("getAliasTypeArgumentsOfType");
1118+
}
1119+
10691120
getObjectType(): Type {
10701121
return this.fetchType(this.objectType, "getObjectTypeOfType");
10711122
}

_packages/native-preview/src/api/sync/types.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,26 @@ export interface Type {
3333

3434
/** Get the symbol associated with this type, if any */
3535
getSymbol(): Symbol | undefined;
36+
37+
/** Get the type arguments of the type alias this type was instantiated from, if any */
38+
getAliasTypeArguments(): readonly Type[];
39+
40+
/** Get the symbol of the type alias this type was instantiated from, if any */
41+
getAliasSymbol(): Symbol | undefined;
42+
}
43+
44+
/**
45+
* Freshable types (TypeFlags.Freshable) - literal types (TypeFlags.Literal) and computed enum types (TypeFlags.Enum).
46+
*/
47+
export interface FreshableType extends Type {
48+
/** Get the fresh version of this type, if any */
49+
getFreshType(): FreshableType | undefined;
50+
/** Get the regular (non-fresh) version of this type, if any */
51+
getRegularType(): FreshableType | undefined;
3652
}
3753

3854
/** Literal types: StringLiteral, NumberLiteral, BigIntLiteral, BooleanLiteral */
39-
export interface LiteralType extends Type {
55+
export interface LiteralType extends FreshableType {
4056
/** The literal value */
4157
readonly value: string | number | boolean;
4258
}
@@ -89,6 +105,8 @@ export interface IntersectionType extends UnionOrIntersectionType {
89105

90106
/** Type parameters (TypeFlags.TypeParameter) */
91107
export interface TypeParameter extends Type {
108+
/** True if this is the synthetic `this` type of an interface, class, or tuple */
109+
readonly isThisType?: boolean;
92110
}
93111

94112
/** Index types — keyof T (TypeFlags.Index) */
@@ -133,6 +151,12 @@ export interface StringMappingType extends Type {
133151
getTarget(): Type;
134152
}
135153

154+
/** Intrinsic types — any, unknown, string, number, bigint, symbol, void, undefined, null, never, object (TypeFlags.Intrinsic) */
155+
export interface IntrinsicType extends Type {
156+
/** The intrinsic type name (e.g. "any", "string", "never") */
157+
readonly intrinsicName: string;
158+
}
159+
136160
/** Base for all type predicates */
137161
export interface TypePredicateBase {
138162
readonly kind: TypePredicateKind;

0 commit comments

Comments
 (0)