BetterThanTomorrow / calva

Clojure & ClojureScript Interactive Programming for VS Code
https://marketplace.visualstudio.com/items?itemName=betterthantomorrow.calva
Other
1.67k stars 217 forks source link

Barfed sexp at the top level does not auto-indent #982

Open plexus opened 3 years ago

plexus commented 3 years ago

settings.json

{"editor.autoIndent": "full"}

Given this form with | indicating the cursor

(foo|
 (bar))

When invoking Calva Paredit: Bard Sexp Forward, you get this

(foo)|
 (bar)

Expected:

(foo)|
(bar)
PEZ commented 3 years ago

Thanks. This reminds me that we should probably try to document how the editor.autoIndent setting plays together with Calva.

To clarify the nature of this bug I'd like to note that this is only happens at the top level. (I know it says so in the title, but anyway.)

So:

(foo
 (bar|)
 (baz))

Slurp forward! =>

(foo
 (bar|
  (baz)))

Barf forward! =>

(foo
 (bar|)
 (baz))

as expected.

The current mechanism for selecting what should be formatted does not lean itself super well to this problem. Let me try to explain how it works (for anyone that picks this up and want to try to fix it):

When we reach the top level things break down a bit. Formatting that whole level is quite dramatic for many files, so I didn't want to do that. And I couldn't then (when implementing the post-edit formatting) find a clean way to determine how much should actually get formatted. It could be argued that I shouldn't label this issue as a bug, since it is rather a multi-headed trade-off, but also it is inconsistent how it behaves....

plexus commented 3 years ago

Thanks for explaining! Is there a way to tell it to format more than one form at the same level, rather than having to go a level up?

PEZ commented 3 years ago

We can use paredit or the token cursor it uses to select what should be formatted.

PEZ commented 3 years ago

I've created a bit of a monster here, so the trickier part is to manage to inject new selection strategy without making it all completely incomprehensible.

The selection will have two parts to it, I think:

  1. Figuring out what to select.
  2. Selecting it.

In both cases we need to take that first thing into account. 😀