Skip to content

Commit d05b6be

Browse files
Add batched version for the following API methods:
- getDeclaredTypeOfSymbol - getAliasedSymbol - getImmediateAliasedSymbol - getExportsOfModule - getMemberInModuleExports
1 parent 6d44e05 commit d05b6be

7 files changed

Lines changed: 595 additions & 22 deletions

File tree

packages/typescript/src/api/async/api.ts

Lines changed: 64 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,11 +1384,21 @@ export class Checker {
13841384
* declared type cannot be determined the checker yields the error type (use
13851385
* {@link Type.isErrorType} to detect it).
13861386
*/
1387-
async getDeclaredTypeOfSymbol(symbol: Symbol): Promise<Type> {
1387+
async getDeclaredTypeOfSymbol(symbol: Symbol): Promise<Type>;
1388+
async getDeclaredTypeOfSymbol(symbols: readonly Symbol[]): Promise<Type[]>;
1389+
async getDeclaredTypeOfSymbol(symbolOrSymbols: Symbol | readonly Symbol[]): Promise<Type | Type[]> {
1390+
if (Array.isArray(symbolOrSymbols)) {
1391+
const data = await this.client.apiRequest("getDeclaredTypesOfSymbols", {
1392+
snapshot: this.snapshotId,
1393+
project: this.project.id,
1394+
symbols: symbolOrSymbols.map(s => s.id),
1395+
});
1396+
return data.map(d => this.objectRegistry.getOrCreateType(d));
1397+
}
13881398
const data = await this.client.apiRequest("getDeclaredTypeOfSymbol", {
13891399
snapshot: this.snapshotId,
13901400
project: this.project.id,
1391-
symbol: symbol.id,
1401+
symbol: (symbolOrSymbols as Symbol).id,
13921402
});
13931403
return this.objectRegistry.getOrCreateType(data);
13941404
}
@@ -1859,11 +1869,21 @@ export class Checker {
18591869
* an unresolved alias the checker yields the unknown symbol (use
18601870
* {@link Checker.isUnknownSymbol} to detect it).
18611871
*/
1862-
async getAliasedSymbol(symbol: Symbol): Promise<Symbol> {
1872+
async getAliasedSymbol(symbol: Symbol): Promise<Symbol>;
1873+
async getAliasedSymbol(symbols: readonly Symbol[]): Promise<Symbol[]>;
1874+
async getAliasedSymbol(symbolOrSymbols: Symbol | readonly Symbol[]): Promise<Symbol | Symbol[]> {
1875+
if (Array.isArray(symbolOrSymbols)) {
1876+
const data = await this.client.apiRequest("getAliasedSymbols", {
1877+
snapshot: this.snapshotId,
1878+
project: this.project.id,
1879+
symbols: symbolOrSymbols.map(s => s.id),
1880+
});
1881+
return data.map(d => this.objectRegistry.getOrCreateSymbol(d));
1882+
}
18631883
const data = await this.client.apiRequest("getAliasedSymbol", {
18641884
snapshot: this.snapshotId,
18651885
project: this.project.id,
1866-
symbol: symbol.id,
1886+
symbol: (symbolOrSymbols as Symbol).id,
18671887
});
18681888
return this.objectRegistry.getOrCreateSymbol(data);
18691889
}
@@ -1880,11 +1900,21 @@ export class Checker {
18801900
});
18811901
}
18821902

1883-
async getImmediateAliasedSymbol(symbol: Symbol): Promise<Symbol | undefined> {
1903+
async getImmediateAliasedSymbol(symbol: Symbol): Promise<Symbol | undefined>;
1904+
async getImmediateAliasedSymbol(symbols: readonly Symbol[]): Promise<(Symbol | undefined)[]>;
1905+
async getImmediateAliasedSymbol(symbolOrSymbols: Symbol | readonly Symbol[]): Promise<Symbol | (Symbol | undefined)[] | undefined> {
1906+
if (Array.isArray(symbolOrSymbols)) {
1907+
const data = await this.client.apiRequest("getImmediateAliasedSymbols", {
1908+
snapshot: this.snapshotId,
1909+
project: this.project.id,
1910+
symbols: symbolOrSymbols.map(s => s.id),
1911+
});
1912+
return data ? data.map(d => d ? this.objectRegistry.getOrCreateSymbol(d) : undefined) : symbolOrSymbols.map(() => undefined);
1913+
}
18841914
const data = await this.client.apiRequest("getImmediateAliasedSymbol", {
18851915
snapshot: this.snapshotId,
18861916
project: this.project.id,
1887-
symbol: symbol.id,
1917+
symbol: (symbolOrSymbols as Symbol).id,
18881918
});
18891919
return data ? this.objectRegistry.getOrCreateSymbol(data) : undefined;
18901920
}
@@ -1945,21 +1975,44 @@ export class Checker {
19451975
return signature.id === (await this.getWellKnownSignatures()).unknown;
19461976
}
19471977

1948-
async getExportsOfModule(symbol: Symbol): Promise<readonly Symbol[]> {
1978+
async getExportsOfModule(symbol: Symbol): Promise<readonly Symbol[]>;
1979+
async getExportsOfModule(symbols: readonly Symbol[]): Promise<readonly (readonly Symbol[])[]>;
1980+
async getExportsOfModule(symbolOrSymbols: Symbol | readonly Symbol[]): Promise<readonly Symbol[] | readonly (readonly Symbol[])[]> {
1981+
if (Array.isArray(symbolOrSymbols)) {
1982+
const data = await this.client.apiRequest("getExportsOfModules", {
1983+
snapshot: this.snapshotId,
1984+
project: this.project.id,
1985+
symbols: symbolOrSymbols.map(s => s.id),
1986+
});
1987+
return data.map(d => d ? d.map(s => this.objectRegistry.getOrCreateSymbol(s)) : []);
1988+
}
19491989
const data = await this.client.apiRequest("getExportsOfModule", {
19501990
snapshot: this.snapshotId,
19511991
project: this.project.id,
1952-
symbol: symbol.id,
1992+
symbol: (symbolOrSymbols as Symbol).id,
19531993
});
19541994
return data ? data.map(d => this.objectRegistry.getOrCreateSymbol(d)) : [];
19551995
}
19561996

1957-
async getMemberInModuleExports(symbol: Symbol, name: string): Promise<Symbol | undefined> {
1997+
async getMemberInModuleExports(symbol: Symbol, name: string): Promise<Symbol | undefined>;
1998+
async getMemberInModuleExports(requests: readonly { symbol: Symbol; name: string; }[]): Promise<(Symbol | undefined)[]>;
1999+
async getMemberInModuleExports(
2000+
symbolOrRequests: Symbol | readonly { symbol: Symbol; name: string; }[],
2001+
name?: string,
2002+
): Promise<Symbol | (Symbol | undefined)[] | undefined> {
2003+
if (Array.isArray(symbolOrRequests)) {
2004+
const data = await this.client.apiRequest("getMembersInModuleExports", {
2005+
snapshot: this.snapshotId,
2006+
project: this.project.id,
2007+
requests: symbolOrRequests.map(r => ({ symbol: r.symbol.id, name: r.name })),
2008+
});
2009+
return data.map(d => d ? this.objectRegistry.getOrCreateSymbol(d) : undefined);
2010+
}
19582011
const data = await this.client.apiRequest("getMemberInModuleExports", {
19592012
snapshot: this.snapshotId,
19602013
project: this.project.id,
1961-
symbol: symbol.id,
1962-
name,
2014+
symbol: (symbolOrRequests as Symbol).id,
2015+
name: name!,
19632016
});
19642017
return data ? this.objectRegistry.getOrCreateSymbol(data) : undefined;
19652018
}

packages/typescript/src/api/proto.generated.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export interface APIMethodInfo {
3232
getTypeOfSymbol: APIMethod<GetTypeOfSymbolParams, TypeResponse>;
3333
getTypesOfSymbols: APIMethod<GetTypesOfSymbolsParams, TypeResponse[]>;
3434
getDeclaredTypeOfSymbol: APIMethod<GetTypeOfSymbolParams, TypeResponse>;
35+
getDeclaredTypesOfSymbols: APIMethod<GetTypesOfSymbolsParams, TypeResponse[]>;
3536
getSourceFile: APIMethod<GetSourceFileParams, SourceFileResponse | null>;
3637
getSourceFileNames: APIMethod<GetSourceFileNamesParams, string[]>;
3738
getSourceFileMetadata: APIMethod<GetSourceFileParams, SourceFileMetadata | null>;
@@ -104,10 +105,14 @@ export interface APIMethodInfo {
104105
getSignatureFromDeclaration: APIMethod<CheckerNodeParams, SignatureResponse>;
105106
getExportSpecifierLocalTargetSymbol: APIMethod<CheckerNodeParams, SymbolResponse | null>;
106107
getAliasedSymbol: APIMethod<CheckerSymbolParams, SymbolResponse>;
108+
getAliasedSymbols: APIMethod<CheckerSymbolsParams, SymbolResponse[]>;
107109
getImmediateAliasedSymbol: APIMethod<CheckerSymbolParams, SymbolResponse | null>;
110+
getImmediateAliasedSymbols: APIMethod<CheckerSymbolsParams, SymbolResponse[] | null>;
108111
getFullyQualifiedName: APIMethod<CheckerSymbolParams, string>;
109112
getExportsOfModule: APIMethod<CheckerSymbolParams, SymbolResponse[] | null>;
113+
getExportsOfModules: APIMethod<CheckerSymbolsParams, SymbolResponse[][]>;
110114
getMemberInModuleExports: APIMethod<GetMemberInModuleExportsParams, SymbolResponse | null>;
115+
getMembersInModuleExports: APIMethod<GetMembersInModuleExportsParams, SymbolResponse[]>;
111116
getJsDocTags: APIMethod<CheckerSymbolParams, JSDocTagInfo[] | null>;
112117
getDocumentationComment: APIMethod<CheckerSymbolParams, string>;
113118
isArrayType: APIMethod<CheckerTypeParams, boolean>;
@@ -678,6 +683,13 @@ export interface CheckerSymbolParams {
678683
symbol: number;
679684
}
680685

686+
/** CheckerSymbolsParams are parameters for checker methods that operate on a list of symbols. */
687+
export interface CheckerSymbolsParams {
688+
snapshot: number;
689+
project: string;
690+
symbols: readonly number[] | null;
691+
}
692+
681693
/** GetMemberInModuleExportsParams are parameters for getMemberInModuleExports. */
682694
export interface GetMemberInModuleExportsParams {
683695
snapshot: number;
@@ -686,6 +698,13 @@ export interface GetMemberInModuleExportsParams {
686698
name: string;
687699
}
688700

701+
/** GetMembersInModuleExportsParams are parameters for getMembersInModuleExports. */
702+
export interface GetMembersInModuleExportsParams {
703+
snapshot: number;
704+
project: string;
705+
requests: readonly MemberInModuleExportsRequest[] | null;
706+
}
707+
689708
/**
690709
* JSDocTagInfo is a single JSDoc tag, mirroring Strada's JSDocTagInfo but with the tag text
691710
* rendered as a plain string rather than SymbolDisplayPart[].
@@ -1021,6 +1040,11 @@ export interface ImportAdderAction {
10211040
isValidTypeOnlyUseSite?: boolean;
10221041
}
10231042

1043+
export interface MemberInModuleExportsRequest {
1044+
symbol: number;
1045+
name: string;
1046+
}
1047+
10241048
/** CompletionEntryResponse represents a single completion item. */
10251049
export interface CompletionEntryResponse {
10261050
name: string;

packages/typescript/src/api/sync/api.ts

Lines changed: 64 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,11 +1392,21 @@ export class Checker {
13921392
* declared type cannot be determined the checker yields the error type (use
13931393
* {@link Type.isErrorType} to detect it).
13941394
*/
1395-
getDeclaredTypeOfSymbol(symbol: Symbol): Type {
1395+
getDeclaredTypeOfSymbol(symbol: Symbol): Type;
1396+
getDeclaredTypeOfSymbol(symbols: readonly Symbol[]): Type[];
1397+
getDeclaredTypeOfSymbol(symbolOrSymbols: Symbol | readonly Symbol[]): Type | Type[] {
1398+
if (Array.isArray(symbolOrSymbols)) {
1399+
const data = this.client.apiRequest("getDeclaredTypesOfSymbols", {
1400+
snapshot: this.snapshotId,
1401+
project: this.project.id,
1402+
symbols: symbolOrSymbols.map(s => s.id),
1403+
});
1404+
return data.map(d => this.objectRegistry.getOrCreateType(d));
1405+
}
13961406
const data = this.client.apiRequest("getDeclaredTypeOfSymbol", {
13971407
snapshot: this.snapshotId,
13981408
project: this.project.id,
1399-
symbol: symbol.id,
1409+
symbol: (symbolOrSymbols as Symbol).id,
14001410
});
14011411
return this.objectRegistry.getOrCreateType(data);
14021412
}
@@ -1867,11 +1877,21 @@ export class Checker {
18671877
* an unresolved alias the checker yields the unknown symbol (use
18681878
* {@link Checker.isUnknownSymbol} to detect it).
18691879
*/
1870-
getAliasedSymbol(symbol: Symbol): Symbol {
1880+
getAliasedSymbol(symbol: Symbol): Symbol;
1881+
getAliasedSymbol(symbols: readonly Symbol[]): Symbol[];
1882+
getAliasedSymbol(symbolOrSymbols: Symbol | readonly Symbol[]): Symbol | Symbol[] {
1883+
if (Array.isArray(symbolOrSymbols)) {
1884+
const data = this.client.apiRequest("getAliasedSymbols", {
1885+
snapshot: this.snapshotId,
1886+
project: this.project.id,
1887+
symbols: symbolOrSymbols.map(s => s.id),
1888+
});
1889+
return data.map(d => this.objectRegistry.getOrCreateSymbol(d));
1890+
}
18711891
const data = this.client.apiRequest("getAliasedSymbol", {
18721892
snapshot: this.snapshotId,
18731893
project: this.project.id,
1874-
symbol: symbol.id,
1894+
symbol: (symbolOrSymbols as Symbol).id,
18751895
});
18761896
return this.objectRegistry.getOrCreateSymbol(data);
18771897
}
@@ -1888,11 +1908,21 @@ export class Checker {
18881908
});
18891909
}
18901910

1891-
getImmediateAliasedSymbol(symbol: Symbol): Symbol | undefined {
1911+
getImmediateAliasedSymbol(symbol: Symbol): Symbol | undefined;
1912+
getImmediateAliasedSymbol(symbols: readonly Symbol[]): (Symbol | undefined)[];
1913+
getImmediateAliasedSymbol(symbolOrSymbols: Symbol | readonly Symbol[]): Symbol | (Symbol | undefined)[] | undefined {
1914+
if (Array.isArray(symbolOrSymbols)) {
1915+
const data = this.client.apiRequest("getImmediateAliasedSymbols", {
1916+
snapshot: this.snapshotId,
1917+
project: this.project.id,
1918+
symbols: symbolOrSymbols.map(s => s.id),
1919+
});
1920+
return data ? data.map(d => d ? this.objectRegistry.getOrCreateSymbol(d) : undefined) : symbolOrSymbols.map(() => undefined);
1921+
}
18921922
const data = this.client.apiRequest("getImmediateAliasedSymbol", {
18931923
snapshot: this.snapshotId,
18941924
project: this.project.id,
1895-
symbol: symbol.id,
1925+
symbol: (symbolOrSymbols as Symbol).id,
18961926
});
18971927
return data ? this.objectRegistry.getOrCreateSymbol(data) : undefined;
18981928
}
@@ -1953,21 +1983,44 @@ export class Checker {
19531983
return signature.id === (this.getWellKnownSignatures()).unknown;
19541984
}
19551985

1956-
getExportsOfModule(symbol: Symbol): readonly Symbol[] {
1986+
getExportsOfModule(symbol: Symbol): readonly Symbol[];
1987+
getExportsOfModule(symbols: readonly Symbol[]): readonly (readonly Symbol[])[];
1988+
getExportsOfModule(symbolOrSymbols: Symbol | readonly Symbol[]): readonly Symbol[] | readonly (readonly Symbol[])[] {
1989+
if (Array.isArray(symbolOrSymbols)) {
1990+
const data = this.client.apiRequest("getExportsOfModules", {
1991+
snapshot: this.snapshotId,
1992+
project: this.project.id,
1993+
symbols: symbolOrSymbols.map(s => s.id),
1994+
});
1995+
return data.map(d => d ? d.map(s => this.objectRegistry.getOrCreateSymbol(s)) : []);
1996+
}
19571997
const data = this.client.apiRequest("getExportsOfModule", {
19581998
snapshot: this.snapshotId,
19591999
project: this.project.id,
1960-
symbol: symbol.id,
2000+
symbol: (symbolOrSymbols as Symbol).id,
19612001
});
19622002
return data ? data.map(d => this.objectRegistry.getOrCreateSymbol(d)) : [];
19632003
}
19642004

1965-
getMemberInModuleExports(symbol: Symbol, name: string): Symbol | undefined {
2005+
getMemberInModuleExports(symbol: Symbol, name: string): Symbol | undefined;
2006+
getMemberInModuleExports(requests: readonly { symbol: Symbol; name: string; }[]): (Symbol | undefined)[];
2007+
getMemberInModuleExports(
2008+
symbolOrRequests: Symbol | readonly { symbol: Symbol; name: string; }[],
2009+
name?: string,
2010+
): Symbol | (Symbol | undefined)[] | undefined {
2011+
if (Array.isArray(symbolOrRequests)) {
2012+
const data = this.client.apiRequest("getMembersInModuleExports", {
2013+
snapshot: this.snapshotId,
2014+
project: this.project.id,
2015+
requests: symbolOrRequests.map(r => ({ symbol: r.symbol.id, name: r.name })),
2016+
});
2017+
return data.map(d => d ? this.objectRegistry.getOrCreateSymbol(d) : undefined);
2018+
}
19662019
const data = this.client.apiRequest("getMemberInModuleExports", {
19672020
snapshot: this.snapshotId,
19682021
project: this.project.id,
1969-
symbol: symbol.id,
1970-
name,
2022+
symbol: (symbolOrRequests as Symbol).id,
2023+
name: name!,
19712024
});
19722025
return data ? this.objectRegistry.getOrCreateSymbol(data) : undefined;
19732026
}

0 commit comments

Comments
 (0)