This commit is contained in:
atagen 2026-03-23 15:06:49 +11:00
parent 76656231be
commit adea668355
6 changed files with 76 additions and 27 deletions

View file

@ -586,26 +586,29 @@ let cmd_complete spans user_dir system_dirs =
| Some r -> Some (try_name, r, List.length tokens)
| None ->
find_result (List.rev (List.tl (List.rev tokens))) in
let all_tokens = cmd_name :: (match rest with
| _ :: _ when List.length rest >= 1 ->
(* exclude the partial last token from subcommand lookup *)
List.rev (List.tl (List.rev rest))
let all_tokens = cmd_name :: rest in
let partial_tokens = cmd_name :: (match rest with
| _ :: _ -> List.rev (List.tl (List.rev rest))
| _ -> []) in
let found = find_result all_tokens in
let last_token = match rest with
| [] -> "" | _ -> List.nth rest (List.length rest - 1) in
(* Try full token list first (last token is a complete subcommand),
then fall back to treating the last token as partial *)
let try_both () =
match find_result all_tokens with
| Some _ as r -> (r, "")
| None -> (find_result partial_tokens, last_token) in
let found, partial = try_both () in
(* If not found at all, try on-the-fly resolution for the base command *)
let result = match found with
| Some _ -> found
let result, partial = match found with
| Some _ -> (found, partial)
| None ->
(match find_in_path cmd_name with
| Some path ->
(match resolve_and_cache ~dir:user_dir cmd_name path with
| Some _pairs ->
find_result all_tokens
| None -> None)
| None -> None) in
let partial = match rest with
| [] -> ""
| _ -> List.nth rest (List.length rest - 1) in
| Some _pairs -> try_both ()
| None -> (None, partial))
| None -> (None, partial)) in
(match result with
| None -> print_string "[]\n"
| Some (_matched_name, r, _depth) ->