MCPcopy Create free account
hub / github.com/microsoft/vscode-extension-samples / activate

Function activate

wasm-component-model-async/src/extension.ts:11–47  ·  view source on GitHub ↗
(context: vscode.ExtensionContext)

Source from the content-addressed store, hash-verified

9import { Types, calculator } from './calculator';
10
11export async function activate(context: vscode.ExtensionContext): Promise<void> {
12 // The channel for printing the result.
13 const channel = vscode.window.createOutputChannel('Calculator');
14 context.subscriptions.push(channel);
15
16 // The channel for printing the log.
17 const log = vscode.window.createOutputChannel('Calculator - Log', { log: true });
18 context.subscriptions.push(log);
19
20 // The implementation of the log function that is called from WASM
21 const service: calculator.Imports.Promisified = {
22 log: (msg: string) => {
23 log.info(msg);
24 }
25 };
26
27 // Load the Wasm module
28 const filename = vscode.Uri.joinPath(context.extensionUri, 'target', 'wasm32-unknown-unknown', 'debug', 'calculator.wasm');
29 const bits = await vscode.workspace.fs.readFile(filename) as Uint8Array<ArrayBuffer>;
30 const module = await WebAssembly.compile(bits);
31
32 const worker = new Worker(vscode.Uri.joinPath(context.extensionUri, './out/worker.js').fsPath);
33 const api = await calculator._.bind(service, module, worker);
34
35 context.subscriptions.push(vscode.commands.registerCommand('vscode-samples.wasm-component-model-async.run', async () => {
36 channel.show();
37 channel.appendLine('Running calculator example');
38 const add = Types.Operation.Add({ left: 1, right: 2 });
39 channel.appendLine(`Add ${await api.calc(add)}`);
40 const sub = Types.Operation.Sub({ left: 10, right: 8 });
41 channel.appendLine(`Sub ${await api.calc(sub)}`);
42 const mul = Types.Operation.Mul({ left: 3, right: 7 });
43 channel.appendLine(`Mul ${await api.calc(mul)}`);
44 const div = Types.Operation.Div({ left: 10, right: 2 });
45 channel.appendLine(`Div ${await api.calc(div)}`);
46 }));
47}

Callers

nothing calls this directly

Calls 2

showMethod · 0.80
readFileMethod · 0.45

Tested by

no test coverage detected