|
1 | 1 | open Typedtree
|
2 | 2 | open SharedTypes
|
3 | 3 |
|
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 |
7 | 9 | | [] -> Location.none
|
8 | 10 | | first :: _ ->
|
9 |
| - let last = List.nth items (List.length items - 1) in |
| 11 | + let last = List.nth locs (List.length locs - 1) in |
10 | 12 | 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) |
13 | 14 | else (last, first)
|
14 | 15 | 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 |
20 | 20 |
|
21 | 21 | 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 |
32 | 23 |
|
33 | 24 | let addItem ~name ~extent ~stamp ~env ~item attributes exported stamps =
|
34 | 25 | let declared =
|
@@ -411,7 +402,7 @@ and forModule env mod_desc moduleName =
|
411 | 402 | let env =
|
412 | 403 | {
|
413 | 404 | env with
|
414 |
| - scope = itemsExtent structure.str_items; |
| 405 | + scope = impItemsExtent structure.str_items; |
415 | 406 | modulePath = ExportedModule (moduleName, env.modulePath);
|
416 | 407 | }
|
417 | 408 | in
|
@@ -484,7 +475,7 @@ let forCmt ~moduleName ~uri ({cmt_modname; cmt_annots} : Cmt_format.cmt_infos) =
|
484 | 475 | | _ -> None)
|
485 | 476 | |> List.concat
|
486 | 477 | in
|
487 |
| - let extent = itemsExtent items in |
| 478 | + let extent = impItemsExtent items in |
488 | 479 | let extent =
|
489 | 480 | {
|
490 | 481 | extent with
|
@@ -527,7 +518,7 @@ let forCmt ~moduleName ~uri ({cmt_modname; cmt_annots} : Cmt_format.cmt_infos) =
|
527 | 518 | | Implementation structure ->
|
528 | 519 | let env =
|
529 | 520 | {
|
530 |
| - scope = itemsExtent structure.str_items; |
| 521 | + scope = impItemsExtent structure.str_items; |
531 | 522 | stamps = initStamps ();
|
532 | 523 | modulePath = File (uri, moduleName);
|
533 | 524 | }
|
@@ -1046,7 +1037,7 @@ end
|
1046 | 1037 | let extraForStructureItems ~(file : File.t)
|
1047 | 1038 | (items : Typedtree.structure_item list) parts =
|
1048 | 1039 | let extra = extraForFile ~file in
|
1049 |
| - let extent = itemsExtent items in |
| 1040 | + let extent = impItemsExtent items in |
1050 | 1041 | let extent =
|
1051 | 1042 | {
|
1052 | 1043 | extent with
|
|
0 commit comments