@@ -562,6 +562,7 @@ let completionForExporteds iterExported getDeclared ~prefix ~exact ~env
562
562
with
563
563
deprecated = declared.deprecated;
564
564
docstring = declared.docstring;
565
+ modulePath = ModulePath. toPathWithoutTip declared.modulePath;
565
566
}
566
567
:: ! res
567
568
| _ -> () );
@@ -1152,9 +1153,12 @@ let completionToItem {Completion.name; deprecated; docstring; kind} =
1152
1153
~deprecated ~detail: (detail name kind) ~docstring
1153
1154
1154
1155
let completionsGetTypeEnv = function
1155
- | {Completion. kind = Value typ ; env} :: _ -> Some (typ, env)
1156
- | {Completion. kind = ObjLabel typ ; env} :: _ -> Some (typ, env)
1157
- | {Completion. kind = Field ({typ} , _ ); env} :: _ -> Some (typ, env)
1156
+ | {Completion. kind = Value typ ; env; modulePath} :: _ ->
1157
+ Some (typ, env, modulePath)
1158
+ | {Completion. kind = ObjLabel typ ; env; modulePath} :: _ ->
1159
+ Some (typ, env, modulePath)
1160
+ | {Completion. kind = Field ({typ} , _ ); env; modulePath} :: _ ->
1161
+ Some (typ, env, modulePath)
1158
1162
| _ -> None
1159
1163
1160
1164
let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos
@@ -1185,7 +1189,7 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos
1185
1189
~env ~exact: true ~scope
1186
1190
|> completionsGetTypeEnv
1187
1191
with
1188
- | Some (typ , env ) -> (
1192
+ | Some (typ , env , modulePath ) -> (
1189
1193
let rec reconstructFunctionType args tRet =
1190
1194
match args with
1191
1195
| [] -> tRet
@@ -1216,7 +1220,10 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos
1216
1220
| args , tRet when args <> [] ->
1217
1221
let args = processApply args labels in
1218
1222
let retType = reconstructFunctionType args tRet in
1219
- [Completion. create ~name: " dummy" ~env ~kind: (Completion. Value retType)]
1223
+ [
1224
+ Completion. createWithModulePath ~name: " dummy" ~env
1225
+ ~kind: (Completion. Value retType) ~module Path;
1226
+ ]
1220
1227
| _ -> [] )
1221
1228
| None -> [])
1222
1229
| CPField (CPId (path , Module), fieldName ) ->
@@ -1231,19 +1238,20 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos
1231
1238
~env ~exact: true ~scope
1232
1239
|> completionsGetTypeEnv
1233
1240
with
1234
- | Some (typ , env ) -> (
1241
+ | Some (typ , env , modulePath ) -> (
1235
1242
match typ |> extractRecordType ~env ~package with
1236
1243
| Some (env , fields , typDecl ) ->
1237
1244
fields
1238
1245
|> Utils. filterMap (fun field ->
1239
1246
if checkName field.fname.txt ~prefix: fieldName ~exact then
1240
1247
Some
1241
- (Completion. create ~name: field.fname.txt ~env
1248
+ (Completion. createWithModulePath ~name: field.fname.txt ~env
1242
1249
~kind:
1243
1250
(Completion. Field
1244
1251
( field,
1245
1252
typDecl.item.decl
1246
- |> Shared. declToString typDecl.name.txt )))
1253
+ |> Shared. declToString typDecl.name.txt ))
1254
+ ~module Path)
1247
1255
else None )
1248
1256
| None -> [] )
1249
1257
| None -> [] )
@@ -1254,7 +1262,7 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos
1254
1262
~env ~exact: true ~scope
1255
1263
|> completionsGetTypeEnv
1256
1264
with
1257
- | Some (typ , env ) -> (
1265
+ | Some (typ , env , modulePath ) -> (
1258
1266
match typ |> extractObjectType ~env ~package with
1259
1267
| Some (env , tObj ) ->
1260
1268
let rec getFields (texp : Types.type_expr ) =
@@ -1270,8 +1278,8 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos
1270
1278
|> Utils. filterMap (fun (field , typ ) ->
1271
1279
if checkName field ~prefix: label ~exact then
1272
1280
Some
1273
- (Completion. create ~name: field ~env
1274
- ~kind: (Completion. ObjLabel typ))
1281
+ (Completion. createWithModulePath ~name: field ~env
1282
+ ~kind: (Completion. ObjLabel typ) ~module Path )
1275
1283
else None )
1276
1284
| None -> [] )
1277
1285
| None -> [] )
@@ -1282,7 +1290,7 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos
1282
1290
~env ~exact: true ~scope
1283
1291
|> completionsGetTypeEnv
1284
1292
with
1285
- | Some (typ , _envNotUsed ) -> (
1293
+ | Some (typ , env , completionItemModulePath ) -> (
1286
1294
let {
1287
1295
arrayModulePath;
1288
1296
optionModulePath;
@@ -1375,7 +1383,20 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos
1375
1383
env
1376
1384
(* Restore original env for the completion after x->foo()... *) ;
1377
1385
})
1378
- | [] -> [] )
1386
+ | [] ->
1387
+ let completions =
1388
+ completionItemModulePath @ [funNamePrefix]
1389
+ |> getCompletionsForPath ~completion Context:Value ~exact: false
1390
+ ~package ~opens ~all Files ~pos ~env ~scope
1391
+ in
1392
+ completions
1393
+ |> List. map (fun (completion : Completion.t ) ->
1394
+ {
1395
+ completion with
1396
+ name = completion.name;
1397
+ env
1398
+ (* Restore original env for the completion after x->foo()... *) ;
1399
+ }))
1379
1400
| None -> [] )
1380
1401
| None -> [] )
1381
1402
@@ -1438,7 +1459,7 @@ let processCompletable ~debug ~package ~scope ~env ~pos ~forHover
1438
1459
| Cjsx (componentPath , prefix , identsSeen ) ->
1439
1460
let labels =
1440
1461
match componentPath @ [" make" ] |> findTypeOfValue with
1441
- | Some (typ , make_env ) ->
1462
+ | Some (typ , make_env , _ ) ->
1442
1463
let rec getFieldsV3 (texp : Types.type_expr ) =
1443
1464
match texp.desc with
1444
1465
| Tfield (name , _ , t1 , t2 ) ->
@@ -1774,7 +1795,7 @@ Note: The `@react.component` decorator requires the react-jsx config to be set i
1774
1795
~env ~exact: true ~scope
1775
1796
|> completionsGetTypeEnv
1776
1797
with
1777
- | Some (typ , _env ) ->
1798
+ | Some (typ , _env , _ ) ->
1778
1799
if debug then
1779
1800
Printf. printf " Found type for function %s\n "
1780
1801
(typ |> Shared. typeToString);
0 commit comments