Skip to content

Commit 0fd7424

Browse files
committed
Show error when selecting a bad installation
Error is triggered when selecting an R installation that cannot be opened
1 parent 37a3a09 commit 0fd7424

File tree

5 files changed

+22
-17
lines changed

5 files changed

+22
-17
lines changed

src/executables/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ export class RExecutableManager {
2727
}
2828
}),
2929
this.executableService,
30-
this.statusBar,
31-
this.quickPick
30+
this.statusBar
3231
);
3332
this.reload();
3433
}
@@ -95,7 +94,7 @@ export class RExecutableManager {
9594
export function validateRExecutablePath(execPath: string): boolean {
9695
try {
9796
const basename = process.platform === 'win32' ? 'R.exe' : 'R';
98-
fs.accessSync(execPath, fs.constants.X_OK);
97+
fs.accessSync(execPath, fs.constants.X_OK && fs.constants.R_OK);
9998
return (path.basename(execPath) === basename);
10099
} catch (error) {
101100
return false;

src/executables/service/locator/unix.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class UnixExecLocator extends AbstractLocatorService {
1717
new Set([
1818
...this.getPathFromDirs(),
1919
...this.getPathFromEnv(),
20-
... this.getPathFromConda()
20+
...this.getPathFromConda()
2121
])
2222
));
2323
this.emitter.fire(this._executablePaths);

src/executables/service/locator/windows.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import os = require('os');
44
import path = require('path');
55
import winreg = require('winreg');
66
import { getUniquePaths, AbstractLocatorService } from './shared';
7-
import { validateRExecutablePath } from '../..';
7+
88

99
const WindowsKnownPaths: string[] = [];
1010

@@ -88,11 +88,11 @@ export class WindowsExecLocator extends AbstractLocatorService {
8888
const i386 = `${rPath}\\${dir}\\bin\\i386\\R.exe`;
8989
const x64 = `${rPath}\\${dir}\\bin\\x64\\R.exe`;
9090

91-
if (validateRExecutablePath(i386)) {
91+
if (fs.existsSync(i386)) {
9292
execPaths.push(i386);
9393
}
9494

95-
if (validateRExecutablePath(x64)) {
95+
if (fs.existsSync(x64)) {
9696
execPaths.push(x64);
9797
}
9898
}

src/executables/ui/quickpick.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { config, getCurrentWorkspaceFolder, getRPathConfigEntry, isMultiRoot } f
77
import { isVirtual, ExecutableType } from '../service';
88
import { RExecutableService } from '../service';
99
import { getRenvVersion } from '../virtual';
10+
import { extensionContext } from '../../extension';
1011

1112
class 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
}

src/executables/ui/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export enum ExecutableNotifications {
22
badFolder = 'Supplied R executable path is not a valid R path.',
3-
badConfig = 'Configured path is not a valid R executable path.'
3+
badConfig = 'Configured path is not a valid R executable path.',
4+
badInstallation = 'Supplied R executable cannot be launched on this operating system.'
45
}

0 commit comments

Comments
 (0)