Commit 8461bc3 1 parent 60bf40a commit 8461bc3 Copy full SHA for 8461bc3
File tree 3 files changed +29
-8
lines changed
3 files changed +29
-8
lines changed Original file line number Diff line number Diff line change @@ -112,10 +112,7 @@ module Poll =
112
112
| s -> Ok (`Mtime s.st_mtime)
113
113
;;
114
114
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))
119
116
end )
120
117
121
118
type config =
Original file line number Diff line number Diff line change @@ -10,7 +10,6 @@ include struct
10
10
module Table = Table
11
11
module Tuple = Tuple
12
12
module Unix_env = Env
13
- module Io = Io
14
13
module Map = Map
15
14
module Monoid = Monoid
16
15
module Pid = Pid
@@ -19,6 +18,31 @@ include struct
19
18
let sprintf = sprintf
20
19
end
21
20
21
+ module Io = struct
22
+ open Base
23
+
24
+ let read_file f =
25
+ Base.Result. try_with (fun () ->
26
+ let fd = Unix. openfile f [ O_CLOEXEC ; O_RDONLY ] 0 in
27
+ Exn. protect
28
+ ~finally: (fun () -> Unix. close fd)
29
+ ~f: (fun () ->
30
+ match Unix. fstat fd with
31
+ | { Unix. st_size; _ } ->
32
+ let buf = Bytes. create st_size in
33
+ let rec loop pos remains =
34
+ if remains > 0
35
+ then (
36
+ let read = Unix. read fd buf pos remains in
37
+ if read = 0
38
+ then failwith (sprintf " unable to read all of %s" f)
39
+ else loop (pos + read) (remains - read))
40
+ in
41
+ loop 0 st_size;
42
+ Stdlib.Bytes. unsafe_to_string buf))
43
+ ;;
44
+ end
45
+
22
46
include struct
23
47
open Base
24
48
module Queue = Queue
Original file line number Diff line number Diff line change @@ -79,12 +79,12 @@ let language_id_of_fname s =
79
79
let open_document_from_file (state : State.t ) uri =
80
80
let filename = Uri. to_path uri in
81
81
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 _ ->
84
84
Log. log ~section: " debug" (fun () ->
85
85
Log. msg " Unable to open file" [ " filename" , `String filename ]);
86
86
Fiber. return None
87
- | text ->
87
+ | Ok text ->
88
88
let languageId = language_id_of_fname filename in
89
89
let text_document = TextDocumentItem. create ~uri ~language Id ~version: 0 ~text in
90
90
let params = DidOpenTextDocumentParams. create ~text Document:text_document in
You can’t perform that action at this time.
0 commit comments