Skip to content

Commit 73a5c73

Browse files
committed
Add heuristic for hover on components in interface files.
Fixes #177
1 parent e612a20 commit 73a5c73

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

analysis/src/Commands.ml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ let hover ~path ~line ~col =
4747
let result =
4848
match ProcessCmt.getFullFromCmt ~uri with
4949
| None -> Protocol.null
50-
| Some ({file; extra} as full) -> (
50+
| Some ({file} as full) -> (
5151
let pos = Utils.protocolLineColToCmtLoc ~line ~col in
52-
match References.locItemForPos ~extra pos with
52+
match References.locItemForPos ~full pos with
5353
| None -> Protocol.null
5454
| Some locItem -> (
5555
let isModule =
@@ -83,10 +83,10 @@ let definition ~path ~line ~col =
8383
let result =
8484
match ProcessCmt.getFullFromCmt ~uri with
8585
| None -> Protocol.null
86-
| Some ({file; extra} as full) -> (
86+
| Some ({file} as full) -> (
8787
let pos = Utils.protocolLineColToCmtLoc ~line ~col in
8888

89-
match References.locItemForPos ~extra pos with
89+
match References.locItemForPos ~full pos with
9090
| None -> Protocol.null
9191
| Some locItem -> (
9292
let isModule =
@@ -118,9 +118,9 @@ let references ~path ~line ~col =
118118
let result =
119119
match ProcessCmt.getFullFromCmt ~uri with
120120
| None -> Protocol.null
121-
| Some ({extra} as full) -> (
121+
| Some full -> (
122122
let pos = Utils.protocolLineColToCmtLoc ~line ~col in
123-
match References.locItemForPos ~extra pos with
123+
match References.locItemForPos ~full pos with
124124
| None -> Protocol.null
125125
| Some locItem ->
126126
let allReferences = References.allReferencesForLocItem ~full locItem in

analysis/src/References.ml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@ let checkPos (line, char)
1717
let locItemsForPos ~extra pos =
1818
extra.locItems |> List.filter (fun {loc; locType = _} -> checkPos pos loc)
1919

20-
let locItemForPos ~extra pos =
21-
let locItems = locItemsForPos ~extra pos in
20+
let locItemForPos ~full pos =
21+
let locItems = locItemsForPos ~extra:full.extra pos in
2222
match locItems with
23+
| _ :: _ :: _ :: l :: _ when full.file.uri |> Uri2.isInterface ->
24+
(* heuristic for makeProps in interface files *)
25+
Some l
2326
| [({locType = Typed (_, LocalReference _)} as li1); li3]
2427
when li1.loc = li3.loc ->
2528
(* JSX and compiler combined:

analysis/tests/src/expected/Jsx.resi.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Hover tests/src/Jsx.resi 1:4
2-
{"contents": "```rescript\nReact.componentLike<{\"first\": string}, React.element>\n```\n\n```rescript\ntype componentLike<'props, 'return> = 'props => 'return\n```"}
2+
{"contents": "```rescript\n(~first: string, ~?key: string, unit) => {\"first\": string}\n```"}
33

44
Hover tests/src/Jsx.resi 4:4
55
{"contents": "```rescript\nint\n```"}

0 commit comments

Comments
 (0)