@@ -19,11 +19,16 @@ let locsForPos ~extra pos =
19
19
20
20
let locForPos ~extra pos =
21
21
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
22
27
| [
23
28
(loc1, Typed (_, LocalReference _));
24
29
(loc2, Typed (_, GlobalReference (" Js_OO" , Tip " unsafe_downgrade" , _)));
25
30
((loc3, _) as l3);
26
- ]
31
+ ] (* For older compiler 9.0 or earlier *)
27
32
when loc1 = loc2 && loc2 = loc3 ->
28
33
(* JSX and compiler combined: *)
29
34
(* ~x becomes Js_OO.unsafe_downgrade(Props)#x *)
@@ -47,18 +52,18 @@ let definedForLoc ~file ~getModule locKind =
47
52
| Constructor name -> (
48
53
match Query. getConstructor file stamp name with
49
54
| None -> None
50
- | Some constructor -> Some ([] , `Constructor constructor))
55
+ | Some constructor -> Some ([] , `Constructor constructor) )
51
56
| Field name -> (
52
57
match Query. getField file stamp name with
53
58
| None -> None
54
- | Some field -> Some ([] , `Field field))
59
+ | Some field -> Some ([] , `Field field) )
55
60
| _ -> (
56
61
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 );
59
64
match Query. declaredForTip ~stamps: file.stamps stamp tip with
60
65
| None -> None
61
- | Some declared -> Some (declared.docstring, `Declared ))
66
+ | Some declared -> Some (declared.docstring, `Declared ) )
62
67
in
63
68
match locKind with
64
69
| NotFound -> None
@@ -90,7 +95,7 @@ let definedForLoc ~file ~getModule locKind =
90
95
None
91
96
| Some res ->
92
97
maybeLog " Yes!! got it" ;
93
- Some res))) )
98
+ Some res ) ) ) )
94
99
95
100
let alternateDeclared ~file ~pathsForModule ~getUri declared tip =
96
101
match Hashtbl. find_opt pathsForModule file.moduleName with
@@ -113,7 +118,7 @@ let alternateDeclared ~file ~pathsForModule ~getUri declared tip =
113
118
~exported: file.contents.exported declared.name.txt tip
114
119
with
115
120
| None -> None
116
- | Some declared -> Some (file, extra, declared))
121
+ | Some declared -> Some (file, extra, declared) )
117
122
else
118
123
match getUri intfUri with
119
124
| Error e ->
@@ -125,8 +130,8 @@ let alternateDeclared ~file ~pathsForModule ~getUri declared tip =
125
130
~exported: file.contents.exported declared.name.txt tip
126
131
with
127
132
| None -> None
128
- | Some declared -> Some (file, extra, declared)) )
129
- | _ -> None )
133
+ | Some declared -> Some (file, extra, declared) ) )
134
+ | _ -> None )
130
135
131
136
let resolveModuleReference ~file ~getModule (declared : moduleKind declared ) =
132
137
match declared.item with
@@ -143,7 +148,7 @@ let resolveModuleReference ~file ~getModule (declared : moduleKind declared) =
143
148
| None -> None
144
149
| Some md ->
145
150
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))) *) ) )
147
152
| `Global (moduleName , path ) -> (
148
153
match getModule moduleName with
149
154
| None -> None
@@ -160,20 +165,20 @@ let resolveModuleReference ~file ~getModule (declared : moduleKind declared) =
160
165
| Some md ->
161
166
Some (env.file, Some md)
162
167
(* Some((env.file.uri, validateLoc(md.name.loc, md.extentLoc))) *)
163
- ))) )
168
+ ) ) ) )
164
169
| `Stamp stamp -> (
165
170
match Hashtbl. find_opt file.stamps.modules stamp with
166
171
| None -> None
167
172
| Some md ->
168
173
Some (file, Some md)
169
- (* Some((file.uri, validateLoc(md.name.loc, md.extentLoc))) *) )
174
+ (* Some((file.uri, validateLoc(md.name.loc, md.extentLoc))) *) )
170
175
| `GlobalMod name -> (
171
176
match getModule name with
172
177
| None -> None
173
178
| Some file ->
174
179
(* maybeLog("Congrats, found a global mod"); *)
175
- Some (file, None ))
176
- | _ -> None )
180
+ Some (file, None ) )
181
+ | _ -> None )
177
182
178
183
let validateLoc (loc : Location.t ) (backup : Location.t ) =
179
184
if loc.loc_start.pos_cnum = - 1 then
@@ -198,18 +203,18 @@ let resolveModuleDefinition ~file ~getModule stamp =
198
203
| None -> Utils. topLoc (Uri2. toPath file.uri)
199
204
| Some declared -> validateLoc declared.name.loc declared.extentLoc
200
205
in
201
- Some (file.uri, loc))
206
+ Some (file.uri, loc) )
202
207
203
208
let definition ~file ~getModule stamp tip =
204
209
match tip with
205
210
| Constructor name -> (
206
211
match Query. getConstructor file stamp name with
207
212
| None -> None
208
- | Some constructor -> Some (file.uri, constructor.cname.loc))
213
+ | Some constructor -> Some (file.uri, constructor.cname.loc) )
209
214
| Field name -> (
210
215
match Query. getField file stamp name with
211
216
| None -> None
212
- | Some field -> Some (file.uri, field.fname.loc))
217
+ | Some field -> Some (file.uri, field.fname.loc) )
213
218
| Module -> resolveModuleDefinition ~file ~get Module stamp
214
219
| _ -> (
215
220
match Query. declaredForTip ~stamps: file.stamps stamp tip with
@@ -219,7 +224,7 @@ let definition ~file ~getModule stamp tip =
219
224
let env = Query. fileEnv file in
220
225
let uri = Query. getSourceUri ~env ~get Module declared.modulePath in
221
226
maybeLog (" Inner uri " ^ Uri2. toString uri);
222
- Some (uri, loc))
227
+ Some (uri, loc) )
223
228
224
229
let orLog message v =
225
230
match v with
@@ -242,8 +247,8 @@ let definitionForLoc ~pathsForModule ~file ~getUri ~getModule loc =
242
247
| None -> None
243
248
| Some (file , _extra , declared ) ->
244
249
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 )
247
252
| Explanation _
248
253
| Typed (_, NotFound )
249
254
| LModule (NotFound | Definition (_, _))
@@ -258,16 +263,16 @@ let definitionForLoc ~pathsForModule ~file ~getUri ~getModule loc =
258
263
|> orLog " No paths found" |?> getSrc |> orLog " No src found"
259
264
with
260
265
| None -> None
261
- | Some src -> Some (Uri2. fromPath src, Utils. topLoc src))
266
+ | Some src -> Some (Uri2. fromPath src, Utils. topLoc src) )
262
267
| LModule (LocalReference (stamp, tip))
263
268
| Typed (_ , LocalReference (stamp , tip )) ->
264
269
maybeLog (" Local defn " ^ tipToString tip);
265
270
definition ~file ~get Module stamp tip
266
271
| LModule (GlobalReference (moduleName, path, tip))
267
272
| Typed (_ , GlobalReference (moduleName , path , tip )) -> (
268
273
maybeLog
269
- (" Global defn " ^ moduleName ^ " " ^ pathToString path ^ " : "
270
- ^ tipToString tip);
274
+ ( " Global defn " ^ moduleName ^ " " ^ pathToString path ^ " : "
275
+ ^ tipToString tip );
271
276
match getModule moduleName with
272
277
| None -> None
273
278
| Some file -> (
@@ -280,4 +285,4 @@ let definitionForLoc ~pathsForModule ~file ~getUri ~getModule loc =
280
285
| Some stamp ->
281
286
(* oooh wht do I do if the stamp is inside a pseudo-file? *)
282
287
maybeLog (" Got stamp " ^ string_of_int stamp);
283
- definition ~file: env.file ~get Module stamp tip)) )
288
+ definition ~file: env.file ~get Module stamp tip ) ) )
0 commit comments