Skip to content

Commit

Permalink
Support cleanup of old version after install
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-mccall committed Jan 25, 2022
1 parent f2519af commit 2c2a397
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
6 changes: 3 additions & 3 deletions src/clangd-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
5 changes: 3 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
30 changes: 27 additions & 3 deletions src/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string|null> {
workspaceState: vscode.Memento,
globalState: vscode.Memento): Promise<string|null> {
// If the workspace overrides clangd.path, give the user a chance to bless it.
await config.getSecureOrPrompt<string>('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(
Expand All @@ -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<string|undefined> {
Expand Down Expand Up @@ -86,6 +88,21 @@ class UI {
}
}

async promptDelete(path: string): Promise<boolean|undefined> {
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');
Expand Down Expand Up @@ -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<string>('clangd.install.cleanupPath');
}
set cleanupPath(p: string|undefined) {
this.globalState.update('clangd.install.cleanupPath', p);
}
}

0 comments on commit 2c2a397

Please sign in to comment.