OCamlPro / ocp-indent

Indentation tool for OCaml, to be used from editors like Emacs and Vim.
http://www.typerex.org/ocp-indent.html
Other
200 stars 63 forks source link

Incorrect indentation of ppx #216

Closed rgrinberg closed 7 years ago

rgrinberg commented 8 years ago

Take the following snippet taken from ppx_deriving:

let core_type_of_decl ~options ~path type_decl =
  let typ = Ppx_deriving.core_type_of_type_decl type_decl in
  Ppx_deriving.poly_arrow_of_type_decl
    (fun var -> [%type: [%t var] -> [%t var] -> Ppx_deriving_runtime.bool])
    type_decl
    [%type: [%t typ] -> [%t typ] -> Ppx_deriving_runtime.bool]

ocp-indent indents it to be:


let core_type_of_decl ~options ~path type_decl =
  let typ = Ppx_deriving.core_type_of_type_decl type_decl in
  Ppx_deriving.poly_arrow_of_type_decl
    (fun var -> [%type: [%t var] -> [%t var] -> Ppx_deriving_runtime.bool])
type_decl
  [%type: [%t typ] -> [%t typ] -> Ppx_deriving_runtime.bool]

The expected result for me is that the original indentation is correct and should be preserved.

bmillwood commented 7 years ago

Looks superficially similar to a test case I have:

module A = struct
  let x = 1

  let%bench_fun "now" [@indexed i = List.range 0 (List.length zones)] =
    let time = now () in
    fun () -> of_time time ~zone

  let x = 2
end

which, under ocp-indent, becomes:

module A = struct
  let x = 1

  let%bench_fun "now" [@indexed i = List.range 0 (List.length zones)] =
let time = now () in
fun () -> of_time time ~zone

let x = 2
end
AltGr commented 7 years ago

Apparently the -> (in the first example) and = (in the second) make ocp-indent's stack pop out of the [% ] / [@ ] blocks. I'll check.