Skip to content

Commit 1238497

Browse files
committed
refactor
1 parent a57f443 commit 1238497

File tree

1 file changed

+16
-25
lines changed

1 file changed

+16
-25
lines changed

analysis/src/ProcessCmt.ml

+16-25
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,25 @@
11
open Typedtree
22
open SharedTypes
33

4-
let itemsExtent items =
5-
let items = items |> List.filter (fun item -> not item.str_loc.loc_ghost) in
6-
match items with
4+
let locsExtent locs =
5+
let locs = locs |> List.filter (fun loc -> not loc.Location.loc_ghost) in
6+
(* This filters out ghost locs, but still assumes positions are ordered.
7+
Perhaps compute min/max. *)
8+
match locs with
79
| [] -> Location.none
810
| first :: _ ->
9-
let last = List.nth items (List.length items - 1) in
11+
let last = List.nth locs (List.length locs - 1) in
1012
let first, last =
11-
if first.str_loc.loc_start.pos_cnum < last.str_loc.loc_start.pos_cnum then
12-
(first, last)
13+
if first.loc_start.pos_cnum < last.loc_start.pos_cnum then (first, last)
1314
else (last, first)
1415
in
15-
{
16-
loc_ghost = true;
17-
loc_start = first.str_loc.loc_start;
18-
loc_end = last.str_loc.loc_end;
19-
}
16+
{loc_ghost = true; loc_start = first.loc_start; loc_end = last.loc_end}
17+
18+
let impItemsExtent items =
19+
items |> List.map (fun item -> item.Typedtree.str_loc) |> locsExtent
2020

2121
let sigItemsExtent items =
22-
let items = items |> List.filter (fun item -> not item.sig_loc.loc_ghost) in
23-
match items with
24-
| [] -> Location.none
25-
| first :: _ ->
26-
let last = List.nth items (List.length items - 1) in
27-
{
28-
Location.loc_ghost = true;
29-
loc_start = first.sig_loc.loc_start;
30-
loc_end = last.sig_loc.loc_end;
31-
}
22+
items |> List.map (fun item -> item.Typedtree.sig_loc) |> locsExtent
3223

3324
let addItem ~name ~extent ~stamp ~env ~item attributes exported stamps =
3425
let declared =
@@ -411,7 +402,7 @@ and forModule env mod_desc moduleName =
411402
let env =
412403
{
413404
env with
414-
scope = itemsExtent structure.str_items;
405+
scope = impItemsExtent structure.str_items;
415406
modulePath = ExportedModule (moduleName, env.modulePath);
416407
}
417408
in
@@ -484,7 +475,7 @@ let forCmt ~moduleName ~uri ({cmt_modname; cmt_annots} : Cmt_format.cmt_infos) =
484475
| _ -> None)
485476
|> List.concat
486477
in
487-
let extent = itemsExtent items in
478+
let extent = impItemsExtent items in
488479
let extent =
489480
{
490481
extent with
@@ -527,7 +518,7 @@ let forCmt ~moduleName ~uri ({cmt_modname; cmt_annots} : Cmt_format.cmt_infos) =
527518
| Implementation structure ->
528519
let env =
529520
{
530-
scope = itemsExtent structure.str_items;
521+
scope = impItemsExtent structure.str_items;
531522
stamps = initStamps ();
532523
modulePath = File (uri, moduleName);
533524
}
@@ -1046,7 +1037,7 @@ end
10461037
let extraForStructureItems ~(file : File.t)
10471038
(items : Typedtree.structure_item list) parts =
10481039
let extra = extraForFile ~file in
1049-
let extent = itemsExtent items in
1040+
let extent = impItemsExtent items in
10501041
let extent =
10511042
{
10521043
extent with

0 commit comments

Comments
 (0)