Repository navigation
Programmatic way to run "Attach External R Session"? #1872
|
Previously, I used .vsc.attach() to connect the extension to a running session. I see there is now a way to do this that involves running a vsc command and pasting: https://github.com/REditorSupport/vscode-R/wiki/Interacting-with-R-terminals#using-self-managed-r-terminals I find the new way a bit cumbersome. Is there any way to do this programmatically directly from R? In particular, I use the R debugger extension and previously I could have those sessions automatically attach when they launch, but now it seems I'll have to manually run a key sequence each time I rerun my code and start the debugger. Is there any faster way? EDIT: workaroundI was able to get "Attach to Debugger" down to one shortcut using the Commands Extension. settings.json "commands.commands": {
"R Custom: Attach to debugger": {
"sequence": [
{ "command": "r.connectToSession" },
{ "command": "workbench.debug.action.focusRepl" },
{ "command": "editor.action.clipboardPasteAction" },
{ "command": "repl.action.acceptInput" }
]
}
}keybindings.json {
"key": "shift+cmd+a",
"command": "R Custom: Attach to debugger",
"when": "inDebugMode"
}Would still be nice to have a way to call this from R. |
Replies: 2 comments 2 replies
|
The R-side entry point is now Sys.getenv(c("SESS_ENDPOINT", "SESS_DISCOVERY_FILE"))
sess::connect()If both variables are empty, you need to pass the current window's endpoint explicitly. It doesn't discover an arbitrary VS Code window automatically. The copied |
|
Workaround: run f <- Sys.glob("~/Library/Application Support/Code/User/globalStorage/reditorsupport.r/tmp/attach/vscode-r-*.R")
if (length(f)) source(f[which.max(file.mtime(f))])Script path: Lines 1226 to 1229 in e2b28f1 |
Workaround: run
R: Attach External R Sessiononce per window. It writes an attach script that lives until your window closes or reloads. Source newest script from your debugged code, macOS path shown:Script path:
vscode-R/src/session.ts
Lines 1226 to 1229 in e2b28f1