Skip to content

Commit

Permalink
[merlin] Also load configuration when sources are in build dir (ocaml…
Browse files Browse the repository at this point in the history
…#4274)

* Drop build context when present to handle files in `_build` dir
* Add test using `dune ocaml-merlin` for files in build dir

Signed-off-by: Ulysse Gérard <[email protected]>
  • Loading branch information
voodoos committed Feb 22, 2021
1 parent 526b9fb commit bca4d4b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
16 changes: 16 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,22 @@ Unreleased
- Have `dune` communicate the location of the standard library directory to
`merlin` (#4211, fixes #4188, @nojb)

- Add support for instrumentation dependencies (#4210, fixes #3983, @nojb)

- Workaround incorrect exception raised by `Unix.utimes` (OCaml PR#8857) in
`Path.touch` on Windows. This fixes dune cache in direct mode on Windows.
(#4223, @dra27)

- Cleanup temporary files after running `$ dune exec`. (#4260, fixes #4243,
@rgrinberg)

- Add a new subcommand `dune ocaml dump-dot-merlin` that prints a mix of all the
merlin configuration of a directory (defaulting to the current directory) in
the Merlin configuration syntax. (#4250, @voodoos)

- `dune ocaml-merlin` is now able to provide configuration for source files in
the `_build` directory. (#4274, @voodoos)

2.8.2 (21/01/2021)
------------------

Expand Down
10 changes: 8 additions & 2 deletions src/dune_rules/merlin_server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ let to_local file_path =
(* Then we make the path relative to [Path.root] (and not [Path.initial_cwd]) *)
match make_relative_to_root abs_file_path with
| Some path -> (
try Ok (Path.Local.of_string path)
try
let path = Path.of_string path in
(* If dune ocaml-merlin is called from within the build dir we must remove
the build context *)
Ok (Path.drop_optional_build_context path |> Path.local_part)
with User_error.E mess -> User_message.to_string mess |> error )
| None ->
Printf.sprintf "Path %S is not in dune workspace (%S)." file_path
Expand Down Expand Up @@ -112,7 +116,9 @@ let load_merlin_file local_path file =
Path.Local.parent path )
in
let default =
Printf.sprintf "No config found for file %S. Try calling `dune build`." file
Printf.sprintf
"No config found for file %S in %S. Try calling `dune build`." file
(Path.Local.to_string local_path)
|> Merlin_conf.make_error
in
Option.value (find_closest local_path) ~default
Expand Down
15 changes: 14 additions & 1 deletion test/blackbox-tests/test-cases/merlin/server.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
$ dune ocaml-merlin <<EOF
> (4:File${#FILE}:$FILE)
> EOF
((5:ERROR61:No config found for file "main.ml". Try calling `dune build`.))
((5:ERROR68:No config found for file "main.ml" in ".". Try calling `dune build`.))

$ dune build @check

Expand Down Expand Up @@ -41,3 +41,16 @@ Test of an valid invalid module name
> (4:File${#FILE}:$FILE)
> EOF
((?:STDLIB?:OPAM_PREFIX/lib/ocaml)(?:EXCLUDE_QUERY_DIR)(?:B?:$TESTCASE_ROOT/_build/default/.not-a-module-name.eobjs/byte)(?:S?:$TESTCASE_ROOT)(?:FLG(?:-w?:@1..3@5..28@30..39@43@46..47@49..57@61..62-?:-strict-sequence?:-strict-formats?:-short-paths?:-keep-locs?:-w?:-24)))

Dune should also provide configuration when the file is in the build folder
$ FILE=$PWD/_build/default/lib3.ml
$ dune ocaml-merlin <<EOF | sed -E "s/[[:digit:]]+:/\?:/g" | sed 's#'$(opam config var prefix)'#OPAM_PREFIX#'
> (4:File${#FILE}:$FILE)
> EOF
((?:STDLIB?:OPAM_PREFIX/lib/ocaml)(?:EXCLUDE_QUERY_DIR)(?:B?:$TESTCASE_ROOT/_build/default/.mylib.objs/byte)(?:B?:$TESTCASE_ROOT/_build/default/.mylib3.objs/byte)(?:S?:$TESTCASE_ROOT)(?:FLG(?:-open?:Mylib?:-w?:@1..3@5..28@30..39@43@46..47@49..57@61..62-?:-strict-sequence?:-strict-formats?:-short-paths?:-keep-locs)))

$ FILE=_build/default/lib3.ml
$ dune ocaml-merlin <<EOF | sed -E "s/[[:digit:]]+:/\?:/g" | sed 's#'$(opam config var prefix)'#OPAM_PREFIX#'
> (4:File${#FILE}:$FILE)
> EOF
((?:STDLIB?:OPAM_PREFIX/lib/ocaml)(?:EXCLUDE_QUERY_DIR)(?:B?:$TESTCASE_ROOT/_build/default/.mylib.objs/byte)(?:B?:$TESTCASE_ROOT/_build/default/.mylib3.objs/byte)(?:S?:$TESTCASE_ROOT)(?:FLG(?:-open?:Mylib?:-w?:@1..3@5..28@30..39@43@46..47@49..57@61..62-?:-strict-sequence?:-strict-formats?:-short-paths?:-keep-locs)))

0 comments on commit bca4d4b

Please sign in to comment.