diff --git a/pkgs/development/ocaml-modules/ocaml-lsp/default.nix b/pkgs/development/ocaml-modules/ocaml-lsp/default.nix index 9e512e35f304..d9a21225cbb1 100644 --- a/pkgs/development/ocaml-modules/ocaml-lsp/default.nix +++ b/pkgs/development/ocaml-modules/ocaml-lsp/default.nix @@ -9,6 +9,7 @@ , dot-merlin-reader , spawn , ocamlc-loc +, merlin , merlin-lib , astring , camlp-streams @@ -25,6 +26,22 @@ let lsp_v = let lsp = lsp_v; in +# Use merlin < 4.17 for OCaml < 5.2 +let merlin-lib_v = + if lib.versions.majorMinor ocaml.version == "4.14" + then merlin-lib.override { + merlin = merlin.override { + version = "4.16-414"; + }; + } else if lib.versions.majorMinor ocaml.version == "5.1" + then merlin-lib.override { + merlin = merlin.override { + version = "4.16-501"; + }; + } else merlin-lib +; in +let merlin-lib = merlin-lib_v; in + buildDunePackage rec { pname = "ocaml-lsp-server"; inherit (lsp) version src preBuild; diff --git a/pkgs/development/tools/ocaml/merlin/4.x.nix b/pkgs/development/tools/ocaml/merlin/4.x.nix index f4c97b9642ec..b15668269494 100644 --- a/pkgs/development/tools/ocaml/merlin/4.x.nix +++ b/pkgs/development/tools/ocaml/merlin/4.x.nix @@ -1,7 +1,6 @@ { lib , substituteAll , fetchurl -, fetchpatch , ocaml , dune_3 , buildDunePackage @@ -13,23 +12,23 @@ , menhir , menhirLib , menhirSdk -}: - -let # Each releases of Merlin support a limited range of versions of OCaml. - merlinVersions = { +, version ? { "4.12.0" = "4.7-412"; "4.12.1" = "4.7-412"; "4.13.0" = "4.7-413"; "4.13.1" = "4.7-413"; - "4.14.0" = "4.16-414"; - "4.14.1" = "4.16-414"; - "4.14.2" = "4.16-414"; + "4.14.0" = "4.17.1-414"; + "4.14.1" = "4.17.1-414"; + "4.14.2" = "4.17.1-414"; "5.0.0" = "4.14-500"; - "5.1.0" = "4.16-501"; - "5.1.1" = "4.16-501"; - "5.2.0" = "5.1-502"; - }; + "5.1.0" = "4.17.1-501"; + "5.1.1" = "4.17.1-501"; + "5.2.0" = "5.2.1-502"; + }."${ocaml.version}" +}: + +let hashes = { "4.7-412" = "sha256-0U3Ia7EblKULNy8AuXFVKACZvGN0arYJv7BWiBRgT0Y="; @@ -37,17 +36,13 @@ let "4.14-500" = "sha256-7CPzJPh1UgzYiX8wPMbU5ZXz1wAJFNQQcp8WuGrR1w4="; "4.16-414" = "sha256-xekZdfPfVoSeGzBvNWwxcJorE519V2NLjSHkcyZvzy0="; "4.16-501" = "sha256-2lvzCbBAZFwpKuRXLMagpwDb0rz8mWrBPI5cODbCHiY="; - "5.1-502" = "sha256-T9gIvCaSnP/MqOoGNEeQFZwQ4+r5yRTPRu956Rf8rhU="; + "4.17.1-414" = "sha256-vz+AbvSGMgU4YdVLc73vlTm6QhivAh2LCsrY435kX8Y="; + "4.17.1-501" = "sha256-N2cHqocfCeljlFbT++S4miHJrXXHdOlMu75n+EKwpQA="; + "5.2.1-502" = "sha256-XALccbLTG2GYUcFKlluRxlCk281Jv1YATu5h4MWNWEw="; }; - version = lib.getAttr ocaml.version merlinVersions; - in -if !lib.hasAttr ocaml.version merlinVersions -then builtins.throw "merlin is not available for OCaml ${ocaml.version}" -else - buildDunePackage { pname = "merlin"; inherit version; @@ -58,23 +53,14 @@ buildDunePackage { }; patches = let - branch = lib.head (lib.tail (lib.splitString "-" version)); - needsVimPatch = lib.versionOlder version "4.17" || - branch == "502" && lib.versionOlder version "5.2"; + old-patch = lib.versionOlder version "4.17"; in [ (substituteAll { - src = ./fix-paths.patch; + src = if old-patch then ./fix-paths.patch else ./fix-paths2.patch; dot_merlin_reader = "${dot-merlin-reader}/bin/dot-merlin-reader"; dune = "${dune_3}/bin/dune"; }) - ] ++ lib.optionals needsVimPatch [ - # https://github.com/ocaml/merlin/pull/1798 - (fetchpatch { - name = "vim-python-12-syntax-warning-fix.patch"; - url = "https://github.com/ocaml/merlin/commit/9e0c47b0d5fd0c4edc37c4c7ce927b155877557d.patch"; - hash = "sha256-HmdTISE/s45C5cwLgsCHNUW6OAPSsvQ/GcJE6VDEobs="; - }) ]; strictDeps = true; diff --git a/pkgs/development/tools/ocaml/merlin/fix-paths2.patch b/pkgs/development/tools/ocaml/merlin/fix-paths2.patch new file mode 100644 index 000000000000..5bef154a1702 --- /dev/null +++ b/pkgs/development/tools/ocaml/merlin/fix-paths2.patch @@ -0,0 +1,17 @@ +diff --git a/src/kernel/mconfig_dot.ml b/src/kernel/mconfig_dot.ml +index 0a42a1d3..91997190 100644 +--- a/src/kernel/mconfig_dot.ml ++++ b/src/kernel/mconfig_dot.ml +@@ -146,10 +146,10 @@ end = struct + let prog, args = + match cfg with + | Dot_merlin -> +- let prog = "dot-merlin-reader" in ++ let prog = "@dot-merlin-reader@" in + (prog, [| prog |]) + | Dune -> +- let prog = "dune" in ++ let prog = "@dune@" in + (prog, [| prog; "ocaml-merlin"; "--no-print-directory" |]) + in + let cwd = Sys.getcwd () in