forked from microsoft/typespec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextension.ts
66 lines (58 loc) · 2.36 KB
/
extension.ts
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
import vscode, { commands, ExtensionContext } from "vscode";
import { createCodeActionProvider } from "./code-action-provider.js";
import { SettingName } from "./const.js";
import { ExtensionLogListener } from "./log/extension-log-listener.js";
import logger from "./log/logger.js";
import { TypeSpecLogOutputChannel } from "./log/typespec-log-output-channel.js";
import { createTaskProvider } from "./task-provider.js";
import { TspLanguageClient } from "./tsp-language-client.js";
import { createCommandOpenUrl } from "./vscode-command.js";
let client: TspLanguageClient | undefined;
/**
* Workaround: LogOutputChannel doesn't work well with LSP RemoteConsole, so having a customized LogOutputChannel to make them work together properly
* More detail can be found at https://github.com/microsoft/vscode-discussions/discussions/1149
*/
const outputChannel = new TypeSpecLogOutputChannel("TypeSpec");
logger.registerLogListener("extension-log", new ExtensionLogListener(outputChannel));
export async function activate(context: ExtensionContext) {
context.subscriptions.push(createTaskProvider());
context.subscriptions.push(createCodeActionProvider());
context.subscriptions.push(createCommandOpenUrl());
context.subscriptions.push(
commands.registerCommand("typespec.showOutputChannel", () => {
outputChannel.show(true /*preserveFocus*/);
}),
);
context.subscriptions.push(
commands.registerCommand("typespec.restartServer", async () => {
if (client) {
await client.restart();
}
}),
);
context.subscriptions.push(
vscode.workspace.onDidChangeConfiguration(async (e: vscode.ConfigurationChangeEvent) => {
if (e.affectsConfiguration(SettingName.TspServerPath)) {
logger.info("TypeSpec server path changed, restarting server...");
const oldClient = client;
client = await TspLanguageClient.create(context, outputChannel);
await oldClient?.stop();
await client.start();
}
}),
);
const tipToolTitle = vscode.l10n.t("Launching TypeSpec language service...");
return await vscode.window.withProgress(
{
title: tipToolTitle,
location: vscode.ProgressLocation.Notification,
},
async () => {
client = await TspLanguageClient.create(context, outputChannel);
await client.start();
},
);
}
export async function deactivate() {
await client?.stop();
}