@@ -756,18 +756,12 @@ let rec getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env
756
756
| Lazy -> [" Lazy" ]
757
757
| Char -> [" Char" ])
758
758
| 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
765
759
match t.Types. desc with
766
760
| Tconstr (path, _typeArgs, _)
767
761
| Tlink {desc = Tconstr (path, _typeArgs, _)}
768
762
| Tsubst {desc = Tconstr (path, _typeArgs, _)}
769
763
| Tpoly ({desc = Tconstr (path , _typeArgs , _ )} , [] ) -> (
770
- match expandPath path with
764
+ match Utils. expandPath path with
771
765
| _ :: pathRev ->
772
766
(* type path is relative to the completion environment
773
767
express it from the root of the file *)
@@ -882,10 +876,33 @@ let rec getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env
882
876
~opens ~all Files ~pos ~env ~scope
883
877
|> completionsGetTypeEnv
884
878
in
879
+ let isBuiltin =
880
+ match pathToComponent with
881
+ | [elName] when Char. lowercase_ascii elName.[0 ] = elName.[0 ] -> true
882
+ | _ -> false
883
+ in
885
884
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)
889
906
in
890
907
match targetLabel with
891
908
| None -> []
0 commit comments