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

R code chunks in VS Code visual mode do not auto-indent #150

Open
JosiahParry opened this issue Apr 26, 2023 · 6 comments
Open

R code chunks in VS Code visual mode do not auto-indent #150

JosiahParry opened this issue Apr 26, 2023 · 6 comments

Comments

@JosiahParry
Copy link

  1. From command pallette create new quarto document
  2. save to random location (remember to delete it)
  3. Right click editor to activate visual editing (not available without saving for some reason)
  4. cmd + shift + i for new code chunk replace python with r
  5. Type rnorm(100) |> and press enter.

Following the pipe operator and a new line the new line should be indented. It is not in this case.

Quarto version 1.3.313

@jjallaire
Copy link
Contributor

The autoindenter used in visual mode is different than the one used in the main editor (it is based on the code mirror R mode) so we don't in fact catch all of these cases. We do plan to eventually replace the embedded editor, and when we do that this will be resolved.

@brianmsm
Copy link

brianmsm commented Aug 8, 2023

This is now also happening in Source Mode. It is difficult to use any code with pipe in quarto right now. I am not sure if it is related to disabling styler: #190

@jjallaire
Copy link
Contributor

This actually hasn't ever worked in source mode either. For source mode we delegate to the R extension, and it looks like they only support this behavior for .R scripts when you have formatOnType enabled: REditorSupport/vscode-R#321.

@brianmsm
Copy link

brianmsm commented Aug 8, 2023

You are right. For some reason I remembered that it did work on quarto files. formatOnType is formatting the indentation in both .R and .Rmd files. I understand that this request should be in the vscode repository, right?

@jjallaire
Copy link
Contributor

We are using the base R syntax rules from the vscode extension so if it could be updated to do this we'd get it for free (note however that in that thread there is some considerable discussion about doing this and I'm not sure if they've sorted out how yet)

@brianmsm
Copy link

brianmsm commented Aug 9, 2023

As I understand languageserver uses by default the formatting rules of the styler package to achieve what is indicated in formatOnType: https://github.com/REditorSupport/languageserver/blob/master/R/formatting.R . Strangely, if from the .qmd file you select the code block and indicate in "format selection" or "format document", this proceeds without problems despite this apparent restriction: https://github.com/REditorSupport/languageserver/blob/master/R/formatting.R#L44

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

No branches or pull requests

3 participants