Skip to content

Commit 2c2a397

Browse files
committed
Support cleanup of old version after install
Depends on clangd/node-clangd#12
1 parent f2519af commit 2c2a397

File tree

4 files changed

+34
-9
lines changed

4 files changed

+34
-9
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"git-clang-format": "git-clang-format"
4545
},
4646
"dependencies": {
47-
"@clangd/install": "0.1.4",
47+
"@clangd/install": "1.0.0",
4848
"abort-controller": "^3.0.0",
4949
"vscode-languageclient": "7.1.0-next.1"
5050
},

src/clangd-context.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ export class ClangdContext implements vscode.Disposable {
5959
client!: ClangdLanguageClient;
6060

6161
async activate(globalStoragePath: string, outputChannel: vscode.OutputChannel,
62-
workspaceState: vscode.Memento) {
63-
const clangdPath =
64-
await install.activate(this, globalStoragePath, workspaceState);
62+
workspaceState: vscode.Memento, globalState: vscode.Memento) {
63+
const clangdPath = await install.activate(this, globalStoragePath,
64+
workspaceState, globalState);
6565
if (!clangdPath)
6666
return;
6767

src/extension.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ export async function activate(context: vscode.ExtensionContext) {
2121
vscode.commands.registerCommand('clangd.restart', async () => {
2222
await clangdContext.dispose();
2323
await clangdContext.activate(context.globalStoragePath, outputChannel,
24-
context.workspaceState);
24+
context.workspaceState,
25+
context.globalState);
2526
}));
2627

2728
await clangdContext.activate(context.globalStoragePath, outputChannel,
28-
context.workspaceState);
29+
context.workspaceState, context.globalState);
2930

3031
const shouldCheck = vscode.workspace.getConfiguration('clangd').get(
3132
'detectExtensionConflicts');

src/install.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ import * as config from './config';
1212
// Returns the clangd path to be used, or null if clangd is not installed.
1313
export async function activate(
1414
context: ClangdContext, globalStoragePath: string,
15-
workspaceState: vscode.Memento): Promise<string|null> {
15+
workspaceState: vscode.Memento,
16+
globalState: vscode.Memento): Promise<string|null> {
1617
// If the workspace overrides clangd.path, give the user a chance to bless it.
1718
await config.getSecureOrPrompt<string>('path', workspaceState);
1819

19-
const ui = new UI(context, globalStoragePath, workspaceState);
20+
const ui = new UI(context, globalStoragePath, workspaceState, globalState);
2021
context.subscriptions.push(vscode.commands.registerCommand(
2122
'clangd.install', async () => common.installLatest(ui)));
2223
context.subscriptions.push(vscode.commands.registerCommand(
@@ -27,7 +28,8 @@ export async function activate(
2728

2829
class UI {
2930
constructor(private context: ClangdContext, private globalStoragePath: string,
30-
private workspaceState: vscode.Memento) {}
31+
private workspaceState: vscode.Memento,
32+
private globalState: vscode.Memento) {}
3133

3234
get storagePath(): string { return this.globalStoragePath; }
3335
async choose(prompt: string, options: string[]): Promise<string|undefined> {
@@ -86,6 +88,21 @@ class UI {
8688
}
8789
}
8890

91+
async promptDelete(path: string): Promise<boolean|undefined> {
92+
const message = `Delete the previous clangd installation? ${path}`;
93+
const remove = 'Delete it';
94+
const preserve = 'Keep it';
95+
const response =
96+
await vscode.window.showInformationMessage(message, remove, preserve);
97+
if (response === remove) {
98+
return true;
99+
} else if (response === preserve) {
100+
return false;
101+
} else {
102+
return undefined; // User dismissed prompt, bail out.
103+
}
104+
}
105+
89106
async promptReload(message: string) {
90107
if (await vscode.window.showInformationMessage(message, 'Reload window'))
91108
vscode.commands.executeCommand('workbench.action.reloadWindow');
@@ -136,4 +153,11 @@ class UI {
136153
set clangdPath(p: string) {
137154
config.update('path', p, vscode.ConfigurationTarget.Global);
138155
}
156+
157+
get cleanupPath(): string|undefined {
158+
return this.globalState.get<string>('clangd.install.cleanupPath');
159+
}
160+
set cleanupPath(p: string|undefined) {
161+
this.globalState.update('clangd.install.cleanupPath', p);
162+
}
139163
}

0 commit comments

Comments
 (0)