Add r.rterm.preferredConsoles for R console selection from PATH - #1625
Conversation
|
Would it make more sense to make R and radian selectable via an Enum? I recently created the arf console that can be used instead of radian, and I have personally switched from radian. |
This would also work. You mean something like: And then this extension would search the PATH for arf, radian, and r, and use the first it finds? This would be a very flexible solution. |
|
+1 on |
|
Fwiw,
|
|
@randy3k Do you have an idea how to proceed here? I could happily adjust the PR to use arf instead of radian, now that radian is not supported anymore. I'm also not shure if this PR is completely independent from #1684. Maybe you could tell us something about the big picture here. Many thanks in advance :) |
|
We shouldn't reply on radian anymore (python is not really a good platform for development an R console). I am not oppposing to the idea of "prefer arf". Though I am not sure if we want to "hard code" arf at the same time. A setting like "prefer this program if found" may be more useful? |
6137443 to
70b621a
Compare
Thanks for your feedback. I agree, hardcoding R consoles is not ideal. I updated the PR and now the new setting takes a list of console names that the user prefers. So you can specify for example I'll gladly adjust this further, based on your feebdack. |
|
@randy3k would you mind taking a look at this PR again? IMHO it's ready. |
grantmcdermott
left a comment
There was a problem hiding this comment.
I test locally it and seems to be working well.
I think it's probably out of scope. But my one question (concern?) is whether the "r.bracketedPaste" shouldn't be coupled with this new entry, since users will get garbled output for arf and radian if this field isn't set to true. Maybe a future "r.bracketedPaste": "auto" configuration could enable this automatically in an intelligent way?
|
I think this PR has been waiting for a long time, so I would not object to merging it as-is. However, since it adds yet another configuration option to an extension that already has quite a few of them, I think we should also consider cleaning up the overall configuration design. I asked ChatGPT to look at this from that longer-term perspective, and the main points were:
So I am fine with merging this PR for now, but if @grantmcdermott and others agree with the general direction, I would like to revisit this (in v4?) and reduce the number of configuration options rather than continuing to add more. From my perspective, there may also eventually be a case for treating arf specially. |
|
Those all sound like good ideas to me 👍 |
|
Sound great! Thank you all :) |
|
I've found copilot review comments to be quite helpful lately. So I'll ask it to do one last pass before we merge. |
There was a problem hiding this comment.
🟡 Changes recommended
Fix missing-setting handling and skip blank console entries during PATH lookup.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Adds configurable PATH-based selection for the R console while preserving explicit terminal paths and system fallback.
Changes:
- Adds
r.rterm.preferredConsoles, defaulting to["R"]. - Searches configured console names in preference order.
- Declares the new setting in the extension configuration.
File summaries
| File | Summary |
|---|---|
src/util.ts |
Implements preferred console PATH resolution. |
package.json |
Declares the new configuration option. |
Review details
Suppressed comments (2)
src/util.ts:140
getRterm()is called by the existing session integration tests with a configuration stub whosegetmethod returnsundefinedfor unknown keys and ignores the default argument. In that case this value isundefined, so thefor...ofbelow throws before the existing R-path fallback runs. Normalize the result with?? ['R'](or otherwise guard the array) so missing/invalid settings retain the documented default.
const preferredConsoles = config().get<string[]>('rterm.preferredConsoles', ['R']);
src/util.ts:146
- This introduces ordered PATH selection and explicit-path precedence, but the existing terminal/session tests do not exercise this branch. A focused test should stub the PATH and configuration to verify that an explicit
rterm.<platform>wins, otherwise the first existing preferred console wins, and the fallback remains the system R path; these cases are otherwise easy to regress without the suite detecting it.
const preferredConsoles = config().get<string[]>('rterm.preferredConsoles', ['R']);
for (const consoleName of preferredConsoles) {
rpath = getRfromEnvPath(platform, consoleName);
if (rpath) {
break;
}
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| const platform: string = process.platform; | ||
| const preferredConsoles = config().get<string[]>('rterm.preferredConsoles', ['R']); | ||
|
|
||
| for (const consoleName of preferredConsoles) { |
There was a problem hiding this comment.
@BerriJ Looks like you just need to indent this properly.
There was a problem hiding this comment.
Done, and while I was at it, I also squashed the commits together.
|
Remaining CI failure is a pre-existing issue (which we should probably address soon-ish). Thanks @BerriJ! |
|
I've opened #1735 |
Close #597 Close #1437 Supersede #1625 Related to #1130 ## Summary - add `r.executablePath` as the canonical vanilla R executable for language-server and other background processes - add `r.consolePath` as the canonical interactive console executable, including bare executable names resolved from `PATH` (for example, `arf` or `radian`) - formally deprecate the six platform-specific `r.rpath.<platform>` and `r.rterm.<platform>` settings while preserving them as compatibility inputs - Show a one-time compatibility warning when an installed R Debugger version still registers the legacy `r.rpath.<platform>` settings - remove the unreleased `r.rterm.preferredConsoles` setting and the previously deprecated, unused `r.helpPanel.rpath` setting - add host-independent regression coverage for precedence, PATH and registry discovery, substitutions, quoting, and workspace edge cases - resolve executable settings and `${workspaceFolder}` against the relevant workspace or document resource when one is available ## Why these names? The names follow the convention used by other VS Code language extensions: for example, Python uses `python.defaultInterpreterPath`, Julia uses `julia.executablePath`, and Ruby LSP uses `rubyLsp.rubyExecutablePath`. `executablePath` clearly identifies the vanilla executable used by the extension, while the parallel `consolePath` name preserves vscode-R's important distinction between background R and an alternative interactive console. We cannot use the shorter `r.rpath` and `r.rterm` while retaining their legacy platform-specific children: VS Code treats dotted configuration identifiers hierarchically, so scalar parent settings conflict with `r.rpath.windows`, `r.rterm.linux`, and the other existing keys. The `Path` suffix also makes clear that these settings select an executable location (including a name resolved from `PATH`), rather than configuring console behavior more broadly. ## Resolution rules Background/vanilla R resolves in this order: 1. `r.executablePath` 2. legacy `r.rpath.<current platform>` 3. `R` on `PATH` 4. Windows registry `InstallPath` (Windows only) The interactive console resolves in this order: 1. `r.consolePath` 2. legacy `r.rterm.<current platform>` 3. an explicitly configured `r.executablePath` 4. system R (`PATH`, then the Windows registry) The distinction between background R and the interactive console remains intentional: background processes never use `r.consolePath` or legacy `r.rterm.<platform>`. Also, a legacy `r.rpath.<platform>` override does not begin controlling the console; only the new canonical `r.executablePath` can provide that default. Both canonical settings use `machine-overridable` scope because executable locations are machine-dependent while workspace overrides remain useful. Relevant terminal, language-server, task, R Markdown, C++ properties, and command call sites now pass their workspace or document URI so folder-level settings and `${workspaceFolder}` substitution use the same resource. Empty values are treated as unset. Explicit but unavailable values fail instead of silently selecting a different executable. ## Historical compatibility The old settings were split by OS when defaults were hard-coded installation paths. The resolver keeps the later discovery behavior added for real-world installations: - `R` on `PATH` takes priority over the Windows registry (#244, #252, #649) - background commands use vanilla R, independently of alternative consoles (#607, #695 and commit `5e9c895`) - `${userHome}`, `${workspaceFolder}`, `${fileWorkspaceFolder}`, and `${fileDirname}` substitutions remain supported (#1398, #1444) - quoted paths and paths containing spaces remain supported (#884) - a bare name is looked up on `PATH`, never interpreted as a workspace-relative path (#1347, #1437) The platform-specific settings remain supported for backward compatibility but are deprecated in favor of the canonical settings and may be removed in a future release. ## Scope boundaries and deliberate follow-ups - `.github/ISSUE_TEMPLATE/bug_report.md` intentionally remains unchanged even though it contains legacy setting examples. The template needs a broader rewrite, which will be handled separately rather than partially updating it in this PR. - This PR makes executable configuration lookup resource-aware, but does not introduce a complete per-folder runtime lifecycle. In particular, it does not restart the help subsystem when the active folder changes or redesign single-/multi-server LSP lifecycle behavior.
This PR will close #1347
It adds a new option
r.rterm.preferredConsoleswhich defaults to ["R"]. You can specify you preferred R consoles like this:The extension will open the first item in that list that it finds on the users
PATH. However, ifr.rterm.linuxis specified, it will use that path (given that this is a more precise setting, I suggest we give precedence to it).Thank you so much for this project. I'm a daily user since many years.
Best,
BerriJ