Skip to content
Open
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
46 changes: 46 additions & 0 deletions packages/typescript/src/api/async/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,14 @@ export class API<FromLSP extends boolean = false> {
}
}

async createBuildOrchestrator(host: ClientSpawnOptions, rootNames: readonly string[], defaultOptions: ParsedCommandLine): Promise<BuildOrchestrator> {
await this.ensureInitialized();
const orchestratorResponse = await this.client.apiRequest("createBuildOrchestrator", { hostOptions: host, rootNames, defaultOptions });
Comment on lines +243 to +245

const orchestrator = new BuildOrchestrator(this.client, orchestratorResponse.buildOrchestratorID);
return orchestrator;
}

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

export class BuildOrchestrator {
private client: Client;
private id: number;

constructor(client: Client, id: number) {
this.client = client;
this.id = id;
}
async build(project?: string): Promise<number> { // , cancellationToken?: CancellationToken, writeFile?: WriteFileCallback, getCustomTransformers?: (project: string) => CustomTransformers): ExitStatus{
const response = await this.client.apiRequest("build", {
buildOrchestratorID: this.id,
...(project !== undefined ? { project } : {}),
});
return response.exitStatus;
}
async buildReferences(project: string): Promise<number> {
const response = await this.client.apiRequest("buildReferences", {
buildOrchestratorID: this.id,
project,
});
return response.exitStatus;
}
async clean(project?: string): Promise<number> {
const response = await this.client.apiRequest("cleanBuild", {
buildOrchestratorID: this.id,
...(project !== undefined ? { project } : {}),
});
return response.exitStatus;
}
async cleanReferences(project?: string): Promise<number> {
const response = await this.client.apiRequest("cleanReferences", {
buildOrchestratorID: this.id,
...(project !== undefined ? { project } : {}),
});
return response.exitStatus;
}
}

function toEmitOutput(response: ProtocolEmitOutputResponse): EmitOutput {
const outputFiles = new Map<string, EmitOutputFile>();
for (const { fileName, ...outputFile } of response.outputFiles) {
Expand Down
2 changes: 1 addition & 1 deletion packages/typescript/src/api/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface FileSystem {
}

/** The callback names supported by the Go server for virtual FS delegation. */
export const fsCallbackNames = ["readFile", "fileExists", "directoryExists", "getAccessibleEntries", "realpath", "writeFile"] as const;
export const fsCallbackNames = ["readFile", "fileExists", "directoryExists", "getAccessibleEntries", "realpath", "writeFile", "removeFile"] as const;

interface VDirectory {
type: "directory";
Expand Down
59 changes: 59 additions & 0 deletions packages/typescript/src/api/proto.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ export interface APIMethodInfo {
initialize: APIMethod<null, InitializeResponse>;
updateSnapshot: APIMethod<UpdateSnapshotParams, UpdateSnapshotResponse>;
updateTemporarySnapshot: APIMethod<UpdateTemporarySnapshotParams, UpdateSnapshotResponse>;
createBuildOrchestrator: APIMethod<CreateBuildOrchestratorParams, CreateBuildOrchestratorResponse>;
build: APIMethod<BuildParams, BuildResponse>;
buildReferences: APIMethod<BuildParams, BuildResponse>;
cleanBuild: APIMethod<CleanBuildParams, CleanBuildResponse>;
cleanReferences: APIMethod<CleanBuildParams, CleanBuildResponse>;
parseCommandLine: APIMethod<ParseCommandLineParams, ConfigFileResponse>;
readConfigFile: APIMethod<ReadConfigFileParams, ReadConfigFileResponse>;
parseJsonConfigFileContent: APIMethod<ParseJsonConfigFileContentParams, ConfigFileResponse>;
Expand Down Expand Up @@ -224,13 +229,43 @@ export interface UpdateTemporarySnapshotParams {
newText: string;
}

export interface CreateBuildOrchestratorParams {
hostOptions: BuildOrchestratorHostOptions;
rootNames: readonly string[] | null;
defaultOptions: ConfigFileResponse;
}

export interface CreateBuildOrchestratorResponse {
buildOrchestratorID: number;
}

export interface BuildParams {
buildOrchestratorID: number;
project?: string;
}

export interface BuildResponse {
exitStatus: number;
}

export interface CleanBuildParams {
buildOrchestratorID: number;
project?: string;
}

export interface CleanBuildResponse {
exitStatus: number;
}

export interface ParseCommandLineParams {
commandLine: readonly string[] | null;
}

export interface ConfigFileResponse {
fileNames: string[];
options: CompilerOptions;
buildOptions?: BuildOptions;
watchOptions?: WatchOptions;
projectReferences?: ProjectReference[];
typeAcquisition?: TypeAcquisition;
compileOnSave?: boolean;
Expand Down Expand Up @@ -888,6 +923,10 @@ export interface SnapshotChanges {
removedProjects?: string[];
}

export interface BuildOrchestratorHostOptions {
cwd?: string;
}

/** CompilerOptions contains the compiler options exposed by the API. */
export interface CompilerOptions {
allowJs?: boolean;
Expand Down Expand Up @@ -994,6 +1033,26 @@ export interface CompilerOptions {
configFilePath?: string;
}

export interface BuildOptions {
dry?: boolean;
force?: boolean;
verbose?: boolean;
builders?: number;
stopBuildOnErrors?: boolean;
/** Internal fields */
clean?: boolean;
}

export interface WatchOptions {
watchInterval: number | null;
watchFile: number;
watchDirectory: number;
fallbackPolling: number;
synchronousWatchDirectory: boolean;
excludeDirectories: string[] | null;
excludeFiles: string[] | null;
}

export interface ProjectReference {
/** Path is a normalized path on disk. */
path: string;
Expand Down
49 changes: 49 additions & 0 deletions packages/typescript/src/api/sync/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { SymbolFlags } from "#enums/symbolFlags";
import { TypeFlags } from "#enums/typeFlags";
import { TypeFormatFlags } from "#enums/typeFormatFlags";
import { TypePredicateKind } from "#enums/typePredicateKind";
import type { CancellationToken } from "../../../vendor/vscode-jsonrpc/lib/common/cancellation.js";
import {
type __String,
type Declaration,
Expand Down Expand Up @@ -220,6 +221,7 @@ export class API<FromLSP extends boolean = false> {
private initialized: boolean = false;
private activeSnapshots: Set<Snapshot> = new Set();
private latestSnapshot: Snapshot | undefined;
private buildOrchestrators: Map<number, BuildOrchestrator> = new Map();
readonly internal: InternalAPI;

constructor(options: APIOptions | LSPConnectionOptions = {}) {
Expand Down Expand Up @@ -248,6 +250,14 @@ export class API<FromLSP extends boolean = false> {
}
}

createBuildOrchestrator(host: ClientSpawnOptions, rootNames: readonly string[], defaultOptions: ParsedCommandLine): BuildOrchestrator {
this.ensureInitialized();
const orchestratorResponse = this.client.apiRequest("createBuildOrchestrator", { hostOptions: host, rootNames, defaultOptions });

const orchestrator = new BuildOrchestrator(this.client, orchestratorResponse.buildOrchestratorID);
return orchestrator;
}

parseConfigFile(file: DocumentIdentifier): ParsedCommandLine {
this.ensureInitialized();
return this.client.apiRequest("parseConfigFile", { file });
Expand Down Expand Up @@ -1269,6 +1279,45 @@ export class Program {
}
}

export class BuildOrchestrator {
private client: Client;
private id: number;

constructor(client: Client, id: number) {
this.client = client;
this.id = id;
}
build(project?: string): number { // , cancellationToken?: CancellationToken, writeFile?: WriteFileCallback, getCustomTransformers?: (project: string) => CustomTransformers): ExitStatus{
const response = this.client.apiRequest("build", {
buildOrchestratorID: this.id,
...(project !== undefined ? { project } : {}),
});
return response.exitStatus;
}
buildReferences(project: string): number {
const response = this.client.apiRequest("buildReferences", {
buildOrchestratorID: this.id,
project,
});
return response.exitStatus;
}
clean(project?: string): number {
const response = this.client.apiRequest("cleanBuild", {
buildOrchestratorID: this.id,
...(project !== undefined ? { project } : {}),
});
return response.exitStatus;
}
cleanReferences(project?: string): number {
const response = this.client.apiRequest("cleanReferences", {
buildOrchestratorID: this.id,
...(project !== undefined ? { project } : {}),
});
return response.exitStatus;
}
// getNextInvalidatedProject(cancellationToken?: CancellationToken): InvalidatedProject<T> | undefined;
}

function toEmitOutput(response: ProtocolEmitOutputResponse): EmitOutput {
const outputFiles = new Map<string, EmitOutputFile>();
for (const { fileName, ...outputFile } of response.outputFiles) {
Expand Down
Loading