Skip to content
This repository was archived by the owner on Feb 19, 2023. It is now read-only.

Commit f8021e4

Browse files
committed
Modify installation model, fix mkdirp issue
Closes #43
1 parent 5940837 commit f8021e4

File tree

5 files changed

+79
-36
lines changed

5 files changed

+79
-36
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,7 @@ instead of using `zls.json`!
3737
## 1.1.0
3838

3939
> You can now install zls directly from the extension! Enjoy!
40+
41+
## 1.1.1
42+
43+
> Bug fixes, more streamlined installation

README.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
## Installing
88

9-
Simply install the extension and follow the instructions in the "It seems that we couldn't find your zls install" popup if it appears - we recommend clicking the "Install zls for me!" button if you're a typical user that's not planning to contribute to zls itself. :)
9+
Simply install the extension and you'll be good to go!
1010

11-
If you *aren't* a typical user, follow the instructions [https://github.com/zigtools/zls#from-source](here) and then add zls to your system PATH or specify the path of the zls binary with the `zls.path` option in VSCode!
11+
If you want to build zls yourself, follow the instructions [https://github.com/zigtools/zls#from-source](here) and then specify the path of the zls binary with the `zls.path` option in VSCode!
1212

1313
Happy Zig-ing!
1414

@@ -51,3 +51,7 @@ instead of using `zls.json`!
5151
### 1.1.0
5252

5353
> You can now install zls directly from the extension! Enjoy!
54+
55+
### 1.1.1
56+
57+
> Bug fixes, more streamlined installation

package-lock.json

+38-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"type": "git",
1212
"url": "https://github.com/zigtools/zls-vscode"
1313
},
14-
"version": "1.1.0",
14+
"version": "1.1.1",
1515
"engines": {
1616
"vscode": "^1.68.0"
1717
},
@@ -176,7 +176,9 @@
176176
"test": "node ./out/test/runTest.js"
177177
},
178178
"dependencies": {
179+
"@types/mkdirp": "^1.0.2",
179180
"axios": "^0.27.2",
181+
"mkdirp": "^1.0.4",
180182
"vscode-languageclient": "8.0.2-next.5"
181183
},
182184
"devDependencies": {

src/extension.ts

+28-27
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import {
77
ServerOptions
88
} from "vscode-languageclient/node";
99
import axios from "axios";
10-
import { existsSync, mkdirSync, writeFileSync } from "fs";
10+
import { existsSync, writeFileSync } from "fs";
11+
import * as mkdirp from "mkdirp";
1112

1213
let outputChannel: vscode.OutputChannel;
1314
let client: LanguageClient | null = null;
@@ -46,23 +47,30 @@ async function installExecutable(context: ExtensionContext): Promise<void> {
4647
return;
4748
}
4849

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+
});
6674
}
6775

6876
export function activate(context: ExtensionContext) {
@@ -115,15 +123,8 @@ function startClient(context: ExtensionContext): Promise<void> {
115123
return new Promise<void>(resolve => {
116124
if (client)
117125
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);
127128
client = null;
128129
}).then(() => {
129130
if (client) {

0 commit comments

Comments
 (0)