Skip to content

Commit 1cd63b4

Browse files
committed
Find references in both .res and .resi files.
1 parent 247ce86 commit 1cd63b4

File tree

6 files changed

+44
-32
lines changed

6 files changed

+44
-32
lines changed

analysis/src/Cmt.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ let fullFromUri ~uri =
2424
prerr_endline ("can't find module " ^ moduleName);
2525
None)
2626

27-
let fullFromModule ~package ~moduleName =
27+
let fullsFromModule ~package ~moduleName =
2828
if Hashtbl.mem package.pathsForModule moduleName then
2929
let paths = Hashtbl.find package.pathsForModule moduleName in
30-
let uri = getUri paths in
31-
fullFromUri ~uri
32-
else None
30+
let uris = getUris paths in
31+
uris |> List.filter_map (fun uri -> fullFromUri ~uri)
32+
else []
3333

3434
let loadFullCmtFromPath ~path =
3535
let uri = Uri.fromPath path in

analysis/src/Commands.ml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,9 @@ let references ~path ~pos ~debug =
172172
| Some loc -> loc
173173
| None -> Uri.toTopLevelLoc uri2
174174
in
175-
if loc.loc_ghost then acc
176-
else
177-
Protocol.stringifyLocation
178-
{uri = Uri.toString uri2; range = Utils.cmtLocToRange loc}
179-
:: acc)
175+
Protocol.stringifyLocation
176+
{uri = Uri.toString uri2; range = Utils.cmtLocToRange loc}
177+
:: acc)
180178
[])
181179
in
182180
print_endline

analysis/src/References.ml

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -506,28 +506,24 @@ let forLocalStamp ~full:{file; extra; package} stamp (tip : Tip.t) =
506506
package.projectFiles |> FileSet.elements
507507
|> List.filter (fun name -> name <> file.moduleName)
508508
|> List.map (fun moduleName ->
509-
match ProcessCmt.fileForModule ~package moduleName with
510-
| None -> []
511-
| Some file -> (
512-
match Cmt.fullFromModule ~package ~moduleName with
513-
| None -> []
514-
| Some {extra} -> (
515-
match
516-
Hashtbl.find_opt extra.externalReferences
517-
thisModuleName
518-
with
519-
| None -> []
520-
| Some refs ->
521-
let locs =
522-
refs
523-
|> Utils.filterMap (fun (p, t, locs) ->
524-
if p = path && t = tip then Some locs
525-
else None)
526-
in
527-
locs
528-
|> List.map (fun loc ->
529-
{uri = file.uri; locOpt = Some loc}))))
530-
|> List.concat
509+
Cmt.fullsFromModule ~package ~moduleName
510+
|> List.map (fun {file; extra} ->
511+
match
512+
Hashtbl.find_opt extra.externalReferences
513+
thisModuleName
514+
with
515+
| None -> []
516+
| Some refs ->
517+
let locs =
518+
refs
519+
|> Utils.filterMap (fun (p, t, locs) ->
520+
if p = path && t = tip then Some locs
521+
else None)
522+
in
523+
locs
524+
|> List.map (fun loc ->
525+
{uri = file.uri; locOpt = Some loc})))
526+
|> List.concat |> List.concat
531527
in
532528
alternativeReferences @ externals)
533529
else (

analysis/src/SharedTypes.ml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,12 @@ let getUri p =
295295
| Namespace {cmt} -> Uri.fromPath cmt
296296
| IntfAndImpl {resi} -> Uri.fromPath resi
297297

298+
let getUris p =
299+
match p with
300+
| Impl {res} -> [Uri.fromPath res]
301+
| Namespace {cmt} -> [Uri.fromPath cmt]
302+
| IntfAndImpl {res; resi} -> [Uri.fromPath res; Uri.fromPath resi]
303+
298304
let getCmtPath ~uri p =
299305
match p with
300306
| Impl {cmt} -> cmt

analysis/tests/src/References.res

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,6 @@ let bb = M.aa
2020
let cc = bb
2121
let dd = M.aa
2222
// ^ref
23-
let _ = <ComponentInner/>
23+
24+
let _ = <ComponentInner/>
25+
// ^ref

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,13 @@ References src/References.res 20:12
2121
{"uri": "References.res", "range": {"start": {"line": 20, "character": 11}, "end": {"line": 20, "character": 13}}}
2222
]
2323

24+
References src/References.res 23:15
25+
getLocItem #4: heuristic for </Comp> within fragments: take make as makeProps does not work
26+
the type is not great but jump to definition works
27+
[
28+
{"uri": "ReferencesInner.res", "range": {"start": {"line": 1, "character": 28}, "end": {"line": 1, "character": 32}}},
29+
{"uri": "References.res", "range": {"start": {"line": 23, "character": 19}, "end": {"line": 23, "character": 23}}},
30+
{"uri": "ComponentInner.res", "range": {"start": {"line": 1, "character": 4}, "end": {"line": 1, "character": 8}}},
31+
{"uri": "ComponentInner.resi", "range": {"start": {"line": 1, "character": 4}, "end": {"line": 1, "character": 8}}}
32+
]
33+

0 commit comments

Comments
 (0)