From 58bb8ea01022cca279ec29ca44334bd53de1706b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ulysse=20G=C3=A9rard?= Date: Tue, 25 Feb 2025 14:11:59 +0100 Subject: [PATCH] Preserve flags ordering in Merlin configuration files. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes ocaml/merlin#1900 Signed-off-by: Ulysse GĂ©rard --- src/dune_rules/merlin/merlin.ml | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/dune_rules/merlin/merlin.ml b/src/dune_rules/merlin/merlin.ml index 2f0fb6fd314..e07474f01a5 100644 --- a/src/dune_rules/merlin/merlin.ml +++ b/src/dune_rules/merlin/merlin.ml @@ -214,26 +214,30 @@ module Processed = struct Path.Set.to_list_map hidden_src_dirs ~f:(make_directive_of_path "SH") in let flags = - let flags = - match flags with + (* Order matters here. The flags should be communicated to Merlin in the + same order that they are passed to the compiler: user flags, pp flags + and then opens *) + let open_flags = + match opens with | [] -> [] - | flags -> - [ make_directive "FLG" (Sexp.List (List.map ~f:(fun s -> Sexp.Atom s) flags)) ] + | opens -> + let open_flags = + Ocaml_flags.open_flags opens |> List.map ~f:(fun x -> Sexp.Atom x) + in + [ make_directive "FLG" (Sexp.List open_flags) ] in - let flags = + let other_flags = match pp with - | None -> flags + | None -> open_flags | Some { flag; args } -> make_directive "FLG" (Sexp.List [ Atom (Pp_kind.to_flag flag); Atom args ]) - :: flags + :: open_flags in - match opens with - | [] -> flags - | opens -> - make_directive - "FLG" - (Sexp.List (Ocaml_flags.open_flags opens |> List.map ~f:(fun x -> Sexp.Atom x))) - :: flags + match flags with + | [] -> other_flags + | flags -> + make_directive "FLG" (Sexp.List (List.map ~f:(fun s -> Sexp.Atom s) flags)) + :: other_flags in let unit_name = [ make_directive "UNIT_NAME" (Sexp.Atom unit_name) ] in let suffixes =