Skip to content

Commit 55c82b4

Browse files
committed
Fix references to file modules
1 parent 76959b6 commit 55c82b4

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

analysis/src/References.ml

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -468,15 +468,30 @@ let forLocalStamp ~full:{file; extra; package} stamp tip =
468468
let allReferencesForLocItem ~full:({file; package} as full) locItem =
469469
match locItem.locType with
470470
| TopLevelModule moduleName ->
471-
let locs =
472-
match Hashtbl.find_opt full.extra.fileReferences moduleName with
471+
let otherModulesReferences =
472+
package.localModules
473+
|> Utils.filterMap (fun name ->
474+
match ProcessCmt.fileForModule ~package name with
475+
| None -> None
476+
| Some file -> ProcessCmt.getFullFromCmt ~uri:file.uri)
477+
|> List.map (fun full ->
478+
match Hashtbl.find_opt full.extra.fileReferences moduleName with
479+
| None -> []
480+
| Some locs ->
481+
locs
482+
|> List.map (fun loc ->
483+
(Uri2.fromPath loc.Location.loc_start.pos_fname, [loc])))
484+
|> List.flatten
485+
in
486+
let targetModuleReference =
487+
match Hashtbl.find_opt package.pathsForModule moduleName with
473488
| None -> []
474-
| Some locs ->
475-
locs
476-
|> List.map (fun loc ->
477-
(Uri2.fromPath loc.Location.loc_start.pos_fname, [loc]))
489+
| Some paths -> (
490+
match SharedTypes.getSrc paths with
491+
| None -> []
492+
| Some src -> [(Uri2.fromPath src, [Utils.topLoc src])])
478493
in
479-
locs
494+
List.append targetModuleReference otherModulesReferences
480495
| Typed (_, _, NotFound) | LModule NotFound | Constant _ -> []
481496
| TypeDefinition (_, _, stamp) -> forLocalStamp ~full stamp Type
482497
| Typed (_, _, (LocalReference (stamp, tip) | Definition (stamp, tip)))

analysis/tests/src/expected/Cross.res.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ References tests/src/Cross.res 0:17
33
{"uri": "Cross.res", "range": {"start": {"line": 0, "character": 15}, "end": {"line": 0, "character": 25}}},
44
{"uri": "Cross.res", "range": {"start": {"line": 3, "character": 16}, "end": {"line": 3, "character": 26}}},
55
{"uri": "Cross.res", "range": {"start": {"line": 6, "character": 13}, "end": {"line": 6, "character": 23}}},
6-
{"uri": "Cross.res", "range": {"start": {"line": 8, "character": 16}, "end": {"line": 8, "character": 26}}}
6+
{"uri": "Cross.res", "range": {"start": {"line": 8, "character": 16}, "end": {"line": 8, "character": 26}}},
7+
{"uri": "References.res", "range": {"start": {"line": 0, "character": 0}, "end": {"line": 0, "character": 0}}}
78
]
89

0 commit comments

Comments
 (0)