Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consistent indentation of fun after let #323

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/indentBlock.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1177,7 +1177,7 @@ let rec update_path config block stream tok =
| KParen | KBegin | KBracket | KBrace | KBracketBar
| KWith(KMatch|KTry) | KBar(KMatch|KTry) | KArrow(KMatch|KTry)
| KFun
| KBody(KType|KExternal) | KColon
| KBody(KType|KExternal|KLet) | KColon
| KStruct | KSig | KObject
| KExtendedItem _ | KExtendedExpr _ -> true
| _ -> false)
Expand All @@ -1187,10 +1187,11 @@ let rec update_path config block stream tok =
| {kind=KFun} :: ({kind=KExpr i} as e) :: path when i = prio_flatop ->
(* eg '>>= fun x ->': indent like the top of the expression *)
{e with kind = KExpr 0} :: path
| {kind=KFun; line } :: {kind=KBody KLet; line=letline} :: _
| {kind=KFun; line } :: {kind=KBody(KLet|KLetIn); line=letline} :: _
when next_offset tok stream = None
&& line = current_line && line <> letline
->
(* Special indentation of [fun] inside a [let]. *)
append (KArrow KFun) L ~pad:0 (reset_line_indent config line path)
| {kind=KFun; line; _ } :: _
when next_offset tok stream = None
Expand Down
18 changes: 18 additions & 0 deletions tests/passing/js-let.ml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,21 @@ let parenthesized_let_tweak =
S.S.g s.S.s ~s
in
y)

let indentation_after_fun =
fun foo ->
bar

let indentation_after_fun =
let f =
fun foo ->
bar
in
()

(* Let is wrongly interpreted as LetIn *)
module M = struct
let indentation_after_fun =
fun foo ->
bar
end