Closed jryans closed 1 year ago
@6cdh, @dannypsnl: My current approach here effectively reverts https://github.com/jeapostrophe/racket-langserver/pull/63 and https://github.com/jeapostrophe/racket-langserver/pull/92... Please take a look at this change. Is there a way we can adjust it to preserve the behaviour you were each trying to fix in those PRs?
I think the root of the issue is on-type-formatting
calls range-formatting
.
Based on my experience,
on-type-formatting
is called, the programmer is typing, and we expect it has indentation for an empty line.range-formatting
or formatting
is called, the programmer completed editing, and we expect it remove trailing whitespaces.These two cases are in conflict.
To solve this issue, we could have two versions of range-formatting
, one for editing mode and one for not.
Just check https://github.com/jeapostrophe/racket-langserver/blob/master/text-document.rkt#L582 said it reuse range-formatting!
, so just as @6cdh suggestion, you might like to write another implementation here
Ah okay, thanks for the suggestions! 🙂 I could potentially pass down a formatting type symbol (on-type, range, document) into range-formatting!
so we can tweak behaviour based on which one is being called.
I think I'll also investigate the details of how DrRacket and also other language extensions typically handle these different formatting types.
Okay, this now preserves the tweaks from #63 and #92 while still allowing empty line indentation while typing.
@6cdh and @dannypsnl, if you could take another look to see if I've missed anything, that would be great. (It might be easier to review commit by commit.)
All review comments have been addressed, please take another look. 😄
Thank you so much everyone!
Adding a new line at the end of the first line of an existing expression would force you back to the start of the line unexpectedly.
For example, with the following:
Previously the langserver left the new line unindented. This fixes the indentation path to instead indent the new line as expected.