Skip to content

Commit 9cbcb3c

Browse files
committed
Presence of .merlin.skip-if-not-cwd skips config in dir
Mitigation for #1869
1 parent 8404f96 commit 9cbcb3c

File tree

2 files changed

+30
-11
lines changed

2 files changed

+30
-11
lines changed

src/kernel/mconfig_dot.ml

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -403,26 +403,37 @@ let find_project_context start_dir =
403403
Sys.file_exists fname && not (Sys.is_directory fname)) fnames
404404
then Some dir else None
405405
in
406+
let cwd = Sys.getcwd () in
407+
let cwd = Misc.canonicalize_filename ~cwd cwd in
406408

407409
let rec loop workdir dir =
408410
try
409411
Some (
410412
List.find_map [
413+
".merlin.skip-if-not-cwd";
411414
".merlin"; "dune-project"; "dune-workspace"
412415
]
413416
~f:(fun f ->
414417
let fname = Filename.concat dir f in
415418
if Sys.file_exists fname && not (Sys.is_directory fname)
416-
then
417-
(* When starting [dot-merlin-reader] from [dir]
418-
the workdir is always [dir] *)
419-
let workdir = if f = ".merlin" then None else workdir in
420-
let workdir = Option.value ~default:dir workdir in
421-
Some ({
422-
workdir;
423-
process_dir = dir;
424-
configurator = Option.get (Configurator.of_string_opt f)
425-
}, fname)
419+
then (
420+
(* Special case:
421+
1. exists .merlin.skip-if-not-cwd
422+
2. not cwd (aka. `cwd <> dir`) *)
423+
if f = ".merlin.skip-if-not-cwd" then (
424+
if cwd <> Misc.canonicalize_filename ~cwd dir then
425+
raise Not_found
426+
else None)
427+
else
428+
(* When starting [dot-merlin-reader] from [dir]
429+
the workdir is always [dir] *)
430+
let workdir = if f = ".merlin" then None else workdir in
431+
let workdir = Option.value ~default:dir workdir in
432+
Some ({
433+
workdir;
434+
process_dir = dir;
435+
configurator = Option.get (Configurator.of_string_opt f)
436+
}, fname))
426437
else None
427438
)
428439
)

src/kernel/mconfig_dot.mli

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,13 @@ val find_project_context : string -> (context * string) option
5757
- dune-project
5858
- dune-workspace
5959
60-
They are detected in that order. [dune] and [jbuild] file do not need to be taken into account because any project using a recent version of dune should have a dune-project file which is even auto-generated when it is missing. And only recent versions of dune will stop writing .merlin files.
60+
They are detected in that order. [dune] and [jbuild] file do not need to
61+
be taken into account because any project using a recent version of dune
62+
should have a dune-project file which is even auto-generated when it is
63+
missing. And only recent versions of dune will stop writing .merlin files.
64+
65+
The presence of the file [".merlin.skip-if-not-cwd"] in a directory means
66+
that the three (3) project configuration files are {b not} checked if the
67+
directory containing [".merlin.skip-if-not-cwd"] is not the current
68+
working directory.
6169
*)

0 commit comments

Comments
 (0)