@@ -12,11 +12,12 @@ import * as config from './config';
12
12
// Returns the clangd path to be used, or null if clangd is not installed.
13
13
export async function activate (
14
14
context : ClangdContext , globalStoragePath : string ,
15
- workspaceState : vscode . Memento ) : Promise < string | null > {
15
+ workspaceState : vscode . Memento ,
16
+ globalState : vscode . Memento ) : Promise < string | null > {
16
17
// If the workspace overrides clangd.path, give the user a chance to bless it.
17
18
await config . getSecureOrPrompt < string > ( 'path' , workspaceState ) ;
18
19
19
- const ui = new UI ( context , globalStoragePath , workspaceState ) ;
20
+ const ui = new UI ( context , globalStoragePath , workspaceState , globalState ) ;
20
21
context . subscriptions . push ( vscode . commands . registerCommand (
21
22
'clangd.install' , async ( ) => common . installLatest ( ui ) ) ) ;
22
23
context . subscriptions . push ( vscode . commands . registerCommand (
@@ -27,7 +28,8 @@ export async function activate(
27
28
28
29
class UI {
29
30
constructor ( private context : ClangdContext , private globalStoragePath : string ,
30
- private workspaceState : vscode . Memento ) { }
31
+ private workspaceState : vscode . Memento ,
32
+ private globalState : vscode . Memento ) { }
31
33
32
34
get storagePath ( ) : string { return this . globalStoragePath ; }
33
35
async choose ( prompt : string , options : string [ ] ) : Promise < string | undefined > {
@@ -86,6 +88,21 @@ class UI {
86
88
}
87
89
}
88
90
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
+
89
106
async promptReload ( message : string ) {
90
107
if ( await vscode . window . showInformationMessage ( message , 'Reload window' ) )
91
108
vscode . commands . executeCommand ( 'workbench.action.reloadWindow' ) ;
@@ -136,4 +153,11 @@ class UI {
136
153
set clangdPath ( p : string ) {
137
154
config . update ( 'path' , p , vscode . ConfigurationTarget . Global ) ;
138
155
}
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
+ }
139
163
}
0 commit comments