Skip to content

Redo pr 649 #651

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@

- Fix issue with references to elements defined in an interface file https://github.com/rescript-lang/rescript-vscode/pull/646

- Fix issue with references from implementation files which also happen to have interface files https://github.com/rescript-lang/rescript-vscode/issues/645

## v1.8.2

#### :rocket: New Feature
Expand Down
8 changes: 4 additions & 4 deletions analysis/src/Cmt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ let fullFromUri ~uri =
prerr_endline ("can't find module " ^ moduleName);
None)

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

let loadFullCmtFromPath ~path =
let uri = Uri.fromPath path in
Expand Down
40 changes: 18 additions & 22 deletions analysis/src/References.ml
Original file line number Diff line number Diff line change
Expand Up @@ -506,28 +506,24 @@ let forLocalStamp ~full:{file; extra; package} stamp (tip : Tip.t) =
package.projectFiles |> FileSet.elements
|> List.filter (fun name -> name <> file.moduleName)
|> List.map (fun moduleName ->
match ProcessCmt.fileForModule ~package moduleName with
| None -> []
| Some file -> (
match Cmt.fullFromModule ~package ~moduleName with
| None -> []
| Some {extra} -> (
match
Hashtbl.find_opt extra.externalReferences
thisModuleName
with
| None -> []
| Some refs ->
let locs =
refs
|> Utils.filterMap (fun (p, t, locs) ->
if p = path && t = tip then Some locs
else None)
in
locs
|> List.map (fun loc ->
{uri = file.uri; locOpt = Some loc}))))
|> List.concat
Cmt.fullsFromModule ~package ~moduleName
|> List.map (fun {file; extra} ->
match
Hashtbl.find_opt extra.externalReferences
thisModuleName
with
| None -> []
| Some refs ->
let locs =
refs
|> Utils.filterMap (fun (p, t, locs) ->
if p = path && t = tip then Some locs
else None)
in
locs
|> List.map (fun loc ->
{uri = file.uri; locOpt = Some loc})))
|> List.concat |> List.concat
in
alternativeReferences @ externals)
else (
Expand Down
6 changes: 6 additions & 0 deletions analysis/src/SharedTypes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,12 @@ let getUri p =
| Namespace {cmt} -> Uri.fromPath cmt
| IntfAndImpl {resi} -> Uri.fromPath resi

let getUris p =
match p with
| Impl {res} -> [Uri.fromPath res]
| Namespace {cmt} -> [Uri.fromPath cmt]
| IntfAndImpl {res; resi} -> [Uri.fromPath res; Uri.fromPath resi]

let getCmtPath ~uri p =
match p with
| Impl {cmt} -> cmt
Expand Down
5 changes: 4 additions & 1 deletion analysis/tests/src/References.res
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@ module M: {
let bb = M.aa
let cc = bb
let dd = M.aa
// ^ref
// ^ref

let _ = <ComponentInner/>
// ^ref
10 changes: 10 additions & 0 deletions analysis/tests/src/expected/References.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,13 @@ References src/References.res 20:12
{"uri": "References.res", "range": {"start": {"line": 20, "character": 11}, "end": {"line": 20, "character": 13}}}
]

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

2 changes: 2 additions & 0 deletions analysis/tests/src/inner/ComponentInner.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@react.component
let make = () => React.null
2 changes: 2 additions & 0 deletions analysis/tests/src/inner/ComponentInner.resi
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@react.component
let make: unit => React.element
2 changes: 2 additions & 0 deletions analysis/tests/src/inner/ReferencesInner.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@react.component
let make = () => <ComponentInner/>
2 changes: 2 additions & 0 deletions analysis/tests/src/inner/ReferencesInner.resi
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@react.component
let make: unit => React.element