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
321 changes: 202 additions & 119 deletions packages/typescript/src/api/async/api.ts

Large diffs are not rendered by default.

270 changes: 151 additions & 119 deletions packages/typescript/src/api/proto.generated.ts

Large diffs are not rendered by default.

22 changes: 5 additions & 17 deletions packages/typescript/src/api/proto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import {
} from "./path.ts";
import type {
APIMethodInfo,
CreateSnapshotParams as CoreCreateSnapshotParams,
DocumentIdentifier,
SignatureResponse,
SourceFileResponse,
SymbolResponse,
TypeResponse,
UpdateSnapshotParams as CoreUpdateSnapshotParams,
} from "./proto.generated.ts";
export type { ConfigFileResponse as ParsedCommandLine, DiagnosticResponse as Diagnostic } from "./proto.generated.ts";

Expand Down Expand Up @@ -81,21 +81,10 @@ export function resolveDocumentURI(identifier: DocumentIdentifier): string {
return identifier.uri;
}

export interface LSPUpdateSnapshotParams extends Omit<CoreUpdateSnapshotParams, "snapshot"> {
/**
* @deprecated Use {@link openProjects} instead.
* Path to a tsconfig.json file to open in the new snapshot.
*/
openProject?: string;

/** FileChanges are not supplied by the LSP */
fileChanges?: never;
}

/**
* Parameters for updateSnapshot, including deprecated members handled by `toUpdateSnapshotRequest`
* Parameters for createSnapshot, including deprecated members handled by `toCreateSnapshotRequest`
*/
export interface UpdateSnapshotParams extends Omit<CoreUpdateSnapshotParams, "snapshot"> {
export interface CreateSnapshotParams extends CoreCreateSnapshotParams {
/**
* @deprecated Use {@link openProjects} instead.
* Path to a tsconfig.json file to open in the new snapshot.
Expand All @@ -104,18 +93,17 @@ export interface UpdateSnapshotParams extends Omit<CoreUpdateSnapshotParams, "sn
}

/**
* Builds the wire request for updateSnapshot, applying the deprecated `openProject`
* Builds the wire request for createSnapshot, applying the deprecated `openProject`
* compatibility shim: a single `openProject` is folded into `openProjects` and is
* never sent on the wire.
*/
export function toUpdateSnapshotRequest(params?: UpdateSnapshotParams, snapshot?: number): CoreUpdateSnapshotParams {
export function toCreateSnapshotRequest(params?: CreateSnapshotParams): CreateSnapshotParams {
const { openProject, openProjects, ...rest } = params ?? {};
const mergedOpenProjects = openProject !== undefined
? [resolveFileName(openProject), ...(openProjects ?? [])]
: openProjects;
return {
...rest,
...(snapshot !== undefined ? { snapshot } : {}),
...(mergedOpenProjects !== undefined ? { openProjects: mergedOpenProjects } : {}),
};
}
2 changes: 1 addition & 1 deletion packages/typescript/src/api/sourceFileCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class SourceFileCache {
const prevProjectMap = this.snapshotProjectPaths.get(previousSnapshotId);
if (!prevProjectMap) return;

const removedProjects = new Set(changes?.removedProjects ?? []);
const removedProjects = new Set<string>(changes?.removedProjects ?? []);
const changedProjects = changes?.changedProjects ?? {};

for (const [projectId, paths] of prevProjectMap) {
Expand Down
553 changes: 323 additions & 230 deletions packages/typescript/src/api/sync/api.ts

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions packages/typescript/test/api-comparison.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,23 +357,23 @@ export async function runBenchmarks(options?: { filter?: string; singleIteration

function createSyncContext(): SyncContext {
const api = new SyncAPI({ cwd: repoRoot });
const snapshot = api.updateSnapshot({ openProject: "tsc/testdata/fixtures/compiler/tsconfig.json" });
const snapshot = api.createSnapshot({ openProject: "tsc/testdata/fixtures/compiler/tsconfig.json" });
const project = snapshot.getProjects()[0];
project.checker.getSymbolAtPosition("core.ts", 0);
return { api, project };
}

async function createAsyncContext(): Promise<AsyncContext> {
const api = new AsyncAPI({ cwd: repoRoot });
const snapshot = await api.updateSnapshot({ openProject: "tsc/testdata/fixtures/compiler/tsconfig.json" });
const snapshot = await api.createSnapshot({ openProject: "tsc/testdata/fixtures/compiler/tsconfig.json" });
const project = snapshot.getProjects()[0];
await project.checker.getSymbolAtPosition("core.ts", 0);
return { api, project };
}

function createGeneratorContext(): SyncContext {
const api = new SyncAPI({ cwd: repoRoot });
const [snapshot] = api.batch(api.updateSnapshot.gen({ openProject: "tsc/testdata/fixtures/compiler/tsconfig.json" }));
const [snapshot] = api.batch(api.createSnapshot.gen({ openProject: "tsc/testdata/fixtures/compiler/tsconfig.json" }));
const project = snapshot.getProjects()[0];
api.batch(project.checker.getSymbolAtPosition.gen("core.ts", 0));
return { api, project };
Expand Down
2 changes: 1 addition & 1 deletion packages/typescript/test/async/api.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export async function runBenchmarks(options?: { filter?: string; singleIteration
}

async function loadSnapshot() {
snapshot = await api.updateSnapshot({ openProject: "tsc/testdata/fixtures/compiler/tsconfig.json" }); // @generators: [snapshot] = api.batch(api.updateSnapshot.gen({ openProject: "tsc/testdata/fixtures/compiler/tsconfig.json" }));
snapshot = await api.createSnapshot({ openProject: "tsc/testdata/fixtures/compiler/tsconfig.json" }); // @generators: [snapshot] = api.batch(api.createSnapshot.gen({ openProject: "tsc/testdata/fixtures/compiler/tsconfig.json" }));
project = snapshot.getProjects()[0];
}

Expand Down
Loading