|
7 | 7 | ServerOptions
|
8 | 8 | } from "vscode-languageclient/node";
|
9 | 9 | import axios from "axios";
|
10 |
| -import { existsSync, mkdirSync, writeFileSync } from "fs"; |
| 10 | +import { existsSync, writeFileSync } from "fs"; |
| 11 | +import * as mkdirp from "mkdirp"; |
11 | 12 |
|
12 | 13 | let outputChannel: vscode.OutputChannel;
|
13 | 14 | let client: LanguageClient | null = null;
|
@@ -46,23 +47,30 @@ async function installExecutable(context: ExtensionContext): Promise<void> {
|
46 | 47 | return;
|
47 | 48 | }
|
48 | 49 |
|
49 |
| - const buildRunner = (await axios.get(`${downloadsRoot}/${def}/bin/build_runner.zig`)).data; |
50 |
| - const exe = (await axios.get(`${downloadsRoot}/${def}/bin/zls${def.endsWith("windows") ? ".exe" : ""}`, { |
51 |
| - responseType: "arraybuffer" |
52 |
| - })).data; |
53 |
| - |
54 |
| - const installDir = vscode.Uri.joinPath(context.globalStorageUri, "zls_install"); |
55 |
| - if (!existsSync(installDir.fsPath)) |
56 |
| - mkdirSync(installDir.fsPath); |
57 |
| - |
58 |
| - writeFileSync(vscode.Uri.joinPath(installDir, `build_runner.zig`).fsPath, buildRunner); |
59 |
| - writeFileSync(vscode.Uri.joinPath(installDir, `zls${def.endsWith("windows") ? ".exe" : ""}`).fsPath, exe, "binary"); |
60 |
| - |
61 |
| - let config = workspace.getConfiguration("zls"); |
62 |
| - await config.update("path", vscode.Uri.joinPath(installDir, `zls${def.endsWith("windows") ? ".exe" : ""}`).fsPath, true); |
63 |
| - |
64 |
| - window.showInformationMessage("zls has been installed and your `zls.path` has been set accordingly!"); |
65 |
| - startClient(context); |
| 50 | + return window.withProgress({ |
| 51 | + title: "Installing zls...", |
| 52 | + location: vscode.ProgressLocation.Notification, |
| 53 | + }, async progress => { |
| 54 | + progress.report({message: "Downloading build runner..."}); |
| 55 | + const buildRunner = (await axios.get(`${downloadsRoot}/${def}/bin/build_runner.zig`)).data; |
| 56 | + progress.report({message: "Downloading zls executable..."}); |
| 57 | + const exe = (await axios.get(`${downloadsRoot}/${def}/bin/zls${def.endsWith("windows") ? ".exe" : ""}`, { |
| 58 | + responseType: "arraybuffer" |
| 59 | + })).data; |
| 60 | + |
| 61 | + progress.report({message: "Installing..."}); |
| 62 | + const installDir = vscode.Uri.joinPath(context.globalStorageUri, "zls_install"); |
| 63 | + if (!existsSync(installDir.fsPath)) |
| 64 | + mkdirp.sync(installDir.fsPath); |
| 65 | + |
| 66 | + writeFileSync(vscode.Uri.joinPath(installDir, `build_runner.zig`).fsPath, buildRunner); |
| 67 | + writeFileSync(vscode.Uri.joinPath(installDir, `zls${def.endsWith("windows") ? ".exe" : ""}`).fsPath, exe, "binary"); |
| 68 | + |
| 69 | + let config = workspace.getConfiguration("zls"); |
| 70 | + await config.update("path", vscode.Uri.joinPath(installDir, `zls${def.endsWith("windows") ? ".exe" : ""}`).fsPath, true); |
| 71 | + |
| 72 | + startClient(context); |
| 73 | + }); |
66 | 74 | }
|
67 | 75 |
|
68 | 76 | export function activate(context: ExtensionContext) {
|
@@ -115,15 +123,8 @@ function startClient(context: ExtensionContext): Promise<void> {
|
115 | 123 | return new Promise<void>(resolve => {
|
116 | 124 | if (client)
|
117 | 125 | client.start().catch(err => {
|
118 |
| - window.showInformationMessage( |
119 |
| - "It seems that we couldn't find your zls install! Either: Add zls to your system PATH, specify where to find zls with the `zls.path` option, or automatically install zls with the button below (recommended!)", |
120 |
| - {}, |
121 |
| - "Install zls for me!", |
122 |
| - ).then(value => { |
123 |
| - if (value) { |
124 |
| - installExecutable(context); |
125 |
| - } |
126 |
| - }); |
| 126 | + window.showInformationMessage("We're installing zls for you! Feel free to change your `zls.path` later if you so wish!"); |
| 127 | + installExecutable(context); |
127 | 128 | client = null;
|
128 | 129 | }).then(() => {
|
129 | 130 | if (client) {
|
|
0 commit comments