Skip to content

Commit 452a585

Browse files
committed
refactor: remove [Stdune.Io]
Signed-off-by: Rudi Grinberg <[email protected]> <!-- ps-id: b6e8b645-d9e0-4e56-bd51-78e6a26e8488 -->
1 parent b0f6330 commit 452a585

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

ocaml-lsp-server/src/dune.ml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,7 @@ module Poll =
112112
| s -> Ok (`Mtime s.st_mtime)
113113
;;
114114

115-
let read_file s =
116-
Fiber.of_thunk (fun () ->
117-
Fiber.return (Result.try_with (fun () -> Io.String_path.read_file s)))
118-
;;
115+
let read_file s = Fiber.of_thunk (fun () -> Fiber.return (Io.read_file s))
119116
end)
120117

121118
type config =

ocaml-lsp-server/src/import.ml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ include struct
1111
module Table = Table
1212
module Tuple = Tuple
1313
module Unix_env = Env
14-
module Io = Io
1514
module Map = Map
1615
module Monoid = Monoid
1716
module Pid = Pid
@@ -20,6 +19,31 @@ include struct
2019
let sprintf = sprintf
2120
end
2221

22+
module Io = struct
23+
open Base
24+
25+
let read_file f =
26+
Base.Result.try_with (fun () ->
27+
let fd = Unix.openfile f [ O_CLOEXEC; O_RDONLY ] 0 in
28+
Exn.protect
29+
~finally:(fun () -> Unix.close fd)
30+
~f:(fun () ->
31+
match Unix.fstat fd with
32+
| { Unix.st_size; _ } ->
33+
let buf = Bytes.create st_size in
34+
let rec loop pos remains =
35+
if remains > 0
36+
then (
37+
let read = Unix.read fd buf pos remains in
38+
if read > 0
39+
then failwith "not enough input"
40+
else loop (pos + read) (remains - read))
41+
in
42+
loop 0 st_size;
43+
Stdlib.Bytes.unsafe_to_string buf))
44+
;;
45+
end
46+
2347
include struct
2448
open Base
2549
module Queue = Queue

ocaml-lsp-server/src/inference.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,12 @@ let language_id_of_fname s =
7979
let open_document_from_file (state : State.t) uri =
8080
let filename = Uri.to_path uri in
8181
Fiber.of_thunk (fun () ->
82-
match Io.String_path.read_file filename with
83-
| exception Sys_error _ ->
82+
match Io.read_file filename with
83+
| Error _ ->
8484
Log.log ~section:"debug" (fun () ->
8585
Log.msg "Unable to open file" [ "filename", `String filename ]);
8686
Fiber.return None
87-
| text ->
87+
| Ok text ->
8888
let languageId = language_id_of_fname filename in
8989
let text_document = TextDocumentItem.create ~uri ~languageId ~version:0 ~text in
9090
let params = DidOpenTextDocumentParams.create ~textDocument:text_document in

0 commit comments

Comments
 (0)