From 2c2a397516cf797be068d9741d4278be080ca044 Mon Sep 17 00:00:00 2001 From: Sam McCall Date: Tue, 25 Jan 2022 21:39:50 +0100 Subject: [PATCH] Support cleanup of old version after install Depends on https://github.com/clangd/node-clangd/pull/12 --- package.json | 2 +- src/clangd-context.ts | 6 +++--- src/extension.ts | 5 +++-- src/install.ts | 30 +++++++++++++++++++++++++++--- 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 1316d442..f85c62e2 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "git-clang-format": "git-clang-format" }, "dependencies": { - "@clangd/install": "0.1.4", + "@clangd/install": "1.0.0", "abort-controller": "^3.0.0", "vscode-languageclient": "7.1.0-next.1" }, diff --git a/src/clangd-context.ts b/src/clangd-context.ts index 09a6e39f..28b8d7cf 100644 --- a/src/clangd-context.ts +++ b/src/clangd-context.ts @@ -59,9 +59,9 @@ export class ClangdContext implements vscode.Disposable { client!: ClangdLanguageClient; async activate(globalStoragePath: string, outputChannel: vscode.OutputChannel, - workspaceState: vscode.Memento) { - const clangdPath = - await install.activate(this, globalStoragePath, workspaceState); + workspaceState: vscode.Memento, globalState: vscode.Memento) { + const clangdPath = await install.activate(this, globalStoragePath, + workspaceState, globalState); if (!clangdPath) return; diff --git a/src/extension.ts b/src/extension.ts index 6d2b596a..98d9bf9d 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -21,11 +21,12 @@ export async function activate(context: vscode.ExtensionContext) { vscode.commands.registerCommand('clangd.restart', async () => { await clangdContext.dispose(); await clangdContext.activate(context.globalStoragePath, outputChannel, - context.workspaceState); + context.workspaceState, + context.globalState); })); await clangdContext.activate(context.globalStoragePath, outputChannel, - context.workspaceState); + context.workspaceState, context.globalState); const shouldCheck = vscode.workspace.getConfiguration('clangd').get( 'detectExtensionConflicts'); diff --git a/src/install.ts b/src/install.ts index 50974e13..f3bcd176 100644 --- a/src/install.ts +++ b/src/install.ts @@ -12,11 +12,12 @@ import * as config from './config'; // Returns the clangd path to be used, or null if clangd is not installed. export async function activate( context: ClangdContext, globalStoragePath: string, - workspaceState: vscode.Memento): Promise { + workspaceState: vscode.Memento, + globalState: vscode.Memento): Promise { // If the workspace overrides clangd.path, give the user a chance to bless it. await config.getSecureOrPrompt('path', workspaceState); - const ui = new UI(context, globalStoragePath, workspaceState); + const ui = new UI(context, globalStoragePath, workspaceState, globalState); context.subscriptions.push(vscode.commands.registerCommand( 'clangd.install', async () => common.installLatest(ui))); context.subscriptions.push(vscode.commands.registerCommand( @@ -27,7 +28,8 @@ export async function activate( class UI { constructor(private context: ClangdContext, private globalStoragePath: string, - private workspaceState: vscode.Memento) {} + private workspaceState: vscode.Memento, + private globalState: vscode.Memento) {} get storagePath(): string { return this.globalStoragePath; } async choose(prompt: string, options: string[]): Promise { @@ -86,6 +88,21 @@ class UI { } } + async promptDelete(path: string): Promise { + const message = `Delete the previous clangd installation? ${path}`; + const remove = 'Delete it'; + const preserve = 'Keep it'; + const response = + await vscode.window.showInformationMessage(message, remove, preserve); + if (response === remove) { + return true; + } else if (response === preserve) { + return false; + } else { + return undefined; // User dismissed prompt, bail out. + } + } + async promptReload(message: string) { if (await vscode.window.showInformationMessage(message, 'Reload window')) vscode.commands.executeCommand('workbench.action.reloadWindow'); @@ -136,4 +153,11 @@ class UI { set clangdPath(p: string) { config.update('path', p, vscode.ConfigurationTarget.Global); } + + get cleanupPath(): string|undefined { + return this.globalState.get('clangd.install.cleanupPath'); + } + set cleanupPath(p: string|undefined) { + this.globalState.update('clangd.install.cleanupPath', p); + } }