Skip to content

Commit 9255d4a

Browse files
committed
fix(ocamllsp): use Spawn to launch ppx
Signed-off-by: Rudi Grinberg <[email protected]> ps-id: 3a6f3b4e-0d69-4730-aaa1-c301cae5e9c3
1 parent 1709fc1 commit 9255d4a

File tree

2 files changed

+14
-2
lines changed
  • ocaml-lsp-server/vendor/merlin/src

2 files changed

+14
-2
lines changed

ocaml-lsp-server/vendor/merlin/src/kernel/dune

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
-open Merlin_specific
1515
-open Merlin_extend)
1616
(libraries merlin_config os_ipc ocaml_parsing ocaml_preprocess ocaml_typing ocaml_utils
17-
merlin_extend merlin_specific merlin_utils merlin_dot_protocol))
17+
merlin_extend merlin_specific merlin_utils merlin_dot_protocol spawn))
1818

1919
(rule
2020
(targets standard_library.ml)

ocaml-lsp-server/vendor/merlin/src/ocaml/driver/pparse.ml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,19 @@ let merlin_system_command =
4646
windows_merlin_system_command
4747
else
4848
fun cmd ~cwd ->
49-
Sys.command (Printf.sprintf "cd %s && %s" (Filename.quote cwd) cmd)
49+
let prog = "/bin/bash" in
50+
let argv = ["sh"; "-c"; cmd] in
51+
let stdin = Unix.openfile "/dev/null" [ Unix.O_RDONLY ] 0x777 in
52+
let pid = Spawn.spawn ~prog ~argv ~stdin ~stdout:Unix.stderr ~stderr:Unix.stderr () in
53+
let (_, status) = Unix.waitpid [] pid in
54+
let res =
55+
match (status : Unix.process_status) with
56+
| WEXITED n -> n
57+
| WSIGNALED _ -> -1
58+
| WSTOPPED _ -> -1
59+
in
60+
Unix.close stdin;
61+
res
5062

5163
let ppx_commandline cmd fn_in fn_out =
5264
Printf.sprintf "%s %s %s%s"

0 commit comments

Comments
 (0)