diff --git a/src/context.ml b/src/context.ml index 677c3685..2d07634a 100644 --- a/src/context.ml +++ b/src/context.ml @@ -454,7 +454,8 @@ let create_for_opam ?root ~env ~targets ~profile ~switch ~name let create ?merlin ~env def = match (def : Workspace.Context.t) with | Default { targets; profile; _ } -> default ~env ~profile ~targets ?merlin () - | Opam { name; switch; root; targets; profile; _ } -> + | Opam { base = { targets ; profile ; loc = _ } + ; name; switch; root; merlin = _ } -> create_for_opam ?root ~env ~profile ~switch ~name ?merlin ~targets () let which t s = which ~cache:t.which_cache ~path:t.path s diff --git a/src/workspace.ml b/src/workspace.ml index 65999fa1..4a4c296d 100644 --- a/src/workspace.ml +++ b/src/workspace.ml @@ -40,60 +40,63 @@ module Context = struct name) end - module Opam = struct - type t = - { loc : Loc.t - ; name : string - ; profile : string - ; switch : string - ; root : string option - ; merlin : bool - ; targets : Target.t list - } - - let t ~profile ~x = - field "switch" string >>= fun switch -> - field "name" Name.t ~default:switch >>= fun name -> - field "targets" (list Target.t) ~default:[Target.Native] >>= fun targets -> - field_o "root" string >>= fun root -> - field_b "merlin" >>= fun merlin -> - field "profile" string ~default:profile >>= fun profile -> - loc >>= fun loc -> - return { loc - ; switch - ; name - ; root - ; merlin - ; targets = Target.add targets x - ; profile - } - end - - module Default = struct + module Base = struct type t = { loc : Loc.t ; profile : string ; targets : Target.t list } - let t ~profile ~x = + let t ~profile = field "targets" (list Target.t) ~default:[Target.Native] >>= fun targets -> field "profile" string ~default:profile >>= fun profile -> - loc - >>= fun loc -> - return { loc - ; targets = Target.add targets x - ; profile + loc >>= fun loc -> + return + { targets + ; profile + ; loc + } + end + + module Opam = struct + type t = + { base : Base.t + ; name : string + ; switch : string + ; root : string option + ; merlin : bool + } + + let t ~profile ~x = + Base.t ~profile >>= fun base -> + field "switch" string >>= fun switch -> + field "name" Name.t ~default:switch >>= fun name -> + field_o "root" string >>= fun root -> + field_b "merlin" >>= fun merlin -> + let base = { base with targets = Target.add base.targets x } in + return { base + ; switch + ; name + ; root + ; merlin } end + module Default = struct + type t = Base.t + + let t ~profile ~x = + Base.t ~profile >>= fun t -> + return { t with targets = Target.add t.targets x } + end + type t = Default of Default.t | Opam of Opam.t let loc = function | Default x -> x.loc - | Opam x -> x.loc + | Opam x -> x.base.loc let t ~profile ~x = sum @@ -121,7 +124,7 @@ module Context = struct let targets = function | Default x -> x.targets - | Opam x -> x.targets + | Opam x -> x.base.targets let all_names t = let n = name t in diff --git a/src/workspace.mli b/src/workspace.mli index 19c04bdc..a73e7c6c 100644 --- a/src/workspace.mli +++ b/src/workspace.mli @@ -8,24 +8,25 @@ module Context : sig | Native | Named of string end - module Opam : sig + module Base : sig type t = { loc : Loc.t - ; name : string ; profile : string + ; targets : Target.t list + } + end + module Opam : sig + type t = + { base : Base.t + ; name : string ; switch : string ; root : string option ; merlin : bool - ; targets : Target.t list } end module Default : sig - type t = - { loc : Loc.t - ; profile : string - ; targets : Target.t list - } + type t = Base.t end type t = Default of Default.t | Opam of Opam.t