this repo has no description
at main 29 lines 1.1 kB view raw
1module Merlin_worker = Worker 2 3let respond m = Js_of_ocaml.Worker.post_message (X_protocol.resp_to_bytes m) 4 5let reformat ~id code = 6 let code' = 7 try Ocamlfmt.fmt code 8 with err -> 9 Brr.Console.error [ "OCamlformat error:"; Printexc.to_string err ]; 10 code 11 in 12 if code <> code' then respond (Formatted_source (id, code')); 13 code' 14 15let run () = 16 Js_of_ocaml.Worker.set_onmessage @@ fun marshaled_message -> 17 match X_protocol.req_of_bytes marshaled_message with 18 | Merlin (id, action) -> 19 respond (Merlin_response (id, Merlin_worker.on_message action)) 20 | Format_config conf -> Ocamlfmt.configure conf 21 | Format (id, code) -> ignore (reformat ~id code : string) 22 | Eval (id, line_number, code) -> 23 let code = reformat ~id code in 24 let output ~loc out = respond (Top_response_at (id, loc, out)) in 25 let result = Eval.execute ~output ~id ~line_number code in 26 respond (Top_response (id, result)) 27 | Setup -> Eval.setup_toplevel () 28 | Add_cmis cmis -> 29 ignore (Merlin_worker.on_message (Protocol.Add_cmis cmis) : Protocol.answer)