You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
The R extension has keybindings for some key R functions like nrow, devtools::test() etc. It would be nice to be able to configure our own keybindings that run code in the active R terminal.
Describe the solution you'd like
A command added to the extension like this:
asyncfunctionrunCommandInRTerm({ text }: {text: string}){constcallableTerminal=awaitchooseTerminal();if(callableTerminal===undefined){return;}callableTerminal.sendText(text);}
Hi @MilesMcBain, there’s a function chooseTerminalAndSendText that does this, but at the moment it’s not exposed in the "commands" section of package.json so it can’t be directly accessed by the user.
I think the necessary change should be only a few lines, so I’ll try to do a PR tonight. (Or feel free to do one earlier if you’d like!)
I tried writing a function that was just a rename of chooseTerminalAndSendText but I ran into issues passing args to commands in keybindings.
See how my version takes { text }: { text: string }?. This was the only way I could get it to work. Otherwise it would silently fail before executing the command. I'm a total VSCode/Typescript noob though so I could easily believe I was missing something.
Activity
andycraig commentedon Jan 22, 2020
Hi @MilesMcBain, there’s a function
chooseTerminalAndSendTextthat does this, but at the moment it’s not exposed in the"commands"section ofpackage.jsonso it can’t be directly accessed by the user.I think the necessary change should be only a few lines, so I’ll try to do a PR tonight. (Or feel free to do one earlier if you’d like!)
MilesMcBain commentedon Jan 22, 2020
I tried writing a function that was just a rename of
chooseTerminalAndSendTextbut I ran into issues passingargsto commands in keybindings.See how my version takes
{ text }: { text: string }?. This was the only way I could get it to work. Otherwise it would silently fail before executing the command. I'm a total VSCode/Typescript noob though so I could easily believe I was missing something.andycraig commentedon Jan 22, 2020
Ah, you were ahead of me :) Let me have a look and see if I can figure out the
argsissue.andycraig commentedon Jan 23, 2020
It seems to work if
chooseTerminalAndSendTextis exposed inpackage.jsonprovided only the value ofargsis specified:I should be able to do a PR for this on Sunday, but feel free to do one in the meantime if you want.
MilesMcBain commentedon Jan 24, 2020
I'll have a go.
Another idea I had is a variant of this that take the current word or selection and sends it as an arg.
Would enable stuff like:
Thoughts on that one?
andycraig commentedon Jan 24, 2020
@MilesMcBain Great, thank you!
Definitely. I've split this off into its own issue.
You might also be interested in #183
andycraig commentedon Jan 26, 2020
@MilesMcBain At the risk of bikeshedding, I think I prefer the idea of the parameter being named, as in your original version.
I have a PR #203 for #183 that I’ll try to change to use named arguments too. I’ll sort that out and then let’s do this one.
renkun-ken commentedon Feb 22, 2020
Closed by #237.