Skip to content

Commit

Permalink
Remove old occurrences code
Browse files Browse the repository at this point in the history
  • Loading branch information
voodoos committed May 13, 2024
1 parent 02959ba commit 11bc49a
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 88 deletions.
81 changes: 0 additions & 81 deletions src/analysis/browse_tree.ml
Original file line number Diff line number Diff line change
Expand Up @@ -60,87 +60,6 @@ let dummy = {
t_children = lazy []
}

let rec normalize_type_expr env type_expr =
match Types.get_desc type_expr with
| Types.Tconstr (path,_,_) ->
normalize_type_decl env (Env.find_type path env)
| _ -> raise Not_found

and normalize_type_decl env decl = match decl.Types.type_manifest with
| Some expr -> normalize_type_expr env expr
| None -> decl

let id_of_constr_decl c = `Id c.Types.cd_id

let same_constructor env a b =
let name = function
| `Description d -> d.Types.cstr_name
| `Declaration d -> Ident.name d.Typedtree.cd_id
| `Extension_constructor ec -> Ident.name ec.Typedtree.ext_id
in
if name a <> name b then false
else begin
let get_decls = function
| `Description d ->
let ty = normalize_type_expr env d.Types.cstr_res in
begin match ty.Types.type_kind with
| Types.Type_variant (decls, _) ->
List.map decls ~f:id_of_constr_decl
| Type_open ->
[`Uid d.cstr_uid]
| _ -> assert false
end
| `Declaration d ->
[`Id d.Typedtree.cd_id]
| `Extension_constructor ext_cons ->
let des = Env.find_ident_constructor ext_cons.Typedtree.ext_id env in
[`Uid des.cstr_uid]
in
let a = get_decls a in
let b = get_decls b in
let same a b = match a, b with
| `Id a, `Id b -> Ident.same a b
| `Uid a, `Uid b -> Shape.Uid.equal a b
| _, _ -> false
in
List.exists a ~f:(fun id -> List.exists b ~f:(same id))
end

let all_occurrences path =
let rec aux acc t =
let acc =
let paths = Browse_raw.node_paths t.t_node in
let same l = Path.same path l.Location.txt in
match List.filter ~f:same paths with
| [] -> acc
| paths -> (t, paths) :: acc
in
if Browse_raw.has_attr ~name:"merlin.hide" t.t_node then
acc
else
List.fold_left ~f:aux ~init:acc (Lazy.force t.t_children)
in
aux []

let all_constructor_occurrences ({t_env = env; _},d) t =
let rec aux acc t =
let acc =
match Browse_raw.node_is_constructor t.t_node with
| Some d' when (
(* Don't try this at home kids. *)
try same_constructor env d d'.Location.txt
with Not_found -> same_constructor t.t_env d d'.Location.txt
) ->
{d' with Location.txt = t} :: acc
| _ -> acc
in
if Browse_raw.has_attr ~name:"merlin.hide" t.t_node then
acc
else
List.fold_left ~f:aux ~init:acc (Lazy.force t.t_children)
in
aux [] t

let all_occurrences_of_prefix path node =
let rec path_prefix ~prefix path =
Path.same prefix path ||
Expand Down
7 changes: 0 additions & 7 deletions src/analysis/browse_tree.mli
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,5 @@ val of_browse : Mbrowse.t -> t

val dummy : t

val all_occurrences : Path.t -> t -> (t * Path.t Location.loc list) list
val all_constructor_occurrences :
t * [ `Description of Types.constructor_description
| `Declaration of Typedtree.constructor_declaration
| `Extension_constructor of Typedtree.extension_constructor ]
-> t -> t Location.loc list

val all_occurrences_of_prefix :
Path.t -> Browse_raw.node -> (Path.t Location.loc * Longident.t) list

0 comments on commit 11bc49a

Please sign in to comment.