Skip to content

Commit b5f8b8f

Browse files
committed
When hovering on a field access, show the instantiated type of the field.
Related: #349
1 parent 3dac12c commit b5f8b8f

File tree

6 files changed

+16
-11
lines changed

6 files changed

+16
-11
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## master
22
- Fix issue where using paths of the form `./something` would show multiple copies of the same file in vscode.
3+
- When hovering on a field access, show the instantiated type of the field.
34

45
## 1.2.1
56

analysis/src/Hover.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ let newHover ~full:{SharedTypes.file; package} locItem =
140140
|> String.concat ", " |> Printf.sprintf "(%s)"
141141
in
142142
typeString :: codeBlock (txt ^ argsString) :: docstring
143-
| `Field {typ} ->
144-
let typeString, docstring = typ |> fromType ~docstring in
143+
| `Field ->
144+
let typeString, docstring = t |> fromType ~docstring in
145145
typeString :: docstring)
146146
in
147147
Some (String.concat "\n\n" parts)

analysis/src/ProcessCmt.ml

+4-5
Original file line numberDiff line numberDiff line change
@@ -765,11 +765,10 @@ struct
765765
| Ldot (_left, name) -> name
766766
| Lapply (_, _) -> assert false
767767

768-
let addForField recordType item {Asttypes.txt; loc} =
768+
let addForField recordType fieldType {Asttypes.txt; loc} =
769769
match (Shared.dig recordType).desc with
770770
| Tconstr (path, _args, _memo) ->
771771
let t = getTypeAtPath ~env path in
772-
let {Types.lbl_res} = item in
773772
let name = handleConstructor txt in
774773
let nameLoc = Utils.endOfLocation loc (String.length name) in
775774
let locType =
@@ -785,7 +784,7 @@ struct
785784
GlobalReference (moduleName, path, Field name)
786785
| _ -> NotFound
787786
in
788-
addLocItem extra nameLoc (Typed (name, lbl_res, locType))
787+
addLocItem extra nameLoc (Typed (name, fieldType, locType))
789788
| _ -> ()
790789

791790
let addForRecord recordType items =
@@ -1004,8 +1003,8 @@ struct
10041003
()
10051004
| Texp_construct (lident, constructor, _args) ->
10061005
addForConstructor expression.exp_type lident constructor
1007-
| Texp_field (inner, lident, label_description) ->
1008-
addForField inner.exp_type label_description lident
1006+
| Texp_field (inner, lident, _label_description) ->
1007+
addForField inner.exp_type expression.exp_type lident
10091008
| Texp_let (_, _, _) ->
10101009
(* TODO this scope tracking won't work for recursive *)
10111010
addScopeExtent expression.exp_loc

analysis/src/References.ml

+1-4
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,7 @@ let definedForLoc ~file ~package locKind =
129129
match getConstructor file stamp name with
130130
| None -> None
131131
| Some constructor -> Some ([], `Constructor constructor))
132-
| Field name -> (
133-
match getField file stamp name with
134-
| None -> None
135-
| Some field -> Some ([], `Field field))
132+
| Field _name -> Some([], `Field)
136133
| _ -> (
137134
maybeLog
138135
("Trying for declared " ^ tipToString tip ^ " " ^ string_of_int stamp

analysis/tests/src/Hover.res

+5
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,8 @@ let _ = <Comp> <div /> <div /> </Comp>
8787

8888
let _ = <Comp1> <div /> <div /> </Comp1>
8989
// ^hov
90+
91+
type r<'a> = {i: 'a, f: float}
92+
93+
let _get = r => r.f +. r.i
94+
// ^hov

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

+3
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,6 @@ Hover tests/src/Hover.res 84:10
5252
Hover tests/src/Hover.res 87:10
5353
{"contents": "```rescript\n{\"children\": React.element} => React.element\n```"}
5454

55+
Hover tests/src/Hover.res 92:25
56+
{"contents": "```rescript\nfloat\n```"}
57+

0 commit comments

Comments
 (0)