vscode-R
vscode-R copied to clipboard
Reindent Lines commands don't work
Describe the bug
Commands Reindent Lines, Reindent Selected Lines do nothing.
To Reproduce
- Create a file
temp.Rwith the following content:for(i in 1:2) { print(i) } - Use command
Reindent Lines; nothing happens - Select all lines
- Use command
Reindent Selected Lines; nothing happens
Contrast with JavaScript:
- Create a file
temp.jswith the following content:for (let index = 0; index < array.length; index++) { const element = array[index]; } - Use command
Reindent Lines; middle line is indented as expected
EDIT: For Javascript, it also works if only lines 2-3 are selected and the Reindent Selected Lines command is used.
Notes
Not sure if this is a vscode-R bug or a VS Code bug, as there seem to be quite a few VS Code issues related to reindenting, e.g., https://github.com/microsoft/vscode/issues/19847
Might be because we have no indentation rules in r-configuration.json etc. https://code.visualstudio.com/api/language-extensions/language-configuration-guide#indentation-rules
I did some testing and I believe this is because we have no indentation rules. Indentation after (, { etc. while typing is provided by default, but not indentation when running Reindent Lines. Issue about this at VS Code: https://github.com/microsoft/vscode/issues/111088
If we did add indentation after pipes, we would run into an additional complication: It seems like VS Code would indent them differently as they were typed than it would indent them when running Reindent Lines. Issue about this at VS Code: https://github.com/microsoft/vscode/issues/111089
As discussed on Twitter, {styler} first needs to support reindention only, which is not the case with styler <= 1.3.2.9000. E.g. reindenting always also implies styling spaces. I opened https://github.com/r-lib/styler/issues/703 to track the status of this.
Thanks @lorenzwalthert. At present the VS Code command Reindent Lines uses a language's indentation rules, not the language server. So styler supporting reindentation only wouldn't help with Reindent Lines, although we could (for example) add our own R: Reindent Lines command. VS Code may add language server reindentation at some point: https://github.com/microsoft/vscode/issues/19847
Thanks @andycraig. Sorry, I did not read this thread properly and concluded from our Twitter discussion that styler was the bottleneck. If you want to use styler to build your own command for indenting lines, at least you now have the tools to do so. Doesn't look like there is much progress on the Microsoft language server side of this issue at the moment...
This issue is stale because it has been open for 365 days with no activity.
unstale
This issue is stale because it has been open for 365 days with no activity.