diff --git a/package.json b/package.json index ae1aba43..f28130c9 100644 --- a/package.json +++ b/package.json @@ -1322,6 +1322,16 @@ "type": "string" } }, + "r.rterm.preferredConsoles": { + "type": "array", + "default": [ + "R" + ], + "markdownDescription": "Ordered list of R console executable names to search for on `PATH` when no explicit terminal path is set (e.g. `r.rterm.linux`). The first entry found on `PATH` will be used. Examples: `arf`, `radian`, `R`.", + "items": { + "type": "string" + } + }, "r.libPaths": { "type": "array", "items": { @@ -2042,4 +2052,4 @@ "extensionDependencies": [ "REditorSupport.r-syntax" ] -} +} \ No newline at end of file diff --git a/src/util.ts b/src/util.ts index 82415567..b170874c 100644 --- a/src/util.ts +++ b/src/util.ts @@ -40,7 +40,7 @@ export function substituteVariables(str: string): string { return result; } -function getRfromEnvPath(platform: string) { +function getRfromEnvPath(platform: string, executableName: string = 'R') { let splitChar = ':'; let fileExtension = ''; @@ -51,7 +51,7 @@ function getRfromEnvPath(platform: string) { const os_paths: string[] | string = process.env.PATH ? process.env.PATH.split(splitChar) : []; for (const os_path of os_paths) { - const os_r_path: string = path.join(os_path, 'R' + fileExtension); + const os_r_path: string = path.join(os_path, executableName + fileExtension); if (fs.existsSync(os_r_path)) { return os_r_path; } @@ -66,7 +66,7 @@ export async function getRpathFromSystem(): Promise { rpath ||= getRfromEnvPath(platform); - if ( !rpath && platform === 'win32') { + if (!rpath && platform === 'win32') { // Find path from registry try { const key = new winreg({ @@ -134,6 +134,20 @@ export async function getRterm(): Promise { const configEntry = getRPathConfigEntry(true); let rpath = config().get(configEntry); rpath &&= substituteVariables(rpath); + + if (!rpath) { + const platform: string = process.platform; + const preferredConsoles = config().get('rterm.preferredConsoles', ['R']); + + for (const consoleName of preferredConsoles) { + rpath = getRfromEnvPath(platform, consoleName); + if (rpath) { + break; + } + } + } + + // Fall back to system R path if still not found rpath ||= await getRpathFromSystem(); if (rpath !== '') {