Skip to content
This repository was archived by the owner on Sep 1, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 6 additions & 0 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ npx hereby format # Format the code
```
</critical>

If you are writing or testing TS API features (eg, code in _packages/native-preview/src/api/async/api.ts), additionally, you need to run
```sh
npx hereby test:api
```
which is not run as part of the primary suite.

## Compiler Features, Fixes, and Tests

When fixing a bug or implementing a new feature, at least one minimal test case should always be added in advance to verify the fix.
Expand Down
7 changes: 7 additions & 0 deletions Herebyfile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,12 @@ export const generateAST = task({
run: () => $`node --experimental-strip-types --no-warnings ./_scripts/generate.ts`,
});

export const generateAPI = task({
name: "generate:api",
description: "Generates API files from internal/api/proto.go and internal/api/session.go.",
run: () => $`go -C ./_tools run ./gen-proto ../internal/api/proto.go ../_packages/native-preview/src/api/proto.generated.ts`,
});

// ── Vendored npm dependencies ───────────────────────────────────

const vendorJsonrpcDir = "_packages/native-preview/vendor/vscode-jsonrpc";
Expand Down Expand Up @@ -829,6 +835,7 @@ export const buildAPI = task({
export const buildAPITests = task({
name: "build:api:test",
description: "Builds the @typescript/native-preview JS API tests.",
dependencies: [generateEnums, generateAPI],
run: async () => {
await $`npm run -w @typescript/native-preview build:test`;
},
Expand Down
394 changes: 232 additions & 162 deletions _packages/native-preview/src/api/async/api.ts

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions _packages/native-preview/src/api/async/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ import {
isSpawnOptions,
resolveExePath,
} from "../options.ts";
import type {
APIMethodInfo,
SourceFileResponseMethod,
} from "../proto.ts";
import {
combineTimingInfo,
disabledServerTimingInfo,
Expand Down Expand Up @@ -162,15 +166,15 @@ export class Client {
}
}

async apiRequest<T>(method: string, params?: unknown): Promise<T> {
async apiRequest<K extends keyof APIMethodInfo>(method: K, params: APIMethodInfo[K]["params"]): Promise<APIMethodInfo[K]["result"]> {
if (!this.connected) {
await this.connect();
}
if (!this.connection) {
throw new Error("Connection not established");
}

const requestType = new RequestType<unknown, T, void>(method);
const requestType = new RequestType<unknown, APIMethodInfo[K]["result"], void>(method);
if (!this.timing) {
return this.connection.sendRequest(requestType, params);
}
Expand All @@ -194,8 +198,8 @@ export class Client {
return result;
}

async apiRequestBinary(method: string, params?: unknown): Promise<Uint8Array | undefined> {
const response = await this.apiRequest<{ data: string; } | null>(method, params);
async apiRequestBinary<K extends SourceFileResponseMethod>(method: K, params: APIMethodInfo[K]["params"]): Promise<Uint8Array | undefined> {
const response = await this.apiRequest(method, params);
if (!response) return undefined;
const buffer = Buffer.from(response.data, "base64");
return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
Expand Down
112 changes: 0 additions & 112 deletions _packages/native-preview/src/api/compilerOptions.ts

This file was deleted.

Loading
Loading