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
39 changes: 39 additions & 0 deletions packages/typescript/src/api/async/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ import type {
ResolvedModule,
ResolvedTypeReferenceDirective,
ResolveModuleNameResult,
ResolveTypeReferenceDirectiveResult,
SignaturePropertyMethod,
SignatureResponse,
SourceFileDescriptor,
Expand Down Expand Up @@ -260,6 +261,7 @@ export type {
ResolvedModule,
ResolvedTypeReferenceDirective,
ResolveModuleNameResult,
ResolveTypeReferenceDirectiveResult,
SourceFileMetadata,
StaticModuleResolution,
StringLiteralType,
Expand Down Expand Up @@ -514,6 +516,22 @@ export class API<FromLSP extends boolean = false> implements FormatDiagnosticsHo
return orchestrator;
}

/** Returns configured type roots or ancestor node_modules/@types candidates, without checking directory existence. */
async getEffectiveTypeRoots(compilerOptions: RawCompilerOptions): Promise<readonly RootedDirectoryPath[]> {
await this.ensureInitialized();
return this.client.apiRequest("getEffectiveTypeRoots", {
compilerOptions: prepareCompilerOptions(compilerOptions, this.getCurrentDirectory()),
});
}

/** Returns the native build-info output path, or undefined when the options do not produce one. */
async getTsBuildInfoEmitOutputFilePath(compilerOptions: RawCompilerOptions): Promise<RootedFilePath | undefined> {
await this.ensureInitialized();
return (await this.client.apiRequest("getTsBuildInfoEmitOutputFilePath", {
compilerOptions: prepareCompilerOptions(compilerOptions, this.getCurrentDirectory()),
})) ?? undefined;
}

async parseConfigFile(file: DocumentIdentifier): Promise<ParsedCommandLine> {
await this.ensureInitialized();
return this.client.apiRequest("parseConfigFile", { file });
Expand Down Expand Up @@ -1249,6 +1267,27 @@ export class ModuleResolver {
});
}

/** Resolves a type directive using this resolver's options and the selected snapshot or live filesystem. */
async resolveTypeReferenceDirective(
typeReferenceDirectiveName: string,
containingFile: DocumentIdentifier,
resolutionMode?: ResolutionMode,
options?: { snapshot?: Snapshot | InProgressSnapshot | undefined; },
): Promise<ResolveTypeReferenceDirectiveResult> {
this.ensureNotDisposed();
if (options?.snapshot instanceof Snapshot && options.snapshot.isDisposed()) {
throw new Error("Snapshot is disposed");
}
return this.client.apiRequest("resolveTypeReferenceDirective", {
snapshot: options?.snapshot instanceof Snapshot ? options.snapshot.id : undefined,
inProgressSnapshot: typeof options?.snapshot === "number" ? -options.snapshot : undefined,
resolver: this.id,
typeReferenceDirectiveName,
containingFile,
resolutionMode,
});
}

[globalThis.Symbol.asyncDispose](): Promise<void> { // @sync: [globalThis.Symbol.dispose](): void {
return this.dispose();
}
Expand Down
28 changes: 28 additions & 0 deletions packages/typescript/src/api/proto.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ export interface APIMethodInfo {
createModuleResolver: APIMethod<CreateModuleResolverParams, number>;
releaseModuleResolver: APIMethod<ReleaseModuleResolverParams, unknown>;
resolveModuleName: APIMethod<ResolveModuleNameParams, ResolveModuleNameResult>;
resolveTypeReferenceDirective: APIMethod<ResolveTypeReferenceDirectiveParams, ResolveTypeReferenceDirectiveResult>;
getEffectiveTypeRoots: APIMethod<CompilerOptionsParams, RootedDirectoryPath[]>;
getTsBuildInfoEmitOutputFilePath: APIMethod<CompilerOptionsParams, RootedFilePath | null>;
parseCommandLine: APIMethod<ParseCommandLineParams, ConfigFileResponse>;
readConfigFile: APIMethod<ReadConfigFileParams, ReadConfigFileResponse>;
parseConfigFileTextToJson: APIMethod<ParseConfigFileTextToJsonParams, ReadConfigFileResponse>;
Expand Down Expand Up @@ -414,6 +417,25 @@ export interface ResolveModuleNameResult {
trace?: string[] | undefined;
}

export interface ResolveTypeReferenceDirectiveParams {
snapshot?: number | undefined;
inProgressSnapshot?: number | undefined;
resolver: number;
typeReferenceDirectiveName: string;
containingFile: DocumentIdentifier;
resolutionMode?: ResolutionMode | undefined;
}

export interface ResolveTypeReferenceDirectiveResult {
resolvedTypeReferenceDirective?: ResolvedTypeReferenceDirective | undefined;
/** Trace is provided when compilerOptions.traceResolution is true. */
trace?: string[] | undefined;
}

export interface CompilerOptionsParams {
compilerOptions: CompilerOptions;
}

export interface ParseCommandLineParams {
commandLine: readonly string[] | null;
}
Expand Down Expand Up @@ -1265,6 +1287,7 @@ export interface BatchRequest {
| "getDefaultProjectForFile"
| "getDocumentationComment"
| "getESSymbolType"
| "getEffectiveTypeRoots"
| "getExportSpecifierLocalTargetSymbol"
| "getExportSymbolOfSymbol"
| "getExportSymbolOfSymbolForChecker"
Expand Down Expand Up @@ -1353,6 +1376,7 @@ export interface BatchRequest {
| "getThisTypeOfType"
| "getTrueType"
| "getTrueTypeOfConditionalType"
| "getTsBuildInfoEmitOutputFilePath"
| "getTypeArguments"
| "getTypeAtLocation"
| "getTypeAtLocations"
Expand Down Expand Up @@ -1393,6 +1417,7 @@ export interface BatchRequest {
| "releaseSourceFile"
| "resolveModuleName"
| "resolveName"
| "resolveTypeReferenceDirective"
| "retainSourceFile"
| "saveHeapProfile"
| "signatureToSignatureDeclaration"
Expand Down Expand Up @@ -1460,6 +1485,7 @@ export interface BatchResponse {
| "getDefaultProjectForFile"
| "getDocumentationComment"
| "getESSymbolType"
| "getEffectiveTypeRoots"
| "getExportSpecifierLocalTargetSymbol"
| "getExportSymbolOfSymbol"
| "getExportSymbolOfSymbolForChecker"
Expand Down Expand Up @@ -1548,6 +1574,7 @@ export interface BatchResponse {
| "getThisTypeOfType"
| "getTrueType"
| "getTrueTypeOfConditionalType"
| "getTsBuildInfoEmitOutputFilePath"
| "getTypeArguments"
| "getTypeAtLocation"
| "getTypeAtLocations"
Expand Down Expand Up @@ -1588,6 +1615,7 @@ export interface BatchResponse {
| "releaseSourceFile"
| "resolveModuleName"
| "resolveName"
| "resolveTypeReferenceDirective"
| "retainSourceFile"
| "saveHeapProfile"
| "signatureToSignatureDeclaration"
Expand Down
90 changes: 90 additions & 0 deletions packages/typescript/src/api/sync/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ import type {
ResolvedModule,
ResolvedTypeReferenceDirective,
ResolveModuleNameResult,
ResolveTypeReferenceDirectiveResult,
SignaturePropertyMethod,
SignatureResponse,
SourceFileDescriptor,
Expand Down Expand Up @@ -278,6 +279,7 @@ export type {
ResolvedModule,
ResolvedTypeReferenceDirective,
ResolveModuleNameResult,
ResolveTypeReferenceDirectiveResult,
SourceFileMetadata,
StaticModuleResolution,
StringLiteralType,
Expand Down Expand Up @@ -641,6 +643,54 @@ export class API<FromLSP extends boolean = false> implements FormatDiagnosticsHo
);
}

/** Returns configured type roots or ancestor node_modules/@types candidates, without checking directory existence. */
get getEffectiveTypeRoots(): {
(compilerOptions: RawCompilerOptions): readonly RootedDirectoryPath[];
gen(compilerOptions: RawCompilerOptions): Generator<ProtocolRequest, readonly RootedDirectoryPath[], ProtocolResponse["result"]>;
} {
const owner = this;
return cacheGeneratorMethod(
owner,
"getEffectiveTypeRoots",
function (compilerOptions: RawCompilerOptions): readonly RootedDirectoryPath[] {
owner.ensureInitialized();
return owner.client.apiRequest("getEffectiveTypeRoots", {
compilerOptions: prepareCompilerOptions(compilerOptions, owner.getCurrentDirectory()),
});
},
function* (compilerOptions: RawCompilerOptions): Generator<ProtocolRequest, readonly RootedDirectoryPath[], ProtocolResponse["result"]> {
yield* owner.ensureInitialized.gen();
return yield* apiRequest("getEffectiveTypeRoots", {
compilerOptions: prepareCompilerOptions(compilerOptions, owner.getCurrentDirectory()),
});
},
);
}

/** Returns the native build-info output path, or undefined when the options do not produce one. */
get getTsBuildInfoEmitOutputFilePath(): {
(compilerOptions: RawCompilerOptions): RootedFilePath | undefined;
gen(compilerOptions: RawCompilerOptions): Generator<ProtocolRequest, RootedFilePath | undefined, ProtocolResponse["result"]>;
} {
const owner = this;
return cacheGeneratorMethod(
owner,
"getTsBuildInfoEmitOutputFilePath",
function (compilerOptions: RawCompilerOptions): RootedFilePath | undefined {
owner.ensureInitialized();
return (owner.client.apiRequest("getTsBuildInfoEmitOutputFilePath", {
compilerOptions: prepareCompilerOptions(compilerOptions, owner.getCurrentDirectory()),
})) ?? undefined;
},
function* (compilerOptions: RawCompilerOptions): Generator<ProtocolRequest, RootedFilePath | undefined, ProtocolResponse["result"]> {
yield* owner.ensureInitialized.gen();
return (yield* apiRequest("getTsBuildInfoEmitOutputFilePath", {
compilerOptions: prepareCompilerOptions(compilerOptions, owner.getCurrentDirectory()),
})) ?? undefined;
},
);
}

get parseConfigFile(): {
(file: DocumentIdentifier): ParsedCommandLine;
gen(file: DocumentIdentifier): Generator<ProtocolRequest, ParsedCommandLine, ProtocolResponse["result"]>;
Expand Down Expand Up @@ -1971,6 +2021,46 @@ export class ModuleResolver {
);
}

/** Resolves a type directive using this resolver's options and the selected snapshot or live filesystem. */
get resolveTypeReferenceDirective(): {
(typeReferenceDirectiveName: string, containingFile: DocumentIdentifier, resolutionMode?: ResolutionMode, options?: { snapshot?: Snapshot | InProgressSnapshot | undefined; }): ResolveTypeReferenceDirectiveResult;
gen(typeReferenceDirectiveName: string, containingFile: DocumentIdentifier, resolutionMode?: ResolutionMode, options?: { snapshot?: Snapshot | InProgressSnapshot | undefined; }): Generator<ProtocolRequest, ResolveTypeReferenceDirectiveResult, ProtocolResponse["result"]>;
} {
const owner = this;
return cacheGeneratorMethod(
owner,
"resolveTypeReferenceDirective",
function (typeReferenceDirectiveName: string, containingFile: DocumentIdentifier, resolutionMode?: ResolutionMode, options?: { snapshot?: Snapshot | InProgressSnapshot | undefined; }): ResolveTypeReferenceDirectiveResult {
owner.ensureNotDisposed();
if (options?.snapshot instanceof Snapshot && options.snapshot.isDisposed()) {
throw new Error("Snapshot is disposed");
}
return owner.client.apiRequest("resolveTypeReferenceDirective", {
snapshot: options?.snapshot instanceof Snapshot ? options.snapshot.id : undefined,
inProgressSnapshot: typeof options?.snapshot === "number" ? -options.snapshot : undefined,
resolver: owner.id,
typeReferenceDirectiveName,
containingFile,
resolutionMode,
});
},
function* (typeReferenceDirectiveName: string, containingFile: DocumentIdentifier, resolutionMode?: ResolutionMode, options?: { snapshot?: Snapshot | InProgressSnapshot | undefined; }): Generator<ProtocolRequest, ResolveTypeReferenceDirectiveResult, ProtocolResponse["result"]> {
owner.ensureNotDisposed();
if (options?.snapshot instanceof Snapshot && options.snapshot.isDisposed()) {
throw new Error("Snapshot is disposed");
}
return yield* apiRequest("resolveTypeReferenceDirective", {
snapshot: options?.snapshot instanceof Snapshot ? options.snapshot.id : undefined,
inProgressSnapshot: typeof options?.snapshot === "number" ? -options.snapshot : undefined,
resolver: owner.id,
typeReferenceDirectiveName,
containingFile,
resolutionMode,
});
},
);
}

[globalThis.Symbol.dispose](): void {
return this.dispose();
}
Expand Down
Loading
Loading