Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install LS into dedicated (persistent) global storage #811

Merged
merged 1 commit into from
Oct 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/languageServerInstaller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,18 @@ export class LanguageServerInstaller {
throw new Error(`Install error: no matching terraform-ls binary for ${os}/${arch}`);
}
try {
this.removeOldBinary();
fs.unlinkSync(this.lsPath.binPath());
} catch {
// ignore missing binary (new install)
}

try {
fs.unlinkSync(this.lsPath.legacyBinPath());
} catch {
// clean up may fail for new installation
// or in new versions where this path is no longer in use
}

return vscode.window.withProgress(
{
cancellable: true,
Expand All @@ -147,10 +154,6 @@ export class LanguageServerInstaller {
);
}

removeOldBinary(): void {
fs.unlinkSync(this.lsPath.binPath());
}

public async cleanupZips(): Promise<string[]> {
const pattern = path.resolve(this.lsPath.installPath(), 'terraform-ls*.zip');
return del(pattern, { force: true });
Expand Down
11 changes: 9 additions & 2 deletions src/serverPath.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as path from 'path';
import * as vscode from 'vscode';

const INSTALL_FOLDER_NAME = 'lsp';
const INSTALL_FOLDER_NAME = 'bin';
export const CUSTOM_BIN_PATH_OPTION_NAME = 'languageServer.pathToBinary';

export class ServerPath {
Expand All @@ -12,7 +12,14 @@ export class ServerPath {
}

public installPath(): string {
return this.context.asAbsolutePath(INSTALL_FOLDER_NAME);
return path.join(this.context.globalStorageUri.fsPath, INSTALL_FOLDER_NAME);
}

// legacyBinPath represents old location where LS was installed.
// We only use it to ensure that old installations are removed
// from there after LS is installed into the new path.
public legacyBinPath(): string {
return path.resolve(this.context.asAbsolutePath('lsp'), this.binName());
}

public hasCustomBinPath(): boolean {
Expand Down