Skip to content

Commit

Permalink
Do not traverse merlin.hide nodes to index occs
Browse files Browse the repository at this point in the history
  • Loading branch information
voodoos committed May 16, 2024
1 parent 5137ef4 commit de17945
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 13 deletions.
29 changes: 28 additions & 1 deletion src/analysis/ast_iterators.ml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,35 @@ let build_uid_to_locs_tbl ~(local_defs : Mtyper.typedtree) () =
iter.structure iter str end;
uid_to_locs_tbl

let has_attribute ~name attrs =
List.exists ~f:(fun a ->
let (str,_) = Ast_helper.Attr.as_tuple a in
str.Location.txt = name
) attrs

let is_hidden attrs =
has_attribute ~name:"merlin.hide" attrs

let iter_on_usages ~f (local_defs : Mtyper.typedtree) =
let iter = Cmt_format.iter_on_occurrences ~f in
let occ_iter = Cmt_format.iter_on_occurrences ~f in
let iter =
{ occ_iter with
(* We avoid iterating on nodes that do not correspond to actual syntax
such as the ones introduced by PPXes *)
module_binding = (fun sub ({ mb_attributes; _ } as mb) ->
if not (is_hidden mb_attributes) then
occ_iter.module_binding sub mb);
include_infos = (fun sub f ({ incl_attributes; _ } as incl) ->
if not (is_hidden incl_attributes) then
occ_iter.include_infos sub f incl);
expr = (fun sub ({ exp_attributes; _ } as e) ->
if not (is_hidden exp_attributes) then
occ_iter.expr sub e);
pat = (fun sub ({ pat_attributes; _ } as p) ->
if not (is_hidden pat_attributes) then
occ_iter.pat sub p);
}
in
begin match local_defs with
| `Interface signature -> iter.signature iter signature
| `Implementation structure -> iter.structure iter structure end
6 changes: 4 additions & 2 deletions src/ocaml/typing/tast_iterator.ml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type iterator =
env: iterator -> Env.t -> unit;
expr: iterator -> expression -> unit;
extension_constructor: iterator -> extension_constructor -> unit;
include_infos: 'a. iterator -> ('a -> unit) -> 'a include_infos -> unit;
location: iterator -> Location.t -> unit;
module_binding: iterator -> module_binding -> unit;
module_coercion: iterator -> module_coercion -> unit;
Expand Down Expand Up @@ -146,7 +147,7 @@ let structure_item sub {str_loc; str_desc; str_env; _} =
| Tstr_class_type list ->
List.iter (fun (_, s, cltd) ->
iter_loc sub s; sub.class_type_declaration sub cltd) list
| Tstr_include incl -> include_infos sub (sub.module_expr sub) incl
| Tstr_include incl -> sub.include_infos sub (sub.module_expr sub) incl
| Tstr_open od -> sub.open_declaration sub od
| Tstr_attribute attr -> sub.attribute sub attr

Expand Down Expand Up @@ -407,7 +408,7 @@ let signature_item sub {sig_loc; sig_desc; sig_env; _} =
| Tsig_recmodule list -> List.iter (sub.module_declaration sub) list
| Tsig_modtype x -> sub.module_type_declaration sub x
| Tsig_modtypesubst x -> sub.module_type_declaration sub x
| Tsig_include incl -> include_infos sub (sub.module_type sub) incl
| Tsig_include incl -> sub.include_infos sub (sub.module_type sub) incl
| Tsig_class list -> List.iter (sub.class_description sub) list
| Tsig_class_type list -> List.iter (sub.class_type_declaration sub) list
| Tsig_open od -> sub.open_description sub od
Expand Down Expand Up @@ -663,6 +664,7 @@ let default_iterator =
env;
expr;
extension_constructor;
include_infos;
location;
module_binding;
module_coercion;
Expand Down
1 change: 1 addition & 0 deletions src/ocaml/typing/tast_iterator.mli
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type iterator =
env: iterator -> Env.t -> unit;
expr: iterator -> expression -> unit;
extension_constructor: iterator -> extension_constructor -> unit;
include_infos: 'a . iterator -> ('a -> unit) -> 'a include_infos -> unit;
location: iterator -> Location.t -> unit;
module_binding: iterator -> module_binding -> unit;
module_coercion: iterator -> module_coercion -> unit;
Expand Down
10 changes: 0 additions & 10 deletions tests/test-dirs/with-ppx/issue1671-string.t
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,6 @@ Merlin should ignore hidden nodes in occurrences results
"line": 1,
"col": 7
}
},
{
"start": {
"line": 3,
"col": 93
},
"end": {
"line": 3,
"col": 94
}
}
],
"notifications": []
Expand Down

0 comments on commit de17945

Please sign in to comment.