Skip to content

Commit

Permalink
Fix EXCLUDE_QUERY_DIR for cms/cmt files (#104)
Browse files Browse the repository at this point in the history
* Fix EXCLUDE_QUERY_DIR for cms/cmt files

* Modify test to use cmt and cms files

* Incorporate PR feedback

* Stop running test on windows

* Refactor to share functionality between build_path and cmt_path
  • Loading branch information
liam923 authored Oct 15, 2024
1 parent abb8560 commit 3b90a60
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 21 deletions.
33 changes: 13 additions & 20 deletions src/kernel/mconfig.ml
Original file line number Diff line number Diff line change
Expand Up @@ -983,14 +983,14 @@ let source_path config =
let hidden_source_path config =
config.merlin.hidden_source_path @ config.ocaml.hidden_dirs

let build_path config =
let collect_paths ~log_title ~config paths =
let dirs =
match config.ocaml.threads with
| `None -> config.ocaml.include_dirs
| `Threads -> "+threads" :: config.ocaml.include_dirs
| `Vmthreads -> "+vmthreads" :: config.ocaml.include_dirs
in
let dirs = config.merlin.cmi_path @ config.merlin.build_path @ dirs in
let dirs = paths @ dirs in
let stdlib = stdlib config in
let exp_dirs = List.map ~f:(Misc.expand_directory stdlib) dirs in
let stdlib = if config.ocaml.no_std_include then [] else [ stdlib ] in
Expand All @@ -999,29 +999,22 @@ let build_path config =
if config.merlin.exclude_query_dir then dirs
else config.query.directory :: dirs
in
let result' = List.filter_dup result in
log ~title:"build_path" "%d items in path, %d after deduplication"
(List.length result) (List.length result');
result'
let result = List.filter_dup result in
log ~title:log_title "%d items in path, %d after deduplication"
(List.length result) (List.length result);
result

let build_path config =
collect_paths ~log_title:"build_path" ~config
(config.merlin.cmi_path @ config.merlin.build_path)

let hidden_build_path config =
config.merlin.hidden_build_path @ config.ocaml.hidden_dirs

let cmt_path config =
let dirs =
match config.ocaml.threads with
| `None -> config.ocaml.include_dirs
| `Threads -> "+threads" :: config.ocaml.include_dirs
| `Vmthreads -> "+vmthreads" :: config.ocaml.include_dirs
in
let dirs =
config.merlin.cmt_path @ config.merlin.build_path
@ config.merlin.hidden_build_path @ dirs
in
let stdlib = stdlib config in
let exp_dirs = List.map ~f:(Misc.expand_directory stdlib) dirs in
let stdlib = if config.ocaml.no_std_include then [] else [ stdlib ] in
config.query.directory :: List.rev_append exp_dirs stdlib
collect_paths ~log_title:"cmt_path" ~config
(config.merlin.cmt_path @ config.merlin.build_path
@ config.merlin.hidden_build_path)

let global_modules ?(include_current = false) config =
let modules = Misc.modules_in_path ~ext:".cmi" (build_path config) in
Expand Down
2 changes: 1 addition & 1 deletion tests/test-dirs/config/dune
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(cram
(applies_to path-expansion hidden-deps)
(applies_to path-expansion hidden-deps exclude-query-dir)
(enabled_if
(<> %{os_type} Win32)))

Expand Down
63 changes: 63 additions & 0 deletions tests/test-dirs/config/exclude-query-dir.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
Test the EXCLUDE_QUERY_DIR directive, which tells Merlin not to look for build artifacts
in the directory of the file being queried on. To test, we create a/test.ml, which depends
on b/foo.ml. The folder b contains a .cmt for the Foo module, and Merlin is configured to
look there. We also include a malformatted foo.cmt in the query directory.
$ mkdir a
$ mkdir b

$ cat > a/test.ml << EOF
> let x = Foo.bar
> EOF

$ cat > b/foo.ml << EOF
> let bar = 10
> EOF

Create the proper and malformatted .cmt files
$ $OCAMLC -c -bin-annot b/foo.ml
$ touch a/foo.cmt

Configure Merlin
$ cat > a/.merlin << EOF
> S .
> B ../b
> S ../b
> EXCLUDE_QUERY_DIR
> EOF

Perform the query
$ $MERLIN single locate -position 1:13 -filename a/test.ml < a/test.ml
{
"class": "return",
"value": {
"file": "$TESTCASE_ROOT/b/foo.ml",
"pos": {
"line": 1,
"col": 4
}
},
"notifications": []
}

Jane Street Only: run the same test as above, but with .cms files instead of .cmt

Remove the old .cmt files
$ rm **/*.cmt

Create the .cms files
$ $OCAMLC -c -bin-annot-cms b/foo.ml
$ touch a/foo.cms

Perform the query again
$ $MERLIN single locate -position 1:13 -filename a/test.ml < a/test.ml
{
"class": "return",
"value": {
"file": "$TESTCASE_ROOT/b/foo.ml",
"pos": {
"line": 1,
"col": 4
}
},
"notifications": []
}

0 comments on commit 3b90a60

Please sign in to comment.