this repo has no description
0
fork

Configure Feed

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

feat(x-ocaml): read data-filename and pass to Merlin queries

Read data-filename attribute from x-ocaml elements. Store in cell
record and Merlin_ext context. Pass through Protocol.action to both
builtin and jtw backends for correct .mli handling.

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

+22 -17
+4 -2
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
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) ->
+6 -6
src/jtw_client.ml
··· 131 131 (id, [X_protocol.Stderr "Internal error during evaluation"])); 132 132 Lwt.return_unit)) 133 133 134 - | X_protocol.Merlin (id, Protocol.Complete_prefix (src, pos)) -> 134 + | X_protocol.Merlin (id, Protocol.Complete_prefix (src, pos, filename)) -> 135 135 let position = match pos with 136 136 | `Offset n -> n 137 137 | _ -> 0 ··· 139 139 Lwt.async (fun () -> 140 140 let open Lwt.Infix in 141 141 Lwt.catch (fun () -> 142 - Jtw.complete t.client src position >|= fun completions -> 142 + Jtw.complete ?filename t.client src position >|= fun completions -> 143 143 respond t (X_protocol.Merlin_response 144 144 (id, Protocol.Completions (convert_completions completions)))) 145 145 (fun _exn -> ··· 147 147 (id, Protocol.Completions { Protocol.from = 0; to_ = 0; entries = [] })); 148 148 Lwt.return_unit)) 149 149 150 - | X_protocol.Merlin (id, Protocol.Type_enclosing (src, pos)) -> 150 + | X_protocol.Merlin (id, Protocol.Type_enclosing (src, pos, filename)) -> 151 151 let position = match pos with 152 152 | `Offset n -> n 153 153 | _ -> 0 ··· 155 155 Lwt.async (fun () -> 156 156 let open Lwt.Infix in 157 157 Lwt.catch (fun () -> 158 - Jtw.type_at t.client src position >|= fun types -> 158 + Jtw.type_at ?filename t.client src position >|= fun types -> 159 159 respond t (X_protocol.Merlin_response 160 160 (id, Protocol.Typed_enclosings (List.map convert_type_info types)))) 161 161 (fun _exn -> ··· 163 163 (id, Protocol.Typed_enclosings [])); 164 164 Lwt.return_unit)) 165 165 166 - | X_protocol.Merlin (id, Protocol.All_errors src) -> 166 + | X_protocol.Merlin (id, Protocol.All_errors (src, filename)) -> 167 167 Lwt.async (fun () -> 168 168 let open Lwt.Infix in 169 169 Lwt.catch (fun () -> 170 - Jtw.errors t.client src >|= fun errors -> 170 + Jtw.errors ?filename t.client src >|= fun errors -> 171 171 respond t (X_protocol.Merlin_response 172 172 (id, Protocol.Errors (List.map convert_error errors)))) 173 173 (fun _exn ->
+9 -8
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
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;