@@ -562,6 +562,7 @@ let completionForExporteds iterExported getDeclared ~prefix ~exact ~env
562562 with
563563 deprecated = declared.deprecated;
564564 docstring = declared.docstring;
565+ modulePath = ModulePath. toPathWithoutTip declared.modulePath;
565566 }
566567 :: ! res
567568 | _ -> () );
@@ -1152,9 +1153,12 @@ let completionToItem {Completion.name; deprecated; docstring; kind} =
11521153 ~deprecated ~detail: (detail name kind) ~docstring
11531154
11541155let 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)
11581162 | _ -> None
11591163
11601164let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos
@@ -1185,7 +1189,7 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos
11851189 ~env ~exact: true ~scope
11861190 |> completionsGetTypeEnv
11871191 with
1188- | Some (typ , env ) -> (
1192+ | Some (typ , env , modulePath ) -> (
11891193 let rec reconstructFunctionType args tRet =
11901194 match args with
11911195 | [] -> tRet
@@ -1216,7 +1220,10 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos
12161220 | args , tRet when args <> [] ->
12171221 let args = processApply args labels in
12181222 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+ ]
12201227 | _ -> [] )
12211228 | None -> [])
12221229 | CPField (CPId (path , Module), fieldName ) ->
@@ -1231,19 +1238,20 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos
12311238 ~env ~exact: true ~scope
12321239 |> completionsGetTypeEnv
12331240 with
1234- | Some (typ , env ) -> (
1241+ | Some (typ , env , modulePath ) -> (
12351242 match typ |> extractRecordType ~env ~package with
12361243 | Some (env , fields , typDecl ) ->
12371244 fields
12381245 |> Utils. filterMap (fun field ->
12391246 if checkName field.fname.txt ~prefix: fieldName ~exact then
12401247 Some
1241- (Completion. create ~name: field.fname.txt ~env
1248+ (Completion. createWithModulePath ~name: field.fname.txt ~env
12421249 ~kind:
12431250 (Completion. Field
12441251 ( field,
12451252 typDecl.item.decl
1246- |> Shared. declToString typDecl.name.txt )))
1253+ |> Shared. declToString typDecl.name.txt ))
1254+ ~module Path)
12471255 else None )
12481256 | None -> [] )
12491257 | None -> [] )
@@ -1254,7 +1262,7 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos
12541262 ~env ~exact: true ~scope
12551263 |> completionsGetTypeEnv
12561264 with
1257- | Some (typ , env ) -> (
1265+ | Some (typ , env , modulePath ) -> (
12581266 match typ |> extractObjectType ~env ~package with
12591267 | Some (env , tObj ) ->
12601268 let rec getFields (texp : Types.type_expr ) =
@@ -1270,8 +1278,8 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos
12701278 |> Utils. filterMap (fun (field , typ ) ->
12711279 if checkName field ~prefix: label ~exact then
12721280 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 )
12751283 else None )
12761284 | None -> [] )
12771285 | None -> [] )
@@ -1282,7 +1290,7 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos
12821290 ~env ~exact: true ~scope
12831291 |> completionsGetTypeEnv
12841292 with
1285- | Some (typ , _envNotUsed ) -> (
1293+ | Some (typ , env , completionItemModulePath ) -> (
12861294 let {
12871295 arrayModulePath;
12881296 optionModulePath;
@@ -1375,7 +1383,20 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos
13751383 env
13761384 (* Restore original env for the completion after x->foo()... *) ;
13771385 })
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+ }))
13791400 | None -> [] )
13801401 | None -> [] )
13811402
@@ -1438,7 +1459,7 @@ let processCompletable ~debug ~package ~scope ~env ~pos ~forHover
14381459 | Cjsx (componentPath , prefix , identsSeen ) ->
14391460 let labels =
14401461 match componentPath @ [" make" ] |> findTypeOfValue with
1441- | Some (typ , make_env ) ->
1462+ | Some (typ , make_env , _ ) ->
14421463 let rec getFieldsV3 (texp : Types.type_expr ) =
14431464 match texp.desc with
14441465 | Tfield (name , _ , t1 , t2 ) ->
@@ -1774,7 +1795,7 @@ Note: The `@react.component` decorator requires the react-jsx config to be set i
17741795 ~env ~exact: true ~scope
17751796 |> completionsGetTypeEnv
17761797 with
1777- | Some (typ , _env ) ->
1798+ | Some (typ , _env , _ ) ->
17781799 if debug then
17791800 Printf. printf " Found type for function %s\n "
17801801 (typ |> Shared. typeToString);
0 commit comments