Skip to content

Visual Studio Code, rebuilt in Rust

Rust
1.1 KB
Raw Blame
// Emits native/crates/exthost/src/proxy_ids.rs from extHost.protocol.ts.
// ProxyIdentifier.nid is a creation counter starting at 1, and extHost.protocol.ts creates every identifier in file order.
import { join } from 'node:path';
import { vscodeSrc } from './vscode-src.ts';

const source = await Bun.file(join(vscodeSrc, 'src/vs/workbench/api/common/extHost.protocol.ts')).text();
// Names are the MainContext/ExtHostContext keys, which differ from the identifier strings in a few places
// (MainThreadLanguageModelTools is created as 'MainThreadChatSkills').
const names = [...source.matchAll(/(\w+): createProxyIdentifier<\w+>\('\w+'\)/g)].map(m => m[1]);
const lines = names.map((name, i) => `    "${name}", // ${i + 1}`);
const rust = `// @generated by port/tools/gen-proxy-ids.ts from src/vs/workbench/api/common/extHost.protocol.ts\n\n/// Index i holds the proxy with rpc id i + 1, named by its MainContext/ExtHostContext key.\npub const PROXY_NAMES: [&str; ${names.length}] = [\n${lines.join('\n')}\n];\n`;
await Bun.write('native/crates/exthost/src/proxy_ids.rs', rust);
console.log(`${names.length} proxy identifiers`);