jeapostrophe / racket-langserver

Other
262 stars 24 forks source link

Fix indentation after new line at first line of expression #100

Closed jryans closed 1 year ago

jryans commented 1 year ago

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:

(define (bob); <- place cursor here, then press Return
  (+ 1 2))

Previously the langserver left the new line unindented. This fixes the indentation path to instead indent the new line as expected.

jryans commented 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?

6cdh commented 1 year ago

I think the root of the issue is on-type-formatting calls range-formatting.

Based on my experience,

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.

dannypsnl commented 1 year ago

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

jryans commented 1 year ago

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.

jryans commented 1 year ago

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.)

jryans commented 1 year ago

All review comments have been addressed, please take another look. 😄

jeapostrophe commented 1 year ago

Thank you so much everyone!