@@ -1157,8 +1157,17 @@ let completionsGetTypeEnv = function
11571157 | {Completion. kind = Field ({typ} , _ ); env} :: _ -> Some (typ, env)
11581158 | _ -> None
11591159
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
11621171 match contextPath with
11631172 | CPString ->
11641173 [
@@ -1181,8 +1190,8 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos
11811190 | CPApply (cp , labels ) -> (
11821191 match
11831192 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
11861195 |> completionsGetTypeEnv
11871196 with
11881197 | Some (typ , env ) -> (
@@ -1227,8 +1236,8 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos
12271236 | CPField (cp , fieldName ) -> (
12281237 match
12291238 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
12321241 |> completionsGetTypeEnv
12331242 with
12341243 | Some (typ , env ) -> (
@@ -1250,8 +1259,8 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos
12501259 | CPObj (cp , label ) -> (
12511260 match
12521261 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
12551264 |> completionsGetTypeEnv
12561265 with
12571266 | Some (typ , env ) -> (
@@ -1275,14 +1284,28 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos
12751284 else None )
12761285 | None -> [] )
12771286 | None -> [] )
1278- | CPPipe ( cp , funNamePrefix ) -> (
1287+ | CPPipe { contextPath = cp ; id = funNamePrefix ; lhsLoc} -> (
12791288 match
12801289 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
12831292 |> completionsGetTypeEnv
12841293 with
12851294 | 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
12861309 let {
12871310 arrayModulePath;
12881311 optionModulePath;
@@ -1418,8 +1441,9 @@ let getOpens ~debug ~rawOpens ~package ~env =
14181441 (* Last open takes priority *)
14191442 List. rev resolvedOpens
14201443
1421- let processCompletable ~debug ~package ~scope ~env ~pos ~forHover
1444+ let processCompletable ~debug ~full ~scope ~env ~pos ~forHover
14221445 (completable : Completable.t ) =
1446+ let package = full.package in
14231447 let rawOpens = Scope. getRawOpens scope in
14241448 let opens = getOpens ~debug ~raw Opens ~package ~env in
14251449 let allFiles = FileSet. union package.projectFiles package.dependenciesFiles in
@@ -1433,8 +1457,8 @@ let processCompletable ~debug ~package ~scope ~env ~pos ~forHover
14331457 | Cnone -> []
14341458 | Cpath contextPath ->
14351459 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
14381462 | Cjsx ([id ], prefix , identsSeen ) when String. uncapitalize_ascii id = id ->
14391463 let mkLabel (name , typString ) =
14401464 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
17831807 let labels =
17841808 match
17851809 cp
1786- |> getCompletionsForContextPath ~package ~opens ~raw Opens ~all Files ~pos
1810+ |> getCompletionsForContextPath ~full ~opens ~raw Opens ~all Files ~pos
17871811 ~env ~exact: true ~scope
17881812 |> completionsGetTypeEnv
17891813 with
0 commit comments