Skip to content

Commit 1b81e8f

Browse files
authored
Exposing more endpoints (#3403)
1 parent 5a31703 commit 1b81e8f

10 files changed

Lines changed: 472 additions & 2 deletions

File tree

Herebyfile.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ const enumDefs = [
323323
{ name: "OuterExpressionKinds", goPrefix: "OEK", goFile: "internal/ast/utilities.go", outDir: "_packages/native-preview/src/enums" },
324324
{ name: "ModifierFlags", goPrefix: "ModifierFlags", goFile: "internal/ast/modifierflags.go", outDir: "_packages/native-preview/src/enums" },
325325
{ name: "TokenFlags", goPrefix: "TokenFlags", goFile: "internal/ast/tokenflags.go", outDir: "_packages/native-preview/src/enums", constEnum: true },
326+
{ name: "NodeBuilderFlags", goPrefix: "Flags", goFile: "internal/nodebuilder/types.go", outDir: "_packages/native-preview/src/enums" },
326327
];
327328

328329
/**

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

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/// <reference path="../node/node.ts" preserve="true" />
22
import { DiagnosticCategory } from "#enums/diagnosticCategory";
33
import { ElementFlags } from "#enums/elementFlags";
4+
import { NodeBuilderFlags } from "#enums/nodeBuilderFlags";
45
import { ObjectFlags } from "#enums/objectFlags";
56
import { SignatureFlags } from "#enums/signatureFlags";
67
import { SignatureKind } from "#enums/signatureKind";
@@ -88,7 +89,7 @@ import type {
8889
UnionType,
8990
} from "./types.ts";
9091

91-
export { DiagnosticCategory, ElementFlags, ModifierFlags, ObjectFlags, SignatureFlags, SignatureKind, SymbolFlags, TypeFlags, TypePredicateKind };
92+
export { DiagnosticCategory, ElementFlags, ModifierFlags, NodeBuilderFlags, ObjectFlags, SignatureFlags, SignatureKind, SymbolFlags, TypeFlags, TypePredicateKind };
9293
export type { APIOptions, ClientSocketOptions, ClientSpawnOptions, DocumentIdentifier, DocumentPosition, LSPConnectionOptions };
9394
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 };
9495
export { documentURIToFileName, fileNameToDocumentURI } from "../path.ts";
@@ -538,6 +539,15 @@ export class Checker {
538539
return data.map(d => this.objectRegistry.getOrCreateSignature(d));
539540
}
540541

542+
async getResolvedSignature(node: Node): Promise<Signature | undefined> {
543+
const data = await this.client.apiRequest<SignatureResponse | null>("getResolvedSignature", {
544+
snapshot: this.snapshotId,
545+
project: this.projectId,
546+
location: getNodeId(node),
547+
});
548+
return data ? this.objectRegistry.getOrCreateSignature(data) : undefined;
549+
}
550+
541551
getTypeAtPosition(file: DocumentIdentifier, position: number): Promise<Type | undefined>;
542552
getTypeAtPosition(file: DocumentIdentifier, positions: readonly number[]): Promise<(Type | undefined)[]>;
543553
async getTypeAtPosition(file: DocumentIdentifier, positionOrPositions: number | readonly number[]): Promise<Type | (Type | undefined)[] | undefined> {
@@ -604,6 +614,51 @@ export class Checker {
604614
return data ? this.objectRegistry.getOrCreateType(data) : undefined;
605615
}
606616

617+
async getNonNullableType(type: Type): Promise<Type | undefined> {
618+
const data = await this.client.apiRequest<TypeResponse | null>("getNonNullableType", {
619+
snapshot: this.snapshotId,
620+
project: this.projectId,
621+
type: type.id,
622+
});
623+
return data ? this.objectRegistry.getOrCreateType(data) : undefined;
624+
}
625+
626+
async getTypeFromTypeNode(node: TypeNode): Promise<Type | undefined> {
627+
const data = await this.client.apiRequest<TypeResponse | null>("getTypeFromTypeNode", {
628+
snapshot: this.snapshotId,
629+
project: this.projectId,
630+
location: getNodeId(node),
631+
});
632+
return data ? this.objectRegistry.getOrCreateType(data) : undefined;
633+
}
634+
635+
async getWidenedType(type: Type): Promise<Type | undefined> {
636+
const data = await this.client.apiRequest<TypeResponse | null>("getWidenedType", {
637+
snapshot: this.snapshotId,
638+
project: this.projectId,
639+
type: type.id,
640+
});
641+
return data ? this.objectRegistry.getOrCreateType(data) : undefined;
642+
}
643+
644+
async getParameterType(signature: Signature, index: number): Promise<Type | undefined> {
645+
const data = await this.client.apiRequest<TypeResponse | null>("getParameterType", {
646+
snapshot: this.snapshotId,
647+
project: this.projectId,
648+
signature: signature.id,
649+
index,
650+
});
651+
return data ? this.objectRegistry.getOrCreateType(data) : undefined;
652+
}
653+
654+
async isArrayLikeType(type: Type): Promise<boolean> {
655+
return this.client.apiRequest<boolean>("isArrayLikeType", {
656+
snapshot: this.snapshotId,
657+
project: this.projectId,
658+
type: type.id,
659+
});
660+
}
661+
607662
async getShorthandAssignmentValueSymbol(node: Node): Promise<Symbol | undefined> {
608663
const data = await this.client.apiRequest<SymbolResponse | null>("getShorthandAssignmentValueSymbol", {
609664
snapshot: this.snapshotId,
@@ -677,6 +732,19 @@ export class Checker {
677732
return decodeNode(binaryData) as TypeNode;
678733
}
679734

735+
async signatureToSignatureDeclaration(signature: Signature, kind: SyntaxKind, enclosingDeclaration?: Node, flags?: NodeBuilderFlags): Promise<Node | undefined> {
736+
const binaryData = await this.client.apiRequestBinary("signatureToSignatureDeclaration", {
737+
snapshot: this.snapshotId,
738+
project: this.projectId,
739+
signature: signature.id,
740+
kind,
741+
location: enclosingDeclaration ? getNodeId(enclosingDeclaration) : undefined,
742+
flags,
743+
});
744+
if (!binaryData) return undefined;
745+
return decodeNode(binaryData) as Node;
746+
}
747+
680748
async typeToString(type: Type, enclosingDeclaration?: Node, flags?: number): Promise<string> {
681749
return this.client.apiRequest<string>("typeToString", {
682750
snapshot: this.snapshotId,

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

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
/// <reference path="../node/node.ts" preserve="true" />
1010
import { DiagnosticCategory } from "#enums/diagnosticCategory";
1111
import { ElementFlags } from "#enums/elementFlags";
12+
import { NodeBuilderFlags } from "#enums/nodeBuilderFlags";
1213
import { ObjectFlags } from "#enums/objectFlags";
1314
import { SignatureFlags } from "#enums/signatureFlags";
1415
import { SignatureKind } from "#enums/signatureKind";
@@ -96,7 +97,7 @@ import type {
9697
UnionType,
9798
} from "./types.ts";
9899

99-
export { DiagnosticCategory, ElementFlags, ModifierFlags, ObjectFlags, SignatureFlags, SignatureKind, SymbolFlags, TypeFlags, TypePredicateKind };
100+
export { DiagnosticCategory, ElementFlags, ModifierFlags, NodeBuilderFlags, ObjectFlags, SignatureFlags, SignatureKind, SymbolFlags, TypeFlags, TypePredicateKind };
100101
export type { APIOptions, ClientSocketOptions, ClientSpawnOptions, DocumentIdentifier, DocumentPosition, LSPConnectionOptions };
101102
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 };
102103
export { documentURIToFileName, fileNameToDocumentURI } from "../path.ts";
@@ -546,6 +547,15 @@ export class Checker {
546547
return data.map(d => this.objectRegistry.getOrCreateSignature(d));
547548
}
548549

550+
getResolvedSignature(node: Node): Signature | undefined {
551+
const data = this.client.apiRequest<SignatureResponse | null>("getResolvedSignature", {
552+
snapshot: this.snapshotId,
553+
project: this.projectId,
554+
location: getNodeId(node),
555+
});
556+
return data ? this.objectRegistry.getOrCreateSignature(data) : undefined;
557+
}
558+
549559
getTypeAtPosition(file: DocumentIdentifier, position: number): Type | undefined;
550560
getTypeAtPosition(file: DocumentIdentifier, positions: readonly number[]): (Type | undefined)[];
551561
getTypeAtPosition(file: DocumentIdentifier, positionOrPositions: number | readonly number[]): Type | (Type | undefined)[] | undefined {
@@ -612,6 +622,51 @@ export class Checker {
612622
return data ? this.objectRegistry.getOrCreateType(data) : undefined;
613623
}
614624

625+
getNonNullableType(type: Type): Type | undefined {
626+
const data = this.client.apiRequest<TypeResponse | null>("getNonNullableType", {
627+
snapshot: this.snapshotId,
628+
project: this.projectId,
629+
type: type.id,
630+
});
631+
return data ? this.objectRegistry.getOrCreateType(data) : undefined;
632+
}
633+
634+
getTypeFromTypeNode(node: TypeNode): Type | undefined {
635+
const data = this.client.apiRequest<TypeResponse | null>("getTypeFromTypeNode", {
636+
snapshot: this.snapshotId,
637+
project: this.projectId,
638+
location: getNodeId(node),
639+
});
640+
return data ? this.objectRegistry.getOrCreateType(data) : undefined;
641+
}
642+
643+
getWidenedType(type: Type): Type | undefined {
644+
const data = this.client.apiRequest<TypeResponse | null>("getWidenedType", {
645+
snapshot: this.snapshotId,
646+
project: this.projectId,
647+
type: type.id,
648+
});
649+
return data ? this.objectRegistry.getOrCreateType(data) : undefined;
650+
}
651+
652+
getParameterType(signature: Signature, index: number): Type | undefined {
653+
const data = this.client.apiRequest<TypeResponse | null>("getParameterType", {
654+
snapshot: this.snapshotId,
655+
project: this.projectId,
656+
signature: signature.id,
657+
index,
658+
});
659+
return data ? this.objectRegistry.getOrCreateType(data) : undefined;
660+
}
661+
662+
isArrayLikeType(type: Type): boolean {
663+
return this.client.apiRequest<boolean>("isArrayLikeType", {
664+
snapshot: this.snapshotId,
665+
project: this.projectId,
666+
type: type.id,
667+
});
668+
}
669+
615670
getShorthandAssignmentValueSymbol(node: Node): Symbol | undefined {
616671
const data = this.client.apiRequest<SymbolResponse | null>("getShorthandAssignmentValueSymbol", {
617672
snapshot: this.snapshotId,
@@ -685,6 +740,19 @@ export class Checker {
685740
return decodeNode(binaryData) as TypeNode;
686741
}
687742

743+
signatureToSignatureDeclaration(signature: Signature, kind: SyntaxKind, enclosingDeclaration?: Node, flags?: NodeBuilderFlags): Node | undefined {
744+
const binaryData = this.client.apiRequestBinary("signatureToSignatureDeclaration", {
745+
snapshot: this.snapshotId,
746+
project: this.projectId,
747+
signature: signature.id,
748+
kind,
749+
location: enclosingDeclaration ? getNodeId(enclosingDeclaration) : undefined,
750+
flags,
751+
});
752+
if (!binaryData) return undefined;
753+
return decodeNode(binaryData) as Node;
754+
}
755+
688756
typeToString(type: Type, enclosingDeclaration?: Node, flags?: number): string {
689757
return this.client.apiRequest<string>("typeToString", {
690758
snapshot: this.snapshotId,
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Code generated by Herebyfile.mjs generate:enums from internal/nodebuilder/types.go. DO NOT EDIT.
2+
3+
export enum NodeBuilderFlags {
4+
None = 0,
5+
NoTruncation = 1 << 0,
6+
WriteArrayAsGenericType = 1 << 1,
7+
GenerateNamesForShadowedTypeParams = 1 << 2,
8+
UseStructuralFallback = 1 << 3,
9+
ForbidIndexedAccessSymbolReferences = 1 << 4,
10+
WriteTypeArgumentsOfSignature = 1 << 5,
11+
UseFullyQualifiedType = 1 << 6,
12+
UseOnlyExternalAliasing = 1 << 7,
13+
SuppressAnyReturnType = 1 << 8,
14+
WriteTypeParametersInQualifiedName = 1 << 9,
15+
MultilineObjectLiterals = 1 << 10,
16+
WriteClassExpressionAsTypeLiteral = 1 << 11,
17+
UseTypeOfFunction = 1 << 12,
18+
OmitParameterModifiers = 1 << 13,
19+
UseAliasDefinedOutsideCurrentScope = 1 << 14,
20+
UseSingleQuotesForStringLiteralType = 1 << 28,
21+
NoTypeReduction = 1 << 29,
22+
UseInstantiationExpressions = 1 << 30,
23+
OmitThisParameter = 1 << 25,
24+
WriteCallStyleSignature = 1 << 27,
25+
AllowThisInObjectLiteral = 1 << 15,
26+
AllowQualifiedNameInPlaceOfIdentifier = 1 << 16,
27+
AllowAnonymousIdentifier = 1 << 17,
28+
AllowEmptyUnionOrIntersection = 1 << 18,
29+
AllowEmptyTuple = 1 << 19,
30+
AllowUniqueESSymbolType = 1 << 20,
31+
AllowEmptyIndexInfoType = 1 << 21,
32+
AllowNodeModulesRelativePaths = 1 << 26,
33+
IgnoreErrors = AllowThisInObjectLiteral | AllowQualifiedNameInPlaceOfIdentifier | AllowAnonymousIdentifier | AllowEmptyUnionOrIntersection | AllowEmptyTuple | AllowEmptyIndexInfoType | AllowNodeModulesRelativePaths,
34+
InObjectTypeLiteral = 1 << 22,
35+
InTypeAlias = 1 << 23,
36+
InInitialEntityName = 1 << 24,
37+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Code generated by Herebyfile.mjs generate:enums from internal/nodebuilder/types.go. DO NOT EDIT.
2+
export var NodeBuilderFlags: any;
3+
(function (NodeBuilderFlags) {
4+
NodeBuilderFlags[NodeBuilderFlags["None"] = 0] = "None";
5+
NodeBuilderFlags[NodeBuilderFlags["NoTruncation"] = 1] = "NoTruncation";
6+
NodeBuilderFlags[NodeBuilderFlags["WriteArrayAsGenericType"] = 2] = "WriteArrayAsGenericType";
7+
NodeBuilderFlags[NodeBuilderFlags["GenerateNamesForShadowedTypeParams"] = 4] = "GenerateNamesForShadowedTypeParams";
8+
NodeBuilderFlags[NodeBuilderFlags["UseStructuralFallback"] = 8] = "UseStructuralFallback";
9+
NodeBuilderFlags[NodeBuilderFlags["ForbidIndexedAccessSymbolReferences"] = 16] = "ForbidIndexedAccessSymbolReferences";
10+
NodeBuilderFlags[NodeBuilderFlags["WriteTypeArgumentsOfSignature"] = 32] = "WriteTypeArgumentsOfSignature";
11+
NodeBuilderFlags[NodeBuilderFlags["UseFullyQualifiedType"] = 64] = "UseFullyQualifiedType";
12+
NodeBuilderFlags[NodeBuilderFlags["UseOnlyExternalAliasing"] = 128] = "UseOnlyExternalAliasing";
13+
NodeBuilderFlags[NodeBuilderFlags["SuppressAnyReturnType"] = 256] = "SuppressAnyReturnType";
14+
NodeBuilderFlags[NodeBuilderFlags["WriteTypeParametersInQualifiedName"] = 512] = "WriteTypeParametersInQualifiedName";
15+
NodeBuilderFlags[NodeBuilderFlags["MultilineObjectLiterals"] = 1024] = "MultilineObjectLiterals";
16+
NodeBuilderFlags[NodeBuilderFlags["WriteClassExpressionAsTypeLiteral"] = 2048] = "WriteClassExpressionAsTypeLiteral";
17+
NodeBuilderFlags[NodeBuilderFlags["UseTypeOfFunction"] = 4096] = "UseTypeOfFunction";
18+
NodeBuilderFlags[NodeBuilderFlags["OmitParameterModifiers"] = 8192] = "OmitParameterModifiers";
19+
NodeBuilderFlags[NodeBuilderFlags["UseAliasDefinedOutsideCurrentScope"] = 16384] = "UseAliasDefinedOutsideCurrentScope";
20+
NodeBuilderFlags[NodeBuilderFlags["UseSingleQuotesForStringLiteralType"] = 268435456] = "UseSingleQuotesForStringLiteralType";
21+
NodeBuilderFlags[NodeBuilderFlags["NoTypeReduction"] = 536870912] = "NoTypeReduction";
22+
NodeBuilderFlags[NodeBuilderFlags["UseInstantiationExpressions"] = 1073741824] = "UseInstantiationExpressions";
23+
NodeBuilderFlags[NodeBuilderFlags["OmitThisParameter"] = 33554432] = "OmitThisParameter";
24+
NodeBuilderFlags[NodeBuilderFlags["WriteCallStyleSignature"] = 134217728] = "WriteCallStyleSignature";
25+
NodeBuilderFlags[NodeBuilderFlags["AllowThisInObjectLiteral"] = 32768] = "AllowThisInObjectLiteral";
26+
NodeBuilderFlags[NodeBuilderFlags["AllowQualifiedNameInPlaceOfIdentifier"] = 65536] = "AllowQualifiedNameInPlaceOfIdentifier";
27+
NodeBuilderFlags[NodeBuilderFlags["AllowAnonymousIdentifier"] = 131072] = "AllowAnonymousIdentifier";
28+
NodeBuilderFlags[NodeBuilderFlags["AllowEmptyUnionOrIntersection"] = 262144] = "AllowEmptyUnionOrIntersection";
29+
NodeBuilderFlags[NodeBuilderFlags["AllowEmptyTuple"] = 524288] = "AllowEmptyTuple";
30+
NodeBuilderFlags[NodeBuilderFlags["AllowUniqueESSymbolType"] = 1048576] = "AllowUniqueESSymbolType";
31+
NodeBuilderFlags[NodeBuilderFlags["AllowEmptyIndexInfoType"] = 2097152] = "AllowEmptyIndexInfoType";
32+
NodeBuilderFlags[NodeBuilderFlags["AllowNodeModulesRelativePaths"] = 67108864] = "AllowNodeModulesRelativePaths";
33+
NodeBuilderFlags[NodeBuilderFlags["IgnoreErrors"] = 70221824] = "IgnoreErrors";
34+
NodeBuilderFlags[NodeBuilderFlags["InObjectTypeLiteral"] = 4194304] = "InObjectTypeLiteral";
35+
NodeBuilderFlags[NodeBuilderFlags["InTypeAlias"] = 8388608] = "InTypeAlias";
36+
NodeBuilderFlags[NodeBuilderFlags["InInitialEntityName"] = 16777216] = "InInitialEntityName";
37+
})(NodeBuilderFlags || (NodeBuilderFlags = {}));

0 commit comments

Comments
 (0)