Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix EXCLUDE_QUERY_DIR for cms/cmt files #104

Merged
merged 5 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/kernel/mconfig.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,9 @@ let cmt_path config =
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
let result' = List.rev_append exp_dirs stdlib in
liam923 marked this conversation as resolved.
Show resolved Hide resolved
if config.merlin.exclude_query_dir then result'
else config.query.directory :: result'

let global_modules ?(include_current = false) config =
let modules = Misc.modules_in_path ~ext:".cmi" (build_path config) in
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 b/foo.ml
liam923 marked this conversation as resolved.
Show resolved Hide resolved
$ touch a/foo.cmt

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": []
}
Loading