roc-lang / roc

A fast, friendly, functional language.
https://roc-lang.org
Universal Permissive License v1.0
4.47k stars 314 forks source link

"code |> comment |> format |> uncomment" workflow has some friction #7219

Open joshuawarner32 opened 1 week ago

joshuawarner32 commented 1 week ago

I have the following code:

expect
    # Test single space
    when parseStr pWhitespace " " is
        Ok _ -> Bool.true
        Err _ -> Bool.false

expect
    # Test multiple spaces
    when parseStr pWhitespace "     " is
        Ok _ -> Bool.true
        Err _ -> Bool.false

I'm trying to see if that's what's causing a compiler crash, so I comment it out (Cmd+/), then save (Cmd+S).

This triggers the auto-format via the Roc language plugin (in Zed), which formats it to this:

# expect
#    # Test single space
#    when parseStr pWhitespace " " is
#        Ok _ -> Bool.true
#        Err _ -> Bool.false

# expect
#    # Test multiple spaces
#    when parseStr pWhitespace "     " is
#        Ok _ -> Bool.true
#        Err _ -> Bool.false

(notice it's inserted space in front of each expect!)

Then, I determine that's not the code at fault, so I uncomment, which doesn't remove the leading space in front of each expect.

This predictably leads to a variety of parsing errors due to invalid indentation, which I need to manually fix up by removing spaces.

It's not obvious to me which part of this process is at fault; they all seem to be doing their jobs. Just the aggregate result is a bit unfortunate.

joshuawarner32 commented 1 week ago

🤔 Actually, if the Cmd+/ inserts not just "#" but "# ", and uncommenting removes up to one leading space, that would fix things.