@@ -756,18 +756,12 @@ let rec getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env
756756 | Lazy -> [" Lazy" ]
757757 | Char -> [" Char" ])
758758 | TypExpr t -> (
759- let rec expandPath (path : Path.t ) =
760- match path with
761- | Pident id -> [Ident. name id]
762- | Pdot (p , s , _ ) -> s :: expandPath p
763- | Papply _ -> []
764- in
765759 match t.Types. desc with
766760 | Tconstr (path, _typeArgs, _)
767761 | Tlink {desc = Tconstr (path, _typeArgs, _)}
768762 | Tsubst {desc = Tconstr (path, _typeArgs, _)}
769763 | Tpoly ({desc = Tconstr (path , _typeArgs , _ )} , [] ) -> (
770- match expandPath path with
764+ match Utils. expandPath path with
771765 | _ :: pathRev ->
772766 (* type path is relative to the completion environment
773767 express it from the root of the file *)
@@ -882,10 +876,33 @@ let rec getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env
882876 ~opens ~all Files ~pos ~env ~scope
883877 |> completionsGetTypeEnv
884878 in
879+ let isBuiltin =
880+ match pathToComponent with
881+ | [elName] when Char. lowercase_ascii elName.[0 ] = elName.[0 ] -> true
882+ | _ -> false
883+ in
885884 let targetLabel =
886- CompletionJsx. getJsxLabels ~component Path:pathToComponent ~find TypeOfValue
887- ~package
888- |> List. find_opt (fun (label , _ , _ ) -> label = propName)
885+ if isBuiltin then
886+ let rec digToTypeForCompletion path ~env =
887+ match
888+ path
889+ |> getCompletionsForPath ~completion Context:Type ~exact: true
890+ ~package ~opens ~all Files ~pos ~env ~scope
891+ with
892+ | {kind = Type {kind = Abstract (Some (p , _ ))} ; env} :: _ ->
893+ let pathRev = p |> Utils. expandPath in
894+ pathRev |> List. rev |> digToTypeForCompletion ~env
895+ | {kind = Type {kind = Record fields } ; env} :: _ -> (
896+ match fields |> List. find_opt (fun f -> f.fname.txt = propName) with
897+ | None -> None
898+ | Some f -> Some (f.fname.txt, f.typ, env))
899+ | _ -> None
900+ in
901+ [" ReactDOM" ; " domProps" ] |> digToTypeForCompletion ~env
902+ else
903+ CompletionJsx. getJsxLabels ~component Path:pathToComponent
904+ ~find TypeOfValue ~package
905+ |> List. find_opt (fun (label , _ , _ ) -> label = propName)
889906 in
890907 match targetLabel with
891908 | None -> []
0 commit comments