File tree Expand file tree Collapse file tree 3 files changed +29
-8
lines changed Expand file tree Collapse file tree 3 files changed +29
-8
lines changed Original file line number Diff line number Diff 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
121118type config =
Original file line number Diff line number Diff line change @@ -9,7 +9,6 @@ include struct
99 module Table = Table
1010 module Tuple = Tuple
1111 module Unix_env = Env
12- module Io = Io
1312 module Map = Map
1413 module Monoid = Monoid
1514 module Pid = Pid
@@ -18,6 +17,31 @@ include struct
1817 let sprintf = sprintf
1918end
2019
20+ module Io = struct
21+ open Base
22+
23+ let read_file f =
24+ Base.Result. try_with (fun () ->
25+ let fd = Unix. openfile f [ O_CLOEXEC ; O_RDONLY ] 0 in
26+ Exn. protect
27+ ~finally: (fun () -> Unix. close fd)
28+ ~f: (fun () ->
29+ match Unix. fstat fd with
30+ | { Unix. st_size; _ } ->
31+ let buf = Bytes. create st_size in
32+ let rec loop pos remains =
33+ if remains > 0
34+ then (
35+ let read = Unix. read fd buf pos remains in
36+ if read = 0
37+ then failwith (sprintf " unable to read all of %s" f)
38+ else loop (pos + read) (remains - read))
39+ in
40+ loop 0 st_size;
41+ Stdlib.Bytes. unsafe_to_string buf))
42+ ;;
43+ end
44+
2145include struct
2246 open Base
2347 module Queue = Queue
Original file line number Diff line number Diff line change @@ -79,12 +79,12 @@ let language_id_of_fname s =
7979let 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 ~language Id ~version: 0 ~text in
9090 let params = DidOpenTextDocumentParams. create ~text Document:text_document in
You can’t perform that action at this time.
0 commit comments