Skip to content

Commit 46e5947

Browse files
committed
Refactor: type for references.
1 parent 2189ce0 commit 46e5947

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

analysis/src/Commands.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ let references ~path ~line ~col =
126126
let allLocs =
127127
allReferences
128128
|> List.fold_left
129-
(fun acc (uri2, references) ->
130-
(references
129+
(fun acc {References.uri = uri2; locs} ->
130+
(locs
131131
|> List.map (fun loc ->
132132
Protocol.stringifyLocation
133133
{
@@ -190,8 +190,8 @@ let rename ~path ~line ~col ~newName =
190190
let referencesToToplevelModules, referencesToItems =
191191
allReferences
192192
|> List.fold_left
193-
(fun acc (uri2, references) ->
194-
(references |> List.map (fun loc -> (uri2, loc))) @ acc)
193+
(fun acc {References.uri = uri2; locs} ->
194+
(locs |> List.map (fun loc -> (uri2, loc))) @ acc)
195195
[]
196196
|> List.partition (fun (_, loc) -> Utils.isTopLoc loc)
197197
in

analysis/src/References.ml

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,8 @@ let rec pathFromVisibility visibilityPath current =
379379
let pathFromVisibility visibilityPath tipName =
380380
pathFromVisibility visibilityPath (Tip tipName)
381381

382+
type references = {uri : Uri2.t; locs : Location.t list}
383+
382384
let forLocalStamp ~full:{file; extra; package} stamp tip =
383385
let env = QueryEnv.fromFile file in
384386
let open Infix in
@@ -392,7 +394,7 @@ let forLocalStamp ~full:{file; extra; package} stamp tip =
392394
| Some localStamp -> (
393395
match Hashtbl.find_opt extra.internalReferences localStamp with
394396
| None -> []
395-
| Some local ->
397+
| Some locs ->
396398
maybeLog ("Checking externals: " ^ string_of_int stamp);
397399
let externals =
398400
match declaredForTip ~stamps:env.file.stamps stamp tip with
@@ -416,7 +418,7 @@ let forLocalStamp ~full:{file; extra; package} stamp tip =
416418
Hashtbl.find_opt extra.internalReferences localStamp
417419
with
418420
| None -> []
419-
| Some local -> [(file.uri, local)]))
421+
| Some local -> [{uri = file.uri; locs = local}]))
420422
(* if this file has a corresponding interface or implementation file
421423
also find the references in that file *)
422424
in
@@ -441,20 +443,20 @@ let forLocalStamp ~full:{file; extra; package} stamp tip =
441443
with
442444
| None -> None
443445
| Some refs ->
444-
let refs =
446+
let locs =
445447
refs
446-
|> Utils.filterMap (fun (p, t, l) ->
447-
if p = path && t = tip then Some l
448+
|> Utils.filterMap (fun (p, t, locs) ->
449+
if p = path && t = tip then Some locs
448450
else None)
449451
in
450-
Some (file.uri, refs))))
452+
Some {uri = file.uri; locs})))
451453
in
452454
alternativeReferences @ externals)
453455
else (
454456
maybeLog "Not visible";
455457
[])
456458
in
457-
(file.uri, local) :: externals)
459+
{uri = file.uri; locs} :: externals)
458460

459461
let allReferencesForLocItem ~full:({file; package} as full) locItem =
460462
match locItem.locType with
@@ -471,14 +473,23 @@ let allReferencesForLocItem ~full:({file; package} as full) locItem =
471473
| Some locs ->
472474
locs |> LocationSet.elements
473475
|> List.map (fun loc ->
474-
(Uri2.fromPath loc.Location.loc_start.pos_fname, [loc])))
476+
{
477+
uri = Uri2.fromPath loc.Location.loc_start.pos_fname;
478+
locs = [loc];
479+
}))
475480
|> List.flatten
476481
in
477482
let targetModuleReferences =
478483
match Hashtbl.find_opt package.pathsForModule moduleName with
479484
| None -> []
480485
| Some paths ->
481-
let moduleSrcToRef src = (Uri2.fromPath src, [Utils.topLoc src]) in
486+
let moduleSrcToRef src =
487+
{
488+
uri = Uri2.fromPath src;
489+
(* XXX TODO use different runtime representation *)
490+
locs = [Utils.topLoc src];
491+
}
492+
in
482493
getSrc paths |> List.map moduleSrcToRef
483494
in
484495
List.append targetModuleReferences otherModulesReferences

0 commit comments

Comments
 (0)