Skip to content
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

Insert Roxygen Skeleton #405

Closed
assignUser opened this issue Aug 31, 2020 · 9 comments
Closed

Insert Roxygen Skeleton #405

assignUser opened this issue Aug 31, 2020 · 9 comments

Comments

@assignUser
Copy link
Contributor

In Rstudio you can insert a roxygen skeleton with the correct param tags via keybind (when the cursor is within a function definition) to create e.g. this:

#' Title
#'
#' @param x 
#'
#' @return
#' @export
#'
#' @examples
exported <- function(x) {
    x + 1
}

It would be a nice qol feature for package developers.
I might look into this but I have yet to make the first steps with vsc extension development/ts and wanted to put the idea out here :)

@andycraig
Copy link
Collaborator

Hi @assignUser, thank you for the suggestion. This seems like a good fit for a snippet. Users can add their own snippets. Also, snippets can be added to the extension without needing to write TypeScript.

Here is a guide on how to create them: https://code.visualstudio.com/docs/editor/userdefinedsnippets#_create-your-own-snippets

@assignUser
Copy link
Contributor Author

assignUser commented Aug 31, 2020

@andycraig Hey thanks for the quick reply. I will look into it but I am not sure that snippets are flexible enough to completely emulate the rstudio function which adds params depending on the function signature. But it is a good quick fix for now I guess 👍

@andycraig
Copy link
Collaborator

@assignUser Oh, I see what you mean. Yes, that would probably require some TypeScript rather than just a snippet.

If you decide you want to try implementing this, we can provide advice etc. as needed.

@renkun-ken
Copy link
Member

renkun-ken commented Aug 31, 2020

I guess this could be made much easier to implement if we define some customized requests in language server so that editor clients could query the information of the parsed data of the document at a document point (row, column). Otherwise, detecting the function arguments could be non-trivial in many cases when cursor is somewhere in the function, e.g., cursor at function formals vs. function body, complex function argument default value, cursor at closure in function, cursor at (raw?!) string literal in function.

Having access to the language client will make it much easier to implement customized language-related features such as this. Unfortunately, vscode-r-lsp and vscode-R are separate projects. I'm not sure if there's a way to access the language client created in vscode-r-lsp unless we merge the two projects (#98) previously done at https://github.com/renkun-ken/vscode-R/tree/lsp.

@MilesMcBain
Copy link
Collaborator

This would come very cheaply with #302. That way we could take advantage or R code that already exists to do this.

I know of code in {sinew} and {fnmate}, there's probably a few others.

@renkun-ken
Copy link
Member

@MilesMcBain I didn't know there's already RStudio plugins doing all these. Thanks for letting us know!

@MilesMcBain
Copy link
Collaborator

MilesMcBain commented Nov 2, 2020

Recently I've been using the RStudio addin in {docthis} for this purpose in VSCode and it works pretty well.

The differences to the built in RStudio behavior are the function object name needs to be selected, and the function needs to exist as an object in the session, e.g. having been placed there by devtools::load_all().

@andycraig
Copy link
Collaborator

It sounds like @MilesMcBain's approach of using the RStudio Addin {docthis} provides this functionality, so I'm going to close this issue as resolved. @assignUser If you feel like any essential functionality is still missing, please feel free to reply and we can re-open.

@assignUser
Copy link
Contributor Author

@andycraig the use of Rstudio Addins sounds like a good solution for now 👍 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants