@@ -455,21 +455,34 @@ let all_commands =
455455 command " locate"
456456 ~spec:
457457 [ optional " -prefix" " <string> Prefix to complete"
458- (Marg. param " string" (fun txt (_ , pos , kind ) ->
459- (Some txt, pos, kind)));
458+ (Marg. param " string" (fun txt (_ , pos , kind , ctx ) ->
459+ (Some txt, pos, kind, ctx )));
460460 arg " -position" " <position> Position to complete"
461- (marg_position (fun pos (prefix , _pos , kind ) -> (prefix, pos, kind)));
461+ (marg_position (fun pos (prefix , _pos , kind , ctx ) ->
462+ (prefix, pos, kind, ctx)));
462463 optional " -look-for"
463464 " <interface|implementation> Prefer opening interface or \
464465 implementation"
465466 (Marg. param " <interface|implementation>"
466- (fun kind (prefix , pos , _ ) ->
467+ (fun kind (prefix , pos , _ , ctx ) ->
467468 match kind with
468- | "mli" | "interface" -> (prefix, pos, `MLI )
469- | "ml" | "implementation" -> (prefix, pos, `ML )
469+ | "mli" | "interface" -> (prefix, pos, `MLI , ctx )
470+ | "ml" | "implementation" -> (prefix, pos, `ML , ctx )
470471 | str ->
471472 failwithf " expecting interface or implementation, got %S."
472- str))
473+ str));
474+ (let contexts =
475+ let open Query_protocol.Locate_context in
476+ all |> List. map ~f: to_string |> String. concat ~sep: " |"
477+ in
478+ optional " -context"
479+ (Format. sprintf
480+ " <%s> Which context to search for the identifier in" contexts)
481+ (Marg. param (Format. sprintf " <%s>" contexts)
482+ (fun ctx (prefix , pos , kind , _ ) ->
483+ match Query_protocol.Locate_context. of_string ctx with
484+ | Some ctx -> (prefix, pos, kind, Some ctx)
485+ | None -> failwithf " invalid context %s." ctx)))
473486 ]
474487 ~doc:
475488 " Finds the declaration of entity at the specified position, Or \
@@ -479,13 +492,13 @@ let all_commands =
479492 - `{'pos': position}` if the location is in the current buffer,\n \
480493 - `{'file': string, 'pos': position}` if definition is located in a \
481494 different file."
482- ~default: (None , `None , `MLI )
495+ ~default: (None , `None , `MLI , None )
483496 begin
484- fun buffer (prefix , pos , lookfor ) ->
497+ fun buffer (prefix , pos , lookfor , context ) ->
485498 match pos with
486499 | `None -> failwith " -position <pos> is mandatory"
487500 | #Msource. position as pos ->
488- run buffer (Query_protocol. Locate (prefix, lookfor, pos))
501+ run buffer (Query_protocol. Locate (prefix, lookfor, pos, context ))
489502 end;
490503 command " locate-type"
491504 ~spec:
0 commit comments