My aggregated monorepo of OCaml code, automaintained
0
fork

Configure Feed

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

feat: add optional filename to Protocol.action for Merlin queries

Add string option filename parameter to Complete_prefix, Type_enclosing,
and All_errors action variants. Thread through builtin worker config and
merlin_client query functions. When provided, Merlin uses the filename
extension to determine .ml vs .mli syntax.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

+19 -14
+4 -2
x-ocaml/src/cell.ml
··· 12 12 fmt_fn : id:int -> string -> unit; 13 13 merlin_worker : Merlin_ext.Client.worker; 14 14 run_on : [ `Click | `Load ]; 15 + filename : string option; 15 16 } 16 17 17 18 let id t = t.id ··· 113 114 (); 114 115 ] 115 116 116 - let init ~id ~run_on ?extra_style ?inline_style ~eval_fn ~fmt_fn ~post_fn this = 117 + let init ~id ~run_on ?filename ?extra_style ?inline_style ~eval_fn ~fmt_fn ~post_fn this = 117 118 let shadow = Webcomponent.attach_shadow this in 118 119 init_css shadow ~extra_style ~inline_style; 119 120 ··· 123 124 124 125 let cm = Editor.make shadow in 125 126 126 - let merlin = Merlin_ext.make ~id post_fn in 127 + let merlin = Merlin_ext.make ~id ?filename post_fn in 127 128 let merlin_worker = Merlin_ext.Client.make_worker merlin in 128 129 let editor = 129 130 { ··· 136 137 fmt_fn; 137 138 merlin_worker; 138 139 run_on; 140 + filename; 139 141 } 140 142 in 141 143 Editor.on_change cm (fun () -> invalidate_after ~editor);
+1
x-ocaml/src/cell.mli
··· 3 3 val init : 4 4 id:int -> 5 5 run_on:[ `Click | `Load ] -> 6 + ?filename:string -> 6 7 ?extra_style:Jstr.t -> 7 8 ?inline_style:Jstr.t -> 8 9 eval_fn:(id:int -> line_number:int -> string -> unit) ->
+3 -3
x-ocaml/src/jtw_client.ml
··· 182 182 Fut.return () 183 183 in 184 184 () 185 - | X_protocol.Merlin (id, Protocol.Complete_prefix (src, pos)) -> 185 + | X_protocol.Merlin (id, Protocol.Complete_prefix (src, pos, _filename)) -> 186 186 let jtw_pos = convert_position pos in 187 187 let _fut : unit Fut.t = 188 188 let* result = ··· 202 202 Fut.return () 203 203 in 204 204 () 205 - | X_protocol.Merlin (id, Protocol.Type_enclosing (src, pos)) -> 205 + | X_protocol.Merlin (id, Protocol.Type_enclosing (src, pos, _filename)) -> 206 206 let jtw_pos = convert_position pos in 207 207 let _fut : unit Fut.t = 208 208 let* result = ··· 221 221 Fut.return () 222 222 in 223 223 () 224 - | X_protocol.Merlin (id, Protocol.All_errors src) -> 224 + | X_protocol.Merlin (id, Protocol.All_errors (src, _filename)) -> 225 225 let _fut : unit Fut.t = 226 226 let* result = 227 227 W.query_errors t.rpc "" None [] false src
+9 -8
x-ocaml/src/merlin_ext.ml
··· 1 - type t = { id : int; mutable context : unit -> string; post_fn : X_protocol.request -> unit } 1 + type t = { id : int; mutable context : unit -> string; post_fn : X_protocol.request -> unit; filename : string option } 2 2 3 3 let set_context t fn = t.context <- fn 4 4 5 - let make ~id post_fn = 6 - { id; context = (fun () -> failwith "Merlin_ext.context"); post_fn } 5 + let make ~id ?filename post_fn = 6 + { id; context = (fun () -> failwith "Merlin_ext.context"); post_fn; filename } 7 7 8 8 let fix_position pre_len = function 9 9 | `Offset at -> `Offset (at + pre_len) ··· 19 19 let fix_request t msg = 20 20 let pre = t.context () in 21 21 let pre_len = String.length pre in 22 + let filename = t.filename in 22 23 match msg with 23 - | Protocol.Complete_prefix (src, position) -> 24 + | Protocol.Complete_prefix (src, position, _) -> 24 25 let position = fix_position pre_len position in 25 - Protocol.Complete_prefix (pre ^ src, position) 26 - | Protocol.Type_enclosing (src, position) -> 26 + Protocol.Complete_prefix (pre ^ src, position, filename) 27 + | Protocol.Type_enclosing (src, position, _) -> 27 28 let position = fix_position pre_len position in 28 - Protocol.Type_enclosing (pre ^ src, position) 29 - | Protocol.All_errors src -> Protocol.All_errors (pre ^ src) 29 + Protocol.Type_enclosing (pre ^ src, position, filename) 30 + | Protocol.All_errors (src, _) -> Protocol.All_errors (pre ^ src, filename) 30 31 | Protocol.Add_cmis _ as other -> other 31 32 32 33 let fix_answer ~pre ~doc msg =
+2 -1
x-ocaml/src/x_ocaml.ml
··· 61 61 | None -> Option.value ~default:"load" run_on 62 62 in 63 63 let id = List.length !all in 64 + let filename = Webcomponent.get_attribute this "data-filename" in 64 65 let eval_fn ~id ~line_number code = Backend.eval ~id ~line_number backend code in 65 66 let fmt_fn ~id code = Backend.fmt ~id backend code in 66 67 let post_fn msg = Backend.post backend msg in 67 - let editor = Cell.init ~id ~run_on ?extra_style ?inline_style ~eval_fn ~fmt_fn ~post_fn this in 68 + let editor = Cell.init ~id ~run_on ?filename ?extra_style ?inline_style ~eval_fn ~fmt_fn ~post_fn this in 68 69 all := editor :: !all; 69 70 Cell.set_prev ~prev editor; 70 71 Cell.start editor this;