Open jmcphers opened 6 months ago
With https://github.com/posit-dev/amalthea/pull/329, we now have a mechanism for indentation rules. They currently only deal with some edge cases that the frontend doesn't handle well. If we implemented a complete set of rules, which should be 1 or 2 weeks of work, we could use this as a rudimentary formatter. The formatter wouldn't do any other whitespace formatting such as line splitting but it would be fast, work on invalid code, be consistent with the as-you-type indenter, and could be use for format-on-save and format-on-paste.
Until we have a more complete formatter the line-splitting aspects can be achieved manually with codegrip (it would be nice to reimplement it in Ark).
Feedback from a beta user who is frustrated with styler because we can't use it while R is busy doing something else (another drawback). https://github.com/posit-dev/positron-beta/discussions/226
Currently, we rely on
styler
to format R code. This has been a big time-saver when building out the initial implementation since code formatting is complicated and styler does a great job! However, this is not ideal in the long run for a number of reasons:styler
package has its own opinionated rules for formatting code that don't necessarily match the ones built into the R language pack. This means that as-you-type formatting may fight/disagree with format-on-save formatting.styler
while R is busy doing something else, since it needs R itself to run.styler
package has to fully parse the code to format it, so it cannot format any selections that aren't correct R code.