positron
positron copied to clipboard
Reindenting lines only removes all indentation
Positron Version:
Positron Version: 2024.07.0 (Universal) build 15 Code - OSS Version: 1.90.0 Commit: d8da3ec9581aa7bcb9726babedacff4e3d528503 Date: 2024-07-05T03:51:32.592Z Electron: 29.4.0 Chromium: 122.0.6261.156 Node.js: 20.9.0 V8: 12.2.281.27-electron.0 OS: Darwin arm64 23.5.0
Steps to reproduce the issue:
- Enable RStudio keybindings
- Select R code that isn't consistently indented
- Type
cmd + ior use the "Reindent lines" command from the Command Palette - All line indentation is removed
Here's a quick video:
https://github.com/posit-dev/positron/assets/73663/f1b8a3a4-9fd6-44c8-be67-0279d23543ee
What did you expect to happen?
In RStudio, the same command results in code that is indented:
https://github.com/posit-dev/positron/assets/73663/149c35a9-6d85-430e-b591-e291f22b25d7
Were there any error messages in the output or Developer Tools console?
Nope.
Actually, it seems to do this just for pipes and ggplot +s. Arguments inside parentheses get aligned correctly:
https://github.com/posit-dev/positron/assets/73663/e8289776-064f-41d1-85cd-a43eca9baea4
This might be related to https://github.com/posit-dev/positron/issues/1316, though that was for indent-as-you-type indentation
This is related to #19 where we realized that the "reindent lines" command uses a whole separate code path. We will be solving this via a real formatter for R, rather than the rudimentary styler + indent-only formatter we have now.
Let's keep this issue open for the cases to check. 👍
With https://github.com/posit-dev/positron/pull/7199 we have removed the styler integration. Instead, we encourage users to install the Air extension, and soon (this milestone) Positron will also bundle the Air extension natively, so you won't even have to install it.
Air is an extremely fast R code formatter. When you hook it up to Format on Save with editor.formatOnSave: true, it completely replaces the need for Reindent Lines. Instead, you just save the file and all formatting and indentation is corrected for you.
In #19 we decided to close that issue because Air replaces the need for Reindent Lines with R code, and because the regex rules used to implement Reindent Lines are too limited to properly support pipe chains (it literally is just impossible). For the same reasons, I'm going to close this issue and encourage everyone to use Air instead.