Skip to content

Commit 6ddf611

Browse files
committed
Fix references to file modules
1 parent 2877f55 commit 6ddf611

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

analysis/src/References.ml

+22-7
Original file line numberDiff line numberDiff line change
@@ -459,15 +459,30 @@ let forLocalStamp ~full:{file; extra; package} stamp tip =
459459
let allReferencesForLocItem ~full:({file; package} as full) locItem =
460460
match locItem.locType with
461461
| TopLevelModule moduleName ->
462-
let locs =
463-
match Hashtbl.find_opt full.extra.fileReferences moduleName with
462+
let otherModulesReferences =
463+
package.localModules
464+
|> Utils.filterMap (fun name ->
465+
match ProcessCmt.fileForModule ~package name with
466+
| None -> None
467+
| Some file -> ProcessCmt.getFullFromCmt ~uri:file.uri)
468+
|> List.map (fun full ->
469+
match Hashtbl.find_opt full.extra.fileReferences moduleName with
470+
| None -> []
471+
| Some locs ->
472+
locs
473+
|> List.map (fun loc ->
474+
(Uri2.fromPath loc.Location.loc_start.pos_fname, [loc])))
475+
|> List.flatten
476+
in
477+
let targetModuleReference =
478+
match Hashtbl.find_opt package.pathsForModule moduleName with
464479
| None -> []
465-
| Some locs ->
466-
locs
467-
|> List.map (fun loc ->
468-
(Uri2.fromPath loc.Location.loc_start.pos_fname, [loc]))
480+
| Some paths -> (
481+
match SharedTypes.getSrc paths with
482+
| None -> []
483+
| Some src -> [(Uri2.fromPath src, [Utils.topLoc src])])
469484
in
470-
locs
485+
List.append targetModuleReference otherModulesReferences
471486
| Typed (_, _, NotFound) | LModule NotFound | Constant _ -> []
472487
| TypeDefinition (_, _, stamp) -> forLocalStamp ~full stamp Type
473488
| Typed (_, _, (LocalReference (stamp, tip) | Definition (stamp, tip)))

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

+2-1
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)