New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support RStudio plugins #302
Comments
Thanks for raising this. I thought about this too but didn't have time to investigate the underlying protocol between RStudio and the plugins. We may raise an issue at RStudio and hear from them about whether the protocol and rstudioapi could be used outside RStudio and let other editors leverage the same protocol? |
This sounds like a good idea to me. If you would like to raise the issue, please do. |
I had this idea myself today! I think something analogous to the So I don't know if collaborating with RStudio is absolutely necessary if that is the blocker. VSCode could provide adapter functions that mock the It could be done with the other init.R stuff by setting an onLoad hook for
or another option could be to create some kind of adapter users have to opt into by using it. e.g.
which could either run the function or return a modified version of it that can be assigned somewhere and referred to in keybindings etc. I think this kind of thing is fairly low risk for the types of functions @andycraig has highlighted. RStudio can't change them without affecting a great many addins in the wild that use them. |
Follow up on licensing issues: We would not be using the backend protocol that talks to RStudio. Depending on interpretation maybe we're modifying the It might be courteous to let them know the plan, but I don't think it we'd need their permission under the design I proposed. |
Hi @MilesMcBain, glad to hear you're interested in this too! I like your idea of reassigning Thank you also for pointing out that the license is MIT. I'd only seen the license file on GitHub, but on the CRAN page it does indeed show as MIT. I think you've resolved the aspects I was concerned about! |
Excellent! I am keen to see this happen, full The direction I am thinking would be dependent on some kind of response mechanism from VSCode to requests from the R session. We could try mirroring the request setup with a response lockfile and response body file. The simplest thing would be to block the R session until a response is received or timeout. But I am wondering if this was already on the cards and if anyone has done any thinking about it? |
I haven't really done any more thinking about it beyond my post creating this issue. If you might be interested in thinking about the details and writing some code to make this happen, that would of course be fantastic! I can help out as much/as little as required. There are a bunch of We've been discussing having R sessions start a server that would enable background communication with them that might be able to avoid blocking, but this hasn't progressed very far to my knowledge. Blocking the R session until a response is received or timeout sounds fine by me. There's code for the session watcher that could be used to watch for requests from the R session, in particular |
Okay I have the response protocol wired up and can get some document context from VSCode back to R. I'm attacking |
Can I ask a question regarding the request protocol? In the case of multiple VSCode instances running how is the communication with VSCode scoped? It seems that currently all communication between R and VSCode runs through the same request file @ Edit: Even though scoping does not seem to be happening, things seem to hold up under different tests, and the instance from which the request is made seems to be the one to get it, despite having verified all instances are writing requests to the same file. A bit spooky. Is this relying on processing preference to foregrounded instance? |
@MilesMcBain Currently, all requests are written to Currently, each vscode instance compares the vscode workspace folder with the working directory written in the request file and see if it should process the request. It does only if the working directory is the folder of subfolder of the vscode workspace root (see https://github.com/Ikuyadeu/vscode-R/blob/master/src/session.ts#L466). If vscode does not open a folder (thus has no workspace root), then it only process requests with working directory being home folder. |
Excellent, thanks for the answer. The synchronous response thing I've rigged up in my WIP should work without issue then. |
Good news! I have a proof of concept for Now might be a good time to check we're okay with the overall approach.
|
It might be easier to review what I've done if I make a PR? |
@MilesMcBain Nice work! Looks quite promising! The approach makes good sense to me.
Looks good to me. We could always improve the organization of code later.
Feel free to change the existing session watcher code to fit the purpose. I'd suggest that we could start from a simple structure and then see if we have to make it more complex to meet the demand.
Feel free to create a PR so that it is easier to know the progress and to discuss around the implementation. |
Cool the PR is made. I thought since it's obvious that this is being actively worked on now, it would be a good time to let authors of the I sent this email just now:
|
Here is the response:
|
This looks awesome! We're also adding a somewhat simpler selection-based API to the next version of RStudio. We don't have any official documentation yet, but the pull request is here: The ultimate idea is that rather than providing the user with the "richer" document context object (with document contents, selection coordinates, etc.) we'll just supply them the text contents of the current selection (assuming only a single cursor, single selection), and then ask the user to provide some transformation of that text to be used when replacing the selection. These APIs will be recommended in the future (where applicable) as they'll be compatible with RStudio's new visual mode editor (which is more like a cell-based WYSIWYG editor) as well as the regular source editor. We're also considering what other APIs we could form that would be compatible both in visual + source modes for RStudio; e.g. we're thinking about whether a chunk-based API (for mutating the contents within the current chunk, or all code chunks in a document, or similar) would be feasible. We'd definitely appreciate your feedback as well, and we'd like to tool this in a way that is easy for VSCode (or other tools) to hook or shim as needed. |
Thanks for your support @kevinushey! I have one question if you don't mind? Is |
Right, |
Great! I am thinking it's best for VSCode to avoid claiming to be a specific RStudio version if possible. So |
Added in #408 |
RStudio plugins communicate with RStudio via the
rstudioapi
package. It looks like this communicates with RStudio via a file-based communication protocol, similar to the session watcher. SeecallRemote
in https://github.com/rstudio/rstudioapi/blob/ac27784fda4ed5a8f7e8d0c8159f841aac22010b/R/remote.RIt seems like we could theoretically support RStudio plugins by running them in a separate R session and supporting the file-based communication protocol. We would have to implement in TypeScript the
rstudioapi
functions like:getActiveDocumentContext
insertText
setDocumentContext
An obstacle is that
rstudioapi
does some checking of RStudio versions etc. so vscode-R might have to identify itself as RStudio at a couple of points. That seems weird and might have side effects. There could even be some copyright/trademark issue, in which case we would DEFINITELY not want to implement this.Even if we cleared those obstacles, this would of course be a lot of work, and would place further demand on the system by adding another R session. So even if it's possible it's not necessary something we want.
The text was updated successfully, but these errors were encountered: