fsharp / emacs-fsharp-mode

F# Emacs mode
Apache License 2.0
205 stars 62 forks source link

Error trying to indent when adding new line #336

Open rinfz opened 10 months ago

rinfz commented 10 months ago

Description

I receive the following error when hitting RET after an open bracket: fsharp--compute-indentation-open-bracket: End position is smaller than start position.

Repro steps

Given the code

let f () =
    Response.ofHtml(

Press RET so we can add the closing bracket on the following line. Cursor resets to col 0 on that line and the error is added to messages buffer.

Same behaviour when trying to build nested lists within ofHtml call:

let f () =
    Response.ofHtml(
        Templates.html5 "en" [

Press RET after [ will raise the error too.

Expected behavior

Cursor moves to next line with correct indentation applied: (+ (current-indentation) fsharp-indent-offset).

Actual behavior

Cursor moved to next line and no indentation is added. An error is raised.

Known workarounds

Comment out the call to (fsharp-goto-initial-line) at the end of fsharp--compute-indentation-open-bracket.

If you include that call, it will cause the cursor to move to col 0 on the Response.ofHtml( line and the cursor position will be before the bracket position causing an error. Without it, the cursor stays on the position of the bracket and can move to the next line correctly.