Skip to content
This repository was archived by the owner on Apr 24, 2021. It is now read-only.

Commit 1338bae

Browse files
committed
Fix hover on labels in component functions with compiler version 9.1.
1 parent 39d853f commit 1338bae

File tree

3 files changed

+32
-26
lines changed

3 files changed

+32
-26
lines changed

Changes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- Add autocomplete for props in JSX components.
55
- Autocomplete: fix issue where `->` autocomplete was overruling `.`. See https://github.com/rescript-lang/rescript-editor-support/issues/99.
66
- Add pipe autocomplete for builtin list, array, string, option types. And for string and array literals.
7+
- Fix hover on labels in component functions with compiler version 9.1.
78

89
## Release 1.0.6 of rescript-vscode
910
This [commit](https://github.com/rescript-lang/rescript-editor-support/commit/03ee0d97b250474028d4fb08eac81ddb21ccb082) is vendored in [rescript-vscode 1.0.6](https://github.com/rescript-lang/rescript-vscode/releases/tag/1.0.6).

src/References.ml

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,16 @@ let locsForPos ~extra pos =
1919

2020
let locForPos ~extra pos =
2121
match locsForPos ~extra pos with
22+
| [(loc1, Typed (_, LocalReference _)); ((loc3, _) as l3)] when loc1 = loc3 ->
23+
(* JSX and compiler combined: *)
24+
(* ~x becomes Props#x *)
25+
(* heuristic for: [Props, x], give loc of `x` *)
26+
Some l3
2227
| [
2328
(loc1, Typed (_, LocalReference _));
2429
(loc2, Typed (_, GlobalReference ("Js_OO", Tip "unsafe_downgrade", _)));
2530
((loc3, _) as l3);
26-
]
31+
] (* For older compiler 9.0 or earlier *)
2732
when loc1 = loc2 && loc2 = loc3 ->
2833
(* JSX and compiler combined: *)
2934
(* ~x becomes Js_OO.unsafe_downgrade(Props)#x *)
@@ -47,18 +52,18 @@ let definedForLoc ~file ~getModule locKind =
4752
| Constructor name -> (
4853
match Query.getConstructor file stamp name with
4954
| None -> None
50-
| Some constructor -> Some ([], `Constructor constructor))
55+
| Some constructor -> Some ([], `Constructor constructor) )
5156
| Field name -> (
5257
match Query.getField file stamp name with
5358
| None -> None
54-
| Some field -> Some ([], `Field field))
59+
| Some field -> Some ([], `Field field) )
5560
| _ -> (
5661
maybeLog
57-
("Trying for declared " ^ tipToString tip ^ " " ^ string_of_int stamp
58-
^ " in file " ^ Uri2.toString file.uri);
62+
( "Trying for declared " ^ tipToString tip ^ " " ^ string_of_int stamp
63+
^ " in file " ^ Uri2.toString file.uri );
5964
match Query.declaredForTip ~stamps:file.stamps stamp tip with
6065
| None -> None
61-
| Some declared -> Some (declared.docstring, `Declared))
66+
| Some declared -> Some (declared.docstring, `Declared) )
6267
in
6368
match locKind with
6469
| NotFound -> None
@@ -90,7 +95,7 @@ let definedForLoc ~file ~getModule locKind =
9095
None
9196
| Some res ->
9297
maybeLog "Yes!! got it";
93-
Some res))))
98+
Some res ) ) ) )
9499

95100
let alternateDeclared ~file ~pathsForModule ~getUri declared tip =
96101
match Hashtbl.find_opt pathsForModule file.moduleName with
@@ -113,7 +118,7 @@ let alternateDeclared ~file ~pathsForModule ~getUri declared tip =
113118
~exported:file.contents.exported declared.name.txt tip
114119
with
115120
| None -> None
116-
| Some declared -> Some (file, extra, declared))
121+
| Some declared -> Some (file, extra, declared) )
117122
else
118123
match getUri intfUri with
119124
| Error e ->
@@ -125,8 +130,8 @@ let alternateDeclared ~file ~pathsForModule ~getUri declared tip =
125130
~exported:file.contents.exported declared.name.txt tip
126131
with
127132
| None -> None
128-
| Some declared -> Some (file, extra, declared)))
129-
| _ -> None)
133+
| Some declared -> Some (file, extra, declared) ) )
134+
| _ -> None )
130135

131136
let resolveModuleReference ~file ~getModule (declared : moduleKind declared) =
132137
match declared.item with
@@ -143,7 +148,7 @@ let resolveModuleReference ~file ~getModule (declared : moduleKind declared) =
143148
| None -> None
144149
| Some md ->
145150
Some (env.file, Some md)
146-
(* Some((env.file.uri, validateLoc(md.name.loc, md.extentLoc))) *)))
151+
(* Some((env.file.uri, validateLoc(md.name.loc, md.extentLoc))) *) ) )
147152
| `Global (moduleName, path) -> (
148153
match getModule moduleName with
149154
| None -> None
@@ -160,20 +165,20 @@ let resolveModuleReference ~file ~getModule (declared : moduleKind declared) =
160165
| Some md ->
161166
Some (env.file, Some md)
162167
(* Some((env.file.uri, validateLoc(md.name.loc, md.extentLoc))) *)
163-
))))
168+
) ) ) )
164169
| `Stamp stamp -> (
165170
match Hashtbl.find_opt file.stamps.modules stamp with
166171
| None -> None
167172
| Some md ->
168173
Some (file, Some md)
169-
(* Some((file.uri, validateLoc(md.name.loc, md.extentLoc))) *))
174+
(* Some((file.uri, validateLoc(md.name.loc, md.extentLoc))) *) )
170175
| `GlobalMod name -> (
171176
match getModule name with
172177
| None -> None
173178
| Some file ->
174179
(* maybeLog("Congrats, found a global mod"); *)
175-
Some (file, None))
176-
| _ -> None)
180+
Some (file, None) )
181+
| _ -> None )
177182

178183
let validateLoc (loc : Location.t) (backup : Location.t) =
179184
if loc.loc_start.pos_cnum = -1 then
@@ -198,18 +203,18 @@ let resolveModuleDefinition ~file ~getModule stamp =
198203
| None -> Utils.topLoc (Uri2.toPath file.uri)
199204
| Some declared -> validateLoc declared.name.loc declared.extentLoc
200205
in
201-
Some (file.uri, loc))
206+
Some (file.uri, loc) )
202207

203208
let definition ~file ~getModule stamp tip =
204209
match tip with
205210
| Constructor name -> (
206211
match Query.getConstructor file stamp name with
207212
| None -> None
208-
| Some constructor -> Some (file.uri, constructor.cname.loc))
213+
| Some constructor -> Some (file.uri, constructor.cname.loc) )
209214
| Field name -> (
210215
match Query.getField file stamp name with
211216
| None -> None
212-
| Some field -> Some (file.uri, field.fname.loc))
217+
| Some field -> Some (file.uri, field.fname.loc) )
213218
| Module -> resolveModuleDefinition ~file ~getModule stamp
214219
| _ -> (
215220
match Query.declaredForTip ~stamps:file.stamps stamp tip with
@@ -219,7 +224,7 @@ let definition ~file ~getModule stamp tip =
219224
let env = Query.fileEnv file in
220225
let uri = Query.getSourceUri ~env ~getModule declared.modulePath in
221226
maybeLog ("Inner uri " ^ Uri2.toString uri);
222-
Some (uri, loc))
227+
Some (uri, loc) )
223228

224229
let orLog message v =
225230
match v with
@@ -242,8 +247,8 @@ let definitionForLoc ~pathsForModule ~file ~getUri ~getModule loc =
242247
| None -> None
243248
| Some (file, _extra, declared) ->
244249
let loc = validateLoc declared.name.loc declared.extentLoc in
245-
Some (file.uri, loc))
246-
else None)
250+
Some (file.uri, loc) )
251+
else None )
247252
| Explanation _
248253
| Typed (_, NotFound)
249254
| LModule (NotFound | Definition (_, _))
@@ -258,16 +263,16 @@ let definitionForLoc ~pathsForModule ~file ~getUri ~getModule loc =
258263
|> orLog "No paths found" |?> getSrc |> orLog "No src found"
259264
with
260265
| None -> None
261-
| Some src -> Some (Uri2.fromPath src, Utils.topLoc src))
266+
| Some src -> Some (Uri2.fromPath src, Utils.topLoc src) )
262267
| LModule (LocalReference (stamp, tip))
263268
| Typed (_, LocalReference (stamp, tip)) ->
264269
maybeLog ("Local defn " ^ tipToString tip);
265270
definition ~file ~getModule stamp tip
266271
| LModule (GlobalReference (moduleName, path, tip))
267272
| Typed (_, GlobalReference (moduleName, path, tip)) -> (
268273
maybeLog
269-
("Global defn " ^ moduleName ^ " " ^ pathToString path ^ " : "
270-
^ tipToString tip);
274+
( "Global defn " ^ moduleName ^ " " ^ pathToString path ^ " : "
275+
^ tipToString tip );
271276
match getModule moduleName with
272277
| None -> None
273278
| Some file -> (
@@ -280,4 +285,4 @@ let definitionForLoc ~pathsForModule ~file ~getUri ~getModule loc =
280285
| Some stamp ->
281286
(* oooh wht do I do if the stamp is inside a pseudo-file? *)
282287
maybeLog ("Got stamp " ^ string_of_int stamp);
283-
definition ~file:env.file ~getModule stamp tip)))
288+
definition ~file:env.file ~getModule stamp tip ) ) )

test/src/expected/Hover.res.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ Hover src/Hover.res 33:4
2020
{"contents": "```rescript\nunit => int\n```\n\nDoc comment for functionWithTypeAnnotation"}
2121

2222
Hover src/Hover.res 37:13
23-
null
23+
{"contents": "```rescript\nstring\n```"}
2424

0 commit comments

Comments
 (0)