Skip to content

Commit

Permalink
Merge pull request #63 from rzk-lang/fix/updating-rzk
Browse files Browse the repository at this point in the history
Fix updating rzk binary
  • Loading branch information
aabounegm authored Nov 1, 2023
2 parents b9ab957 + 24b52a3 commit 2894d85
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 10 deletions.
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,11 @@
"commands": [
{
"command": "rzk.clearLocalInstallations",
"title": "Rzk [Debug]: Clear local Rzk installation",
"when": "inDebugMode"
"title": "Rzk: Clear local Rzk installation"
},
{
"command": "rzk.restartLspServer",
"title": "Rzk: Restart LSP server"
}
],
"yamlValidation": [
Expand Down
32 changes: 29 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,12 @@ export function activate(context: vscode.ExtensionContext) {
delimiter + binFolder.fsPath
);

vscode.commands.registerCommand('rzk.clearLocalInstallations', () => {
clearLocalInstallations(binFolder);
});
vscode.commands.registerCommand(
'rzk.clearLocalInstallations',
(silent = false) => {
clearLocalInstallations(binFolder, silent);
}
);

if (rzkPath) {
let serverOptions: ServerOptions = {
Expand Down Expand Up @@ -117,6 +120,29 @@ export function activate(context: vscode.ExtensionContext) {
output.appendLine('Language server error: ' + JSON.stringify(e));
});

// For internal use. I don't see a good reason to expose to the client
vscode.commands.registerCommand('rzk.stopLspServer', async () => {
try {
await client.stop();
output.appendLine('Language server stopped successfully');
} catch (e) {
output.appendLine(
'Error stopping language server: ' + JSON.stringify(e)
);
}
});

vscode.commands.registerCommand('rzk.restartLspServer', async () => {
try {
await client.restart();
output.appendLine('Language server restarted successfully');
} catch (e) {
output.appendLine(
'Error restarting language server: ' + JSON.stringify(e)
);
}
});

context.subscriptions.push(client);
}
}
36 changes: 31 additions & 5 deletions src/installRzk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,35 @@ async function installLatestRzk(binFolder: vscode.Uri, progress?: Progress) {

output.appendLine(`Extracting to "${binFolder.path}"`);
const assetStream = Readable.from(Buffer.from(assetBuffer));
// Stop the server to avoid any possible permission denied errors
await vscode.commands.executeCommand('rzk.stopLspServer');
// Silently clear the existing installation. Apparently, stopping the server is not enough
await vscode.commands.executeCommand('rzk.clearLocalInstallations', true);
let error = false;
const tarInputStream = extract({
cwd: binFolder.fsPath,
onwarn(code, message, data) {
// Note: throwing here causes it to fail silently. It cannot be caught
error = true;
output.appendLine(
`Error ${code} occurred while extracting: "${message}"`
);
vscode.window
.showWarningMessage(
`An error occurred during extraction (${code}).
Please file an issue on [GitHub](https://github.com/rzk-lang/vscode-rzk/issues).
Don't forget to include the logs from the output panel.`,
'Open output panel'
)
.then((action) => {
if (action === 'Open output panel') {
output.show();
}
});
},
});
await pipeline(assetStream, tarInputStream);
if (error) return;
output.appendLine('File extracted successfully');
vscode.window
.showInformationMessage(
Expand Down Expand Up @@ -243,15 +268,16 @@ async function checkForUpdates(binPath: string, binFolder?: vscode.Uri) {
}
}

export function clearLocalInstallations(binFolder: vscode.Uri) {
export function clearLocalInstallations(binFolder: vscode.Uri, silent = false) {
vscode.workspace.fs
.delete(vscode.Uri.joinPath(binFolder, binName))
.then(() =>
vscode.window.showInformationMessage(
.then(() => {
if (silent) return;
return vscode.window.showInformationMessage(
'Rzk successfully removed from VS Code. Please reload the window',
'Reload'
)
)
);
})
.then((value) => {
if (value === 'Reload') {
vscode.commands.executeCommand('workbench.action.reloadWindow');
Expand Down

0 comments on commit 2894d85

Please sign in to comment.