Skip to content

Commit e7cc545

Browse files
committed
Find references to file as module.
1 parent 4740b5d commit e7cc545

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

analysis/src/References.ml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ let locItemsForPos ~extra pos =
1919

2020
let locItemForPos ~full pos =
2121
let locItems = locItemsForPos ~extra:full.extra pos in
22-
if !Log.spamError then
22+
if !Log.spamError then
2323
print_endline
2424
("locItems:\n"
2525
^ (locItems |> List.map locItemToString |> String.concat "\n"));
@@ -34,7 +34,10 @@ let locItemForPos ~full pos =
3434
] ->
3535
(* heuristic for </Comp> within a fragment *)
3636
None
37-
| [{locType = Constant _}; ({locType = Typed ("createDOMElementVariadic", _, _)} as li2)] ->
37+
| [
38+
{locType = Constant _};
39+
({locType = Typed ("createDOMElementVariadic", _, _)} as li2);
40+
] ->
3841
(* heuristic for <div> *)
3942
Some li2
4043
| {locType = Typed ("makeProps", _, _)}
@@ -464,8 +467,16 @@ let forLocalStamp ~full:{file; extra; package} stamp tip =
464467

465468
let allReferencesForLocItem ~full:({file; package} as full) locItem =
466469
match locItem.locType with
467-
| Typed (_, _, NotFound) | LModule NotFound | TopLevelModule _ | Constant _ ->
468-
[]
470+
| TopLevelModule moduleName -> (
471+
match Hashtbl.find_opt package.pathsForModule moduleName with
472+
| None -> []
473+
| Some paths -> (
474+
match getSrc paths with
475+
| None -> []
476+
| Some src ->
477+
let uri, loc = (Uri2.fromPath src, Utils.topLoc src) in
478+
[(uri, [loc])]))
479+
| Typed (_, _, NotFound) | LModule NotFound | Constant _ -> []
469480
| TypeDefinition (_, _, stamp) -> forLocalStamp ~full stamp Type
470481
| Typed (_, _, (LocalReference (stamp, tip) | Definition (stamp, tip)))
471482
| LModule (LocalReference (stamp, tip) | Definition (stamp, tip)) ->
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
References tests/src/Cross.res 0:17
22
[
3-
3+
{"uri": "References.res", "range": {"start": {"line": 0, "character": 0}, "end": {"line": 0, "character": 0}}}
44
]
55

0 commit comments

Comments
 (0)