MCPcopy Index your code
hub / github.com/microsoft/SandDance / activate

Function activate

extensions/vscode-sanddance/src/extension.ts:10–65  ·  view source on GitHub ↗
(context: vscode.ExtensionContext)

Source from the content-addressed store, hash-verified

8import { TextDecoder } from 'util';
9
10export function activate(context: vscode.ExtensionContext) {
11 let current: WebViewWithUri | undefined = undefined;
12 context.subscriptions.push(
13 vscode.commands.registerCommand('sanddance.view',
14 (fileUri: vscode.Uri) => {
15 const columnToShowIn = vscode.window.activeTextEditor ? vscode.window.activeTextEditor.viewColumn : undefined;
16 const uriFsPath = fileUri.fsPath;
17 //only allow one SandDance at a time
18 if (current && current.uriFsPath !== uriFsPath) {
19 current.panel.dispose();
20 current = undefined;
21 }
22 if (current) {
23
24 //TODO: registerWebviewPanelSerializer to hydrate state
25
26 // If we already have a panel, show it in the target column
27 current.panel.reveal(columnToShowIn);
28
29 } else {
30 // Otherwise, create a new panel
31 current = newPanel(context, uriFsPath);
32
33 current.panel.onDidDispose(() => {
34 current = undefined;
35 }, null, context.subscriptions);
36
37 // Handle messages from the webview
38 current.panel.webview.onDidReceiveMessage(message => {
39 switch (message.command) {
40 case 'getFileContent': {
41 vscode.workspace.fs.readFile(fileUri).then(uint8array => {
42 if (current && current.panel.visible) {
43
44 //TODO string type of dataFile
45 const dataFile = {
46 type: path.extname(uriFsPath).substring(1),
47 rawText: new TextDecoder().decode(uint8array),
48 };
49 const compactUI = context.globalState.get('compactUI');
50 current.panel.webview.postMessage({ command: 'gotFileContent', dataFile, compactUI });
51 }
52 });
53 break;
54 }
55 case 'setCompactUI': {
56 context.globalState.update('compactUI', message.compactUI);
57 break;
58 }
59 }
60 }, undefined, context.subscriptions);
61 }
62 },
63 ),
64 );
65}
66
67export function deactivate() {

Callers

nothing calls this directly

Calls 5

newPanelFunction · 0.90
postMessageMethod · 0.65
readFileMethod · 0.45
getMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected