Skip to content

Commit

Permalink
Also traverse module type aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
voodoos committed Sep 20, 2023
1 parent 7e491bf commit 576182c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/analysis/locate.ml
Original file line number Diff line number Diff line change
Expand Up @@ -311,18 +311,27 @@ let load_cmt ~config comp_unit ml_or_mli =
| None -> Error ()

let scrape_alias ~env ~fallback_uid ~namespace path =
let find_type_and_uid ~env ~namespace path =
match namespace with
| Shape.Sig_component_kind.Module ->
let { Types.md_type; md_uid; _ } = Env.find_module path env in
md_type, md_uid
| Module_type ->
begin match Env.find_modtype path env with
| { Types.mtd_type = Some mtd_type; mtd_uid; _ } ->
mtd_type, mtd_uid
| _ -> raise Not_found
end
| _ -> raise Not_found
in
let rec non_alias_declaration_uid ~fallback_uid path =
match Env.find_module path env with
| { md_type = Mty_alias path; md_uid = fallback_uid; _ } ->
match find_type_and_uid ~env ~namespace path with
| (Mty_alias path | Mty_ident path), fallback_uid ->
non_alias_declaration_uid ~fallback_uid path
| { md_type = Mty_ident _ | Mty_signature _ | Mty_functor _ | Mty_for_hole;
md_uid; _ }-> md_uid
| _, md_uid -> md_uid
| exception Not_found -> fallback_uid
in
match namespace with
| Shape.Sig_component_kind.Module ->
non_alias_declaration_uid ~fallback_uid path
| _ -> fallback_uid
non_alias_declaration_uid ~fallback_uid path

let uid_of_path ~config ~env ~ml_or_mli ~decl_uid path namespace =
let module Shape_reduce =
Expand Down
13 changes: 13 additions & 0 deletions tests/test-dirs/locate/issue1667.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
> end
>
> module M : B.T = struct end
> module type T2 = B.T
> module M2 : T2 = struct end
> EOF

$ $MERLIN single locate -look-for mli -position 7:13 \
Expand All @@ -27,3 +29,14 @@
"col": 2
}
}


$ $MERLIN single locate -look-for mli -position 9:12 \
> -filename ./main.ml < ./main.ml | jq '.value'
{
"file": "$TESTCASE_ROOT/main.ml",
"pos": {
"line": 2,
"col": 2
}
}

0 comments on commit 576182c

Please sign in to comment.