···702702 line1, src
703703704704 let complete_prefix _id _deps is_toplevel source position =
705705+ try begin
705706 let line1, src = mangle_toplevel is_toplevel source [] in
706707 let src= line1 ^ src in
707708 let source = Merlin_kernel.Msource.make src in
···750751 IdlM.ErrM.return { Toplevel_api_gen.from; to_; entries }
751752 | None ->
752753 IdlM.ErrM.return { Toplevel_api_gen.from = 0; to_ = 0; entries = [] }
754754+ end
755755+ with e ->
756756+ Logs.info (fun m -> m "Error: %s" (Printexc.to_string e));
757757+ IdlM.ErrM.return_err
758758+ (Toplevel_api_gen.InternalError (Printexc.to_string e))
753759754760 let add_cmi id deps source =
755761 Logs.info (fun m -> m "add_cmi");
···847853 (Toplevel_api_gen.InternalError (Printexc.to_string e))
848854849855 let type_enclosing _id deps is_toplevel orig_source position =
850850- let line1, src = mangle_toplevel is_toplevel orig_source deps in
851851- let src = line1 ^ src in
852852- let position =
853853- match position with
854854- | Toplevel_api_gen.Start -> `Start
855855- | Offset x -> `Offset (x + String.length line1)
856856- | Logical (x, y) -> `Logical (x+1, y)
857857- | End -> `End
858858- in
859859- let source = Merlin_kernel.Msource.make src in
860860- let query = Query_protocol.Type_enclosing (None, position, None) in
861861- let enclosing = wdispatch source query in
862862- let map_index_or_string = function
863863- | `Index i -> Toplevel_api_gen.Index i
864864- | `String s -> String s
865865- in
866866- let map_tail_position = function
867867- | `No -> Toplevel_api_gen.No
868868- | `Tail_position -> Tail_position
869869- | `Tail_call -> Tail_call
870870- in
871871- let enclosing =
872872- List.map
873873- (fun (x, y, z) -> (x, map_index_or_string y, map_tail_position z))
874874- enclosing
875875- in
876876- IdlM.ErrM.return enclosing
856856+ try
857857+ let line1, src = mangle_toplevel is_toplevel orig_source deps in
858858+ let src = line1 ^ src in
859859+ let position =
860860+ match position with
861861+ | Toplevel_api_gen.Start -> `Start
862862+ | Offset x -> `Offset (x + String.length line1)
863863+ | Logical (x, y) -> `Logical (x+1, y)
864864+ | End -> `End
865865+ in
866866+ let source = Merlin_kernel.Msource.make src in
867867+ let query = Query_protocol.Type_enclosing (None, position, None) in
868868+ let enclosing = wdispatch source query in
869869+ let map_index_or_string = function
870870+ | `Index i -> Toplevel_api_gen.Index i
871871+ | `String s -> String s
872872+ in
873873+ let map_tail_position = function
874874+ | `No -> Toplevel_api_gen.No
875875+ | `Tail_position -> Tail_position
876876+ | `Tail_call -> Tail_call
877877+ in
878878+ let enclosing =
879879+ List.map
880880+ (fun (x, y, z) -> (x, map_index_or_string y, map_tail_position z))
881881+ enclosing
882882+ in
883883+ IdlM.ErrM.return enclosing
884884+ with e ->
885885+ Logs.info (fun m -> m "Error: %s" (Printexc.to_string e));
886886+ IdlM.ErrM.return_err
887887+ (Toplevel_api_gen.InternalError (Printexc.to_string e))
888888+877889end
+16-3
lib/ocamltop.ml
···1010 len''
11111212let parse_toplevel s =
1313- Logs.warn (fun m -> m "Parsing toplevel phrases");
1313+ let legacy_warn =
1414+ let b = ref false in
1515+ fun () ->
1616+ if !b
1717+ then ()
1818+ else
1919+ (Logs.warn (fun m -> m "Warning: Legacy toplevel output detected");
2020+ b := true)
2121+ in
2222+1423 let lexbuf = Lexing.from_string s in
1524 let rec loop pos =
1625 let _phr = !Toploop.parse_toplevel_phrase lexbuf in
1726 let new_pos = Lexing.lexeme_end lexbuf in
1827 let phr = String.sub s pos (new_pos - pos) in
1928 let (junk, (cont, is_legacy, output)) = Toplexer.entry lexbuf in
2020- if is_legacy then
2121- Logs.warn (fun m -> m "Warning: Legacy toplevel output detected");
2929+ let output =
3030+ if is_legacy then begin
3131+ legacy_warn ();
3232+ List.map (fun x -> try String.sub x 2 (String.length x - 2) with _ -> "") output
3333+ end else output
3434+ in
2235 let new_pos = Lexing.lexeme_end lexbuf in
2336 if cont then (phr, junk, output) :: loop new_pos else [ (phr, junk, output) ]
2437 in