this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix worker initialization. The first request must be the one loading Cmis.

+51 -16
+5 -2
src/client/merlin_client.ml
··· 79 79 80 80 let make_worker url = 81 81 let worker = make_worker @@ Webworker.create @@ Jstr.of_string url in 82 + let ready, set_ready = Fut.create () in 82 83 let on_message m = 83 84 let m = Brr.Ev.as_type m in 84 85 let data_marshaled = Brr_io.Message.Ev.data m |> Js_of_ocaml.Js.to_bytestring in 85 86 let data : Protocol.answer = Marshal.from_string data_marshaled 0 in 86 - on_message worker data 87 + match data with 88 + | Protocol.Ready -> set_ready () 89 + | _ -> on_message worker data 87 90 in 88 91 let _listen = 89 92 Brr.Ev.listen Brr_io.Message.Ev.message on_message 90 93 @@ Webworker.as_target worker.worker 91 94 in 92 - worker 95 + worker, ready
+10 -2
src/extension/merlin_codemirror.ml
··· 14 14 let linter worker = fun view -> 15 15 let open Fut.Syntax in 16 16 let doc = Utils.get_full_doc @@ Editor.View.state view in 17 + let* worker = worker in 17 18 let+ result = Merlin_client.query_errors worker doc in 18 19 List.map (fun Protocol.{ kind; loc; main; sub = _; source } -> 19 20 let from = loc.loc_start.pos_cnum in ··· 47 48 let source = Utils.get_full_doc @@ Autocomplete.Context.state ctx in 48 49 let pos = Autocomplete.Context.pos ctx in 49 50 let+ { from; to_; entries } = 51 + let* worker = worker in 50 52 Merlin_client.query_completions worker source (`Offset pos) 51 53 in 52 54 let options = ··· 72 74 let open Fut.Syntax in 73 75 let doc = Utils.get_full_doc @@ Editor.View.state view in 74 76 let pos = `Offset pos in 77 + let* worker = worker in 75 78 let+ result = Merlin_client.query_type worker doc pos in 76 79 match result with 77 80 | (loc, `String type_, _)::_ -> ··· 100 103 101 104 module Make (Config : Config) = struct 102 105 let worker = 103 - let worker = Merlin_client.make_worker Config.worker_url in 104 - let _ = Merlin_client.add_cmis worker Config.cmis in 106 + let open Fut.Syntax in 107 + let worker, ready = Merlin_client.make_worker Config.worker_url in 108 + let* () = ready in 109 + (* Initial Cmi loading should be the first request. Todo: make it clearer in 110 + the protocol that this is a mandatory initial exchange: Start worker -> 111 + worker sends Ready -> client sends Add_cmis *) 112 + let+ () = Merlin_client.add_cmis worker Config.cmis in 105 113 worker 106 114 107 115 open Extensions (Merlin_client.Webworker)
+4 -4
src/extension/merlin_codemirror.mli
··· 37 37 38 38 type worker = Merlin_client.Make(Worker).worker 39 39 40 - val autocomplete : worker -> Code_mirror.Extension.t 40 + val autocomplete : worker Fut.t -> Code_mirror.Extension.t 41 41 (** An extension providing completions when typing *) 42 42 43 - val tooltip_on_hover : worker -> Code_mirror.Extension.t 43 + val tooltip_on_hover : worker Fut.t -> Code_mirror.Extension.t 44 44 (** An extension providing type-information when hovering code *) 45 45 46 - val linter : worker -> Code_mirror.Extension.t 46 + val linter : worker Fut.t -> Code_mirror.Extension.t 47 47 (** An extension that highlights errors and warnings in the code *) 48 48 49 - val all_extensions : worker -> Code_mirror.Extension.t array 49 + val all_extensions : worker Fut.t -> Code_mirror.Extension.t array 50 50 (** All the Merlin-specific extensions (does not include [ocaml]) *) 51 51 52 52 end
+14
src/protocol/protocol.ml
··· 46 46 | All_errors of source 47 47 | Add_cmis of cmis 48 48 49 + let action_to_string = function 50 + | Complete_prefix _ -> "Complete_prefix" 51 + | Type_enclosing _ -> "Type_enclosing" 52 + | All_errors _ -> "All_errors" 53 + | Add_cmis _ -> "Add_cmis" 54 + 49 55 type error = { 50 56 kind : Location.report_kind; 51 57 loc: Location.t; ··· 65 71 66 72 (* type errors = { from: int; to_: int; entries: error list } *) 67 73 type answer = 74 + | Ready 68 75 | Errors of error list 69 76 | Completions of completions 70 77 | Typed_enclosings of 71 78 (Location.t * [ `Index of int | `String of string ] * is_tail_position) list 72 79 | Added_cmis 80 + 81 + let answer_to_string = function 82 + | Ready -> "Ready" 83 + | Errors _ -> "Errors" 84 + | Completions _ -> "Completions" 85 + | Typed_enclosings _ -> "Type_enclosings" 86 + | Added_cmis -> "Added_cmis" 73 87 74 88 let report_source_to_string = function 75 89 | Location.Lexer -> "lexer"
+18 -8
src/worker/worker.ml
··· 5 5 module Location = Ocaml_parsing.Location 6 6 7 7 let stdlib_path = "/static/cmis" 8 + let log s = Console.console##log (Js.string s) 8 9 9 10 let sync_get url = 10 11 let x = XmlHttpRequest.create () in ··· 251 252 | Add_cmis cmis -> 252 253 add_cmis cmis 253 254 255 + let post res = 256 + Marshal.to_string res [] 257 + |> Js.bytestring 258 + |> Worker.post_message 259 + 254 260 let run () = 255 261 Console.console##log (Js.string "Worker running"); 256 - Worker.set_onmessage @@ fun marshaled_message -> 257 - Console.console##log (Js.string "Received message"); 258 - let action : Protocol.action = 259 - let str = Js.to_bytestring marshaled_message in 260 - Marshal.from_string str 0 in 261 - let res = on_message action in 262 - let res = Marshal.to_string res [] |> Js.bytestring in 263 - Worker.post_message res 262 + Worker.set_onmessage (fun marshaled_message -> 263 + let action : Protocol.action = 264 + let str = Js.to_bytestring marshaled_message in 265 + Marshal.from_string str 0 266 + in 267 + log @@ Printf.sprintf "Received message with action %S" 268 + (Protocol.action_to_string action); 269 + let res = on_message action in 270 + log @@ Printf.sprintf "Sending message with answer %S" 271 + (Protocol.answer_to_string res); 272 + post res); 273 + post Protocol.Ready