Skip to content

Commit 8131c43

Browse files
authored
fix: use correct file permissions for preprocessing (#1153)
from jboillot/bugfix/ocamllsp-pp-output-file-creation
1 parent 1f78031 commit 8131c43

File tree

6 files changed

+106
-5
lines changed

6 files changed

+106
-5
lines changed

CHANGES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# Unreleased
2+
3+
## Fixes
4+
5+
- Fix file permissions used when specifying output files of pp and ppx. (#1153)
6+
17
# 1.16.1
28

39
## Fixes

ocaml-lsp-server/src/ocaml_lsp_server.ml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -878,20 +878,21 @@ let run_in_directory ~prog ~prog_is_quoted:_ ~args ~cwd ?stdin ?stdout ?stderr
878878
let argv = [ "sh"; "-c"; cmd ] in
879879
let stdin =
880880
match stdin with
881-
| Some file -> Unix.openfile file [ Unix.O_WRONLY ] 0x664
882-
| None -> Unix.openfile "/dev/null" [ Unix.O_RDONLY ] 0x777
881+
| Some file -> Unix.openfile file [ Unix.O_RDONLY ] 0o664
882+
| None -> Unix.openfile "/dev/null" [ Unix.O_RDONLY ] 0o777
883883
in
884884
let stdout, should_close_stdout =
885885
match stdout with
886-
| Some file -> (Unix.openfile file [ Unix.O_WRONLY ] 0x664, true)
886+
| Some file ->
887+
(Unix.openfile file [ Unix.O_WRONLY; Unix.O_CREAT ] 0o664, true)
887888
| None ->
888889
(* Runned programs should never output to stdout since it is the channel
889890
used by LSP to communicate with the editor *)
890891
(Unix.stderr, false)
891892
in
892893
let stderr =
893894
Option.map stderr ~f:(fun file ->
894-
Unix.openfile file [ Unix.O_WRONLY ] 0x664)
895+
Unix.openfile file [ Unix.O_WRONLY; Unix.O_CREAT ] 0o664)
895896
in
896897
let pid =
897898
let cwd : Spawn.Working_dir.t = Path cwd in

ocaml-lsp-server/test/e2e-new/dune

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
(deps
1313
%{bin:ocamlformat-rpc}
1414
for_ppx.ml
15+
for_pp.ml
1516
(package ocaml-lsp-server)))
1617
(libraries
1718
stdune
@@ -32,4 +33,23 @@
3233
ppx_expect.config_types
3334
ppx_inline_test.config)
3435
(preprocess
35-
(pps ppx_expect)))
36+
(per_module
37+
((action
38+
(run %{dep:for_pp.sh} %{input-file}))
39+
for_pp)
40+
((pps ppx_expect)
41+
action_extract
42+
action_inline
43+
code_actions
44+
document_flow
45+
for_ppx
46+
hover_extended
47+
metrics
48+
semantic_hl_data
49+
semantic_hl_helpers
50+
semantic_hl_tests
51+
start_stop
52+
test
53+
with_pp
54+
with_ppx
55+
workspace_change_config))))
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
type world
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/sh
2+
sed 's/world/universe/g' $1
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
open! Test.Import
2+
3+
let path = Filename.concat (Sys.getcwd ()) "for_pp.ml"
4+
5+
let uri = DocumentUri.of_path path
6+
7+
let print_hover hover =
8+
match hover with
9+
| None -> print_endline "no hover response"
10+
| Some hover ->
11+
hover |> Hover.yojson_of_t
12+
|> Yojson.Safe.pretty_to_string ~std:false
13+
|> print_endline
14+
15+
let hover_req client position =
16+
Client.request
17+
client
18+
(TextDocumentHover
19+
{ HoverParams.position
20+
; textDocument = TextDocumentIdentifier.create ~uri
21+
; workDoneToken = None
22+
})
23+
24+
let%expect_test "with-pp" =
25+
let position = Position.create ~line:0 ~character:9 in
26+
let handler =
27+
Client.Handler.make
28+
~on_notification:(fun client _notification ->
29+
Client.state client;
30+
Fiber.return ())
31+
()
32+
in
33+
let output =
34+
Test.run ~handler @@ fun client ->
35+
let run_client () =
36+
let capabilities = ClientCapabilities.create () in
37+
Client.start client (InitializeParams.create ~capabilities ())
38+
in
39+
let run () =
40+
let* (_ : InitializeResult.t) = Client.initialized client in
41+
let textDocument =
42+
let text = Io.String_path.read_file path in
43+
TextDocumentItem.create ~uri ~languageId:"ocaml" ~version:0 ~text
44+
in
45+
let* () =
46+
Client.notification
47+
client
48+
(TextDocumentDidOpen (DidOpenTextDocumentParams.create ~textDocument))
49+
in
50+
let* () =
51+
let+ resp = hover_req client position in
52+
print_hover resp
53+
in
54+
let output = [%expect.output] in
55+
let* () = Client.request client Shutdown in
56+
let+ () = Client.stop client in
57+
output
58+
in
59+
Fiber.fork_and_join_unit run_client run
60+
in
61+
let (_ : string) = [%expect.output] in
62+
print_endline output;
63+
[%expect
64+
{|
65+
{
66+
"contents": { "kind": "plaintext", "value": "type universe" },
67+
"range": {
68+
"end": { "character": 13, "line": 0 },
69+
"start": { "character": 0, "line": 0 }
70+
}
71+
}|}]

0 commit comments

Comments
 (0)