Skip to content

When hovering on a field access, show the instantiated type of the fi… #361

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 1 commit into from
Feb 8, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## master
- Fix issue where using paths of the form `./something` would show multiple copies of the same file in vscode.
- When hovering on a field access, show the instantiated type of the field.

## 1.2.1

Expand Down
4 changes: 2 additions & 2 deletions analysis/src/Hover.ml
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ let newHover ~full:{SharedTypes.file; package} locItem =
|> String.concat ", " |> Printf.sprintf "(%s)"
in
typeString :: codeBlock (txt ^ argsString) :: docstring
| `Field {typ} ->
let typeString, docstring = typ |> fromType ~docstring in
| `Field ->
let typeString, docstring = t |> fromType ~docstring in
typeString :: docstring)
in
Some (String.concat "\n\n" parts)
9 changes: 4 additions & 5 deletions analysis/src/ProcessCmt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -765,11 +765,10 @@ struct
| Ldot (_left, name) -> name
| Lapply (_, _) -> assert false

let addForField recordType item {Asttypes.txt; loc} =
let addForField recordType fieldType {Asttypes.txt; loc} =
match (Shared.dig recordType).desc with
| Tconstr (path, _args, _memo) ->
let t = getTypeAtPath ~env path in
let {Types.lbl_res} = item in
let name = handleConstructor txt in
let nameLoc = Utils.endOfLocation loc (String.length name) in
let locType =
Expand All @@ -785,7 +784,7 @@ struct
GlobalReference (moduleName, path, Field name)
| _ -> NotFound
in
addLocItem extra nameLoc (Typed (name, lbl_res, locType))
addLocItem extra nameLoc (Typed (name, fieldType, locType))
| _ -> ()

let addForRecord recordType items =
Expand Down Expand Up @@ -1004,8 +1003,8 @@ struct
()
| Texp_construct (lident, constructor, _args) ->
addForConstructor expression.exp_type lident constructor
| Texp_field (inner, lident, label_description) ->
addForField inner.exp_type label_description lident
| Texp_field (inner, lident, _label_description) ->
addForField inner.exp_type expression.exp_type lident
| Texp_let (_, _, _) ->
(* TODO this scope tracking won't work for recursive *)
addScopeExtent expression.exp_loc
Expand Down
5 changes: 1 addition & 4 deletions analysis/src/References.ml
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,7 @@ let definedForLoc ~file ~package locKind =
match getConstructor file stamp name with
| None -> None
| Some constructor -> Some ([], `Constructor constructor))
| Field name -> (
match getField file stamp name with
| None -> None
| Some field -> Some ([], `Field field))
| Field _name -> Some([], `Field)
| _ -> (
maybeLog
("Trying for declared " ^ tipToString tip ^ " " ^ string_of_int stamp
Expand Down
5 changes: 5 additions & 0 deletions analysis/tests/src/Hover.res
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,8 @@ let _ = <Comp> <div /> <div /> </Comp>

let _ = <Comp1> <div /> <div /> </Comp1>
// ^hov

type r<'a> = {i: 'a, f: float}

let _get = r => r.f +. r.i
// ^hov
3 changes: 3 additions & 0 deletions analysis/tests/src/expected/Hover.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,6 @@ Hover tests/src/Hover.res 84:10
Hover tests/src/Hover.res 87:10
{"contents": "```rescript\n{\"children\": React.element} => React.element\n```"}

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