Skip to content

Commit

Permalink
Merge pull request #67 from rzk-lang/hotfix/first-time-installation
Browse files Browse the repository at this point in the history
Fix first time installation
  • Loading branch information
aabounegm authored Nov 20, 2023
2 parents de1e48a + 249c168 commit 54eb77e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 26 deletions.
46 changes: 22 additions & 24 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export function activate(context: vscode.ExtensionContext) {
}
);

let client: LanguageClient;
if (rzkPath) {
let serverOptions: ServerOptions = {
run: {
Expand Down Expand Up @@ -103,7 +104,7 @@ export function activate(context: vscode.ExtensionContext) {
};

// Create the language client and start the client.
const client = new LanguageClient(
client = new LanguageClient(
'rzk-language-server',
'Rzk Language Server',
serverOptions,
Expand All @@ -120,29 +121,26 @@ 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);
}
// 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)
);
}
});
}
14 changes: 12 additions & 2 deletions src/installRzk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,19 @@ 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');
await vscode.commands
.executeCommand('rzk.stopLspServer')
.then(undefined, (err) => {
output.appendLine(
`Error stopping the LSP server (${err}). Perhaps the server wasn't running? `
);
});
// Silently clear the existing installation. Apparently, stopping the server is not enough
await vscode.commands.executeCommand('rzk.clearLocalInstallations', true);
await vscode.commands
.executeCommand('rzk.clearLocalInstallations', true)
.then(undefined, (err) => {
output.appendLine('Error clearing local installations.');
});
let error = false;
const tarInputStream = extract({
cwd: binFolder.fsPath,
Expand Down

0 comments on commit 54eb77e

Please sign in to comment.