Skip to content

Commit

Permalink
Do not always close stdout in [run_in_directory]
Browse files Browse the repository at this point in the history
This fixes the ppx test
  • Loading branch information
voodoos committed Jun 7, 2023
1 parent 8c23075 commit 04c864f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
6 changes: 3 additions & 3 deletions ocaml-lsp-server/src/ocaml_lsp_server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ let run_in_directory ~prog ~prog_is_quoted:_ ~args ~cwd ?stdin:_ ?stdout
let prog = "/bin/sh" in
let argv = [ "sh"; "-c"; cmd ] in
let stdin = Unix.openfile "/dev/null" [ Unix.O_RDONLY ] 0x777 in
let stdout =
let out =
match stdout with
| Some file -> Unix.openfile file [ Unix.O_WRONLY ] 0x664
| None ->
Expand All @@ -889,7 +889,7 @@ let run_in_directory ~prog ~prog_is_quoted:_ ~args ~cwd ?stdin:_ ?stdout
in
let pid =
let cwd : Spawn.Working_dir.t = Path cwd in
Spawn.spawn ~cwd ~prog ~argv ~stdin ~stdout ()
Spawn.spawn ~cwd ~prog ~argv ~stdin ~stdout:out ()
in
let _, status = Unix.waitpid [] pid in
let res =
Expand All @@ -899,7 +899,7 @@ let run_in_directory ~prog ~prog_is_quoted:_ ~args ~cwd ?stdin:_ ?stdout
| WSTOPPED _ -> -1
in
Unix.close stdin;
Unix.close stdout;
if Option.is_some stdout then Unix.close out;
`Finished res

let run_in_directory =
Expand Down
11 changes: 10 additions & 1 deletion ocaml-lsp-server/test/e2e-new/with_ppx.ml
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,14 @@ let%expect_test "with-ppx" =
print_endline !output;
[%expect {|
Received 0 diagnostics
no hover response|}]
{
"contents": {
"kind": "plaintext",
"value": "Expect_test_common.File.Location.t"
},
"range": {
"end": { "character": 8, "line": 97 },
"start": { "character": 2, "line": 86 }
}
}|}]

0 comments on commit 04c864f

Please sign in to comment.