forked from microsoft/typescript-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommands.ts
More file actions
91 lines (78 loc) · 3.89 KB
/
commands.ts
File metadata and controls
91 lines (78 loc) · 3.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import * as vscode from "vscode";
import { Client } from "./client";
import { restartExtHostOnChangeIfNeeded } from "./util";
export function registerEnablementCommands(context: vscode.ExtensionContext): void {
context.subscriptions.push(vscode.commands.registerCommand("typescript.native-preview.enable", () => {
// Fire and forget, because this will restart the extension host and cause an error if we await
updateUseTsgoSetting(true);
}));
context.subscriptions.push(vscode.commands.registerCommand("typescript.native-preview.disable", () => {
// Fire and forget, because this will restart the extension host and cause an error if we await
updateUseTsgoSetting(false);
}));
}
export function registerLanguageCommands(context: vscode.ExtensionContext, client: Client, outputChannel: vscode.OutputChannel, traceOutputChannel: vscode.OutputChannel): vscode.Disposable[] {
const disposables: vscode.Disposable[] = [];
disposables.push(vscode.commands.registerCommand("typescript.native-preview.restart", () => {
return client.restart(context);
}));
disposables.push(vscode.commands.registerCommand("typescript.native-preview.output.focus", () => {
outputChannel.show();
}));
disposables.push(vscode.commands.registerCommand("typescript.native-preview.lsp-trace.focus", () => {
traceOutputChannel.show();
}));
disposables.push(vscode.commands.registerCommand("typescript.native-preview.selectVersion", async () => {
}));
disposables.push(vscode.commands.registerCommand("typescript.native-preview.showMenu", showCommands));
return disposables;
}
/**
* Updates the TypeScript Native Preview setting and reloads extension host.
*/
async function updateUseTsgoSetting(enable: boolean): Promise<void> {
const tsConfig = vscode.workspace.getConfiguration("typescript");
let target: vscode.ConfigurationTarget | undefined;
const useTsgo = tsConfig.inspect("experimental.useTsgo");
if (useTsgo) {
target = useTsgo.workspaceFolderValue !== undefined ? vscode.ConfigurationTarget.WorkspaceFolder :
useTsgo.workspaceValue !== undefined ? vscode.ConfigurationTarget.Workspace :
useTsgo.globalValue !== undefined ? vscode.ConfigurationTarget.Global : undefined;
}
// Update the setting and restart the extension host (needed to change the state of the built-in TS extension)
await tsConfig.update("experimental.useTsgo", enable, target ?? vscode.ConfigurationTarget.Global);
await restartExtHostOnChangeIfNeeded();
}
/**
* Shows the quick pick menu for TypeScript Native Preview commands
*/
async function showCommands(): Promise<void> {
const commands: readonly { label: string; description: string; command: string; }[] = [
{
label: "$(refresh) Restart Server",
description: "Restart the TypeScript Native Preview language server",
command: "typescript.native-preview.restart",
},
{
label: "$(output) Show TS Server Log",
description: "Show the TypeScript Native Preview server log",
command: "typescript.native-preview.output.focus",
},
{
label: "$(debug-console) Show LSP Messages",
description: "Show the LSP communication trace",
command: "typescript.native-preview.lsp-trace.focus",
},
{
label: "$(stop-circle) Disable TypeScript Native Preview",
description: "Switch back to the built-in TypeScript extension",
command: "typescript.native-preview.disable",
},
];
const selected = await vscode.window.showQuickPick(commands, {
placeHolder: "TypeScript Native Preview Commands",
});
if (selected) {
await vscode.commands.executeCommand(selected.command);
}
}