@@ -1157,8 +1157,17 @@ let completionsGetTypeEnv = function
1157
1157
| {Completion. kind = Field ({typ} , _ ); env} :: _ -> Some (typ, env)
1158
1158
| _ -> None
1159
1159
1160
- let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos
1161
- ~env ~exact ~scope (contextPath : Completable.contextPath ) =
1160
+ let findReturnTypeOfFunctionAtLoc loc ~(env : QueryEnv.t ) ~full ~debug =
1161
+ match References. getLocItem ~full ~pos: (loc |> Loc. end_) ~debug with
1162
+ | Some {locType = Typed (_ , typExpr , _ )} -> (
1163
+ match extractFunctionType ~env ~package: full.package typExpr with
1164
+ | args , tRet when args <> [] -> Some tRet
1165
+ | _ -> None )
1166
+ | _ -> None
1167
+
1168
+ let rec getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env
1169
+ ~exact ~scope (contextPath : Completable.contextPath ) =
1170
+ let package = full.package in
1162
1171
match contextPath with
1163
1172
| CPString ->
1164
1173
[
@@ -1181,8 +1190,8 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos
1181
1190
| CPApply (cp , labels ) -> (
1182
1191
match
1183
1192
cp
1184
- |> getCompletionsForContextPath ~package ~opens ~raw Opens ~all Files ~pos
1185
- ~env ~ exact:true ~scope
1193
+ |> getCompletionsForContextPath ~full ~opens ~raw Opens ~all Files ~pos ~env
1194
+ ~exact: true ~scope
1186
1195
|> completionsGetTypeEnv
1187
1196
with
1188
1197
| Some (typ , env ) -> (
@@ -1227,8 +1236,8 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos
1227
1236
| CPField (cp , fieldName ) -> (
1228
1237
match
1229
1238
cp
1230
- |> getCompletionsForContextPath ~package ~opens ~raw Opens ~all Files ~pos
1231
- ~env ~ exact:true ~scope
1239
+ |> getCompletionsForContextPath ~full ~opens ~raw Opens ~all Files ~pos ~env
1240
+ ~exact: true ~scope
1232
1241
|> completionsGetTypeEnv
1233
1242
with
1234
1243
| Some (typ , env ) -> (
@@ -1250,8 +1259,8 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos
1250
1259
| CPObj (cp , label ) -> (
1251
1260
match
1252
1261
cp
1253
- |> getCompletionsForContextPath ~package ~opens ~raw Opens ~all Files ~pos
1254
- ~env ~ exact:true ~scope
1262
+ |> getCompletionsForContextPath ~full ~opens ~raw Opens ~all Files ~pos ~env
1263
+ ~exact: true ~scope
1255
1264
|> completionsGetTypeEnv
1256
1265
with
1257
1266
| Some (typ , env ) -> (
@@ -1275,14 +1284,28 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos
1275
1284
else None )
1276
1285
| None -> [] )
1277
1286
| None -> [] )
1278
- | CPPipe ( cp , funNamePrefix ) -> (
1287
+ | CPPipe { contextPath = cp ; id = funNamePrefix ; lhsLoc} -> (
1279
1288
match
1280
1289
cp
1281
- |> getCompletionsForContextPath ~package ~opens ~raw Opens ~all Files ~pos
1282
- ~env ~ exact:true ~scope
1290
+ |> getCompletionsForContextPath ~full ~opens ~raw Opens ~all Files ~pos ~env
1291
+ ~exact: true ~scope
1283
1292
|> completionsGetTypeEnv
1284
1293
with
1285
1294
| Some (typ , envFromCompletionItem ) -> (
1295
+ (* If the type we're completing on is a type parameter, we won't be able to do
1296
+ completion unless we know what that type parameter is compiled as. This
1297
+ attempts to look up the compiled type for that type parameter by looking
1298
+ for compiled information at the loc of that expression. *)
1299
+ let typ =
1300
+ match typ with
1301
+ | {Types. desc = Tvar _ } -> (
1302
+ match
1303
+ findReturnTypeOfFunctionAtLoc lhsLoc ~env ~full ~debug: false
1304
+ with
1305
+ | None -> typ
1306
+ | Some typFromLoc -> typFromLoc)
1307
+ | _ -> typ
1308
+ in
1286
1309
let {
1287
1310
arrayModulePath;
1288
1311
optionModulePath;
@@ -1418,8 +1441,9 @@ let getOpens ~debug ~rawOpens ~package ~env =
1418
1441
(* Last open takes priority *)
1419
1442
List. rev resolvedOpens
1420
1443
1421
- let processCompletable ~debug ~package ~scope ~env ~pos ~forHover
1444
+ let processCompletable ~debug ~full ~scope ~env ~pos ~forHover
1422
1445
(completable : Completable.t ) =
1446
+ let package = full.package in
1423
1447
let rawOpens = Scope. getRawOpens scope in
1424
1448
let opens = getOpens ~debug ~raw Opens ~package ~env in
1425
1449
let allFiles = FileSet. union package.projectFiles package.dependenciesFiles in
@@ -1433,8 +1457,8 @@ let processCompletable ~debug ~package ~scope ~env ~pos ~forHover
1433
1457
| Cnone -> []
1434
1458
| Cpath contextPath ->
1435
1459
contextPath
1436
- |> getCompletionsForContextPath ~package ~opens ~raw Opens ~all Files ~pos
1437
- ~env ~ exact: forHover ~scope
1460
+ |> getCompletionsForContextPath ~full ~opens ~raw Opens ~all Files ~pos ~env
1461
+ ~exact: forHover ~scope
1438
1462
| Cjsx ([id ], prefix , identsSeen ) when String. uncapitalize_ascii id = id ->
1439
1463
let mkLabel (name , typString ) =
1440
1464
Completion. create ~name ~kind: (Label typString) ~env
@@ -1783,7 +1807,7 @@ Note: The `@react.component` decorator requires the react-jsx config to be set i
1783
1807
let labels =
1784
1808
match
1785
1809
cp
1786
- |> getCompletionsForContextPath ~package ~opens ~raw Opens ~all Files ~pos
1810
+ |> getCompletionsForContextPath ~full ~opens ~raw Opens ~all Files ~pos
1787
1811
~env ~exact: true ~scope
1788
1812
|> completionsGetTypeEnv
1789
1813
with
0 commit comments