@@ -7,6 +7,7 @@ import { config, getCurrentWorkspaceFolder, getRPathConfigEntry, isMultiRoot } f
77import { isVirtual , ExecutableType } from '../service' ;
88import { RExecutableService } from '../service' ;
99import { getRenvVersion } from '../virtual' ;
10+ import { extensionContext } from '../../extension' ;
1011
1112class ExecutableQuickPickItem implements vscode . QuickPickItem {
1213 public recommended : boolean ;
@@ -54,18 +55,16 @@ enum PathQuickPickMenu {
5455 configuration = '$(settings-gear) Configuration path'
5556}
5657
57- export class ExecutableQuickPick implements vscode . Disposable {
58+
59+ export class ExecutableQuickPick {
5860 private readonly service : RExecutableService ;
59- private quickpick : vscode . QuickPick < vscode . QuickPickItem > ;
61+ private quickpick : vscode . QuickPick < vscode . QuickPickItem | ExecutableQuickPickItem > ;
6062 private currentFolder : vscode . WorkspaceFolder ;
6163
6264 public constructor ( service : RExecutableService ) {
6365 this . service = service ;
6466 this . currentFolder = getCurrentWorkspaceFolder ( ) ;
65- }
66-
67- public dispose ( ) : void {
68- this . quickpick . dispose ( ) ;
67+ extensionContext . subscriptions . push ( this . quickpick ) ;
6968 }
7069
7170 private setItems ( ) : void {
@@ -178,7 +177,7 @@ export class ExecutableQuickPick implements vscode.Disposable {
178177 this . quickpick . hide ( ) ;
179178 }
180179 } ) ;
181- this . quickpick . onDidChangeSelection ( ( items : vscode . QuickPickItem [ ] ) => {
180+ this . quickpick . onDidChangeSelection ( ( items : vscode . QuickPickItem [ ] | ExecutableQuickPickItem [ ] ) => {
182181 const qpItem = items [ 0 ] ;
183182 if ( qpItem . label ) {
184183 switch ( qpItem . label ) {
@@ -189,7 +188,7 @@ export class ExecutableQuickPick implements vscode.Disposable {
189188 canSelectMany : false ,
190189 title : ' R executable file'
191190 } ;
192- void vscode . window . showOpenDialog ( opts ) . then ( ( epath ) => {
191+ void vscode . window . showOpenDialog ( opts ) . then ( ( epath : vscode . Uri [ ] ) => {
193192 if ( epath ) {
194193 const execPath = path . normalize ( epath ?. [ 0 ] . fsPath ) ;
195194 if ( execPath && validateRExecutablePath ( execPath ) ) {
@@ -215,7 +214,13 @@ export class ExecutableQuickPick implements vscode.Disposable {
215214 break ;
216215 }
217216 default : {
218- this . service . setWorkspaceExecutable ( this . currentFolder ?. uri ?. fsPath , ( qpItem as ExecutableQuickPickItem ) . executable ) ;
217+ const executable = ( qpItem as ExecutableQuickPickItem ) . executable ;
218+ if ( executable ?. rVersion ) {
219+ this . service . setWorkspaceExecutable ( this . currentFolder ?. uri ?. fsPath , executable ) ;
220+ } else {
221+ void vscode . window . showErrorMessage ( ExecutableNotifications . badInstallation ) ;
222+ this . service . setWorkspaceExecutable ( this . currentFolder ?. uri ?. fsPath , undefined ) ;
223+ }
219224 break ;
220225 }
221226 }
0 commit comments