Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 35 additions & 9 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,40 @@

import { existsSync } from 'fs-extra';
import path = require('path');
import fs = require('fs');
import { window, workspace } from 'vscode';
import winreg = require('winreg');

export function config() {
return workspace.getConfiguration('r');
}

function getRfromEnvPath(platform: string) {
let splitChar: string = ':';
let fileExtension: string = '';

if (platform === 'win32') {
splitChar = ';';
fileExtension = '.exe';
}

const os_paths: string[]|string = process.env.PATH.split(splitChar);
for (const os_path of os_paths) {
const os_r_path: string = path.join(os_path, 'R' + fileExtension);
if (fs.existsSync(os_r_path)) {
return os_r_path;
}
}
return '';
}

export async function getRpath() {
if (process.platform === 'win32') {
let rpath: string = config().get<string>('rterm.windows');

let rpath: string = '';
const platform: string = process.platform;

if ( platform === 'win32') {
rpath = config().get<string>('rterm.windows');
if (rpath === '') {
// Find path from registry
try {
Expand All @@ -26,17 +50,19 @@ export async function getRpath() {
rpath = '';
}
}

return rpath;
} else if (platform === 'darwin') {
rpath = config().get<string>('rterm.mac');
} else if (platform === 'linux') {
rpath = config().get<string>('rterm.linux');
}
if (process.platform === 'darwin') {
return config().get<string>('rterm.mac');

if (rpath === '') {
rpath = getRfromEnvPath(platform);
}
if (process.platform === 'linux') {
return config().get<string>('rterm.linux');
if (rpath !== '') {
return rpath;
}
window.showErrorMessage(`${process.platform} can't use R`);

return undefined;
}

Expand Down