@@ -697,41 +697,48 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env ~exact
697
697
let package = full.package in
698
698
match contextPath with
699
699
| CPString ->
700
+ if Debug. verbose () then print_endline " [ctx_path]--> CPString" ;
700
701
[
701
702
Completion. create " dummy" ~env
702
703
~kind:
703
704
(Completion. Value
704
705
(Ctype. newconstr (Path. Pident (Ident. create " string" )) [] ));
705
706
]
706
707
| CPBool ->
708
+ if Debug. verbose () then print_endline " [ctx_path]--> CPBool" ;
707
709
[
708
710
Completion. create " dummy" ~env
709
711
~kind:
710
712
(Completion. Value
711
713
(Ctype. newconstr (Path. Pident (Ident. create " bool" )) [] ));
712
714
]
713
715
| CPInt ->
716
+ if Debug. verbose () then print_endline " [ctx_path]--> CPInt" ;
714
717
[
715
718
Completion. create " dummy" ~env
716
719
~kind:
717
720
(Completion. Value
718
721
(Ctype. newconstr (Path. Pident (Ident. create " int" )) [] ));
719
722
]
720
723
| CPFloat ->
724
+ if Debug. verbose () then print_endline " [ctx_path]--> CPFloat" ;
721
725
[
722
726
Completion. create " dummy" ~env
723
727
~kind:
724
728
(Completion. Value
725
729
(Ctype. newconstr (Path. Pident (Ident. create " float" )) [] ));
726
730
]
727
731
| CPArray None ->
732
+ if Debug. verbose () then print_endline " [ctx_path]--> CPArray (no payload)" ;
728
733
[
729
734
Completion. create " array" ~env
730
735
~kind:
731
736
(Completion. Value
732
737
(Ctype. newconstr (Path. Pident (Ident. create " array" )) [] ));
733
738
]
734
739
| CPArray (Some cp ) -> (
740
+ if Debug. verbose () then
741
+ print_endline " [ctx_path]--> CPArray (with payload)" ;
735
742
match mode with
736
743
| Regular -> (
737
744
match
@@ -757,6 +764,7 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env ~exact
757
764
(Ctype. newconstr (Path. Pident (Ident. create " array" )) [] ));
758
765
])
759
766
| CPOption cp -> (
767
+ if Debug. verbose () then print_endline " [ctx_path]--> CPOption" ;
760
768
match
761
769
cp
762
770
|> getCompletionsForContextPath ~debug ~full ~opens ~raw Opens ~pos ~env
@@ -771,6 +779,7 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env ~exact
771
779
(Completion. ExtractedType (Toption (env, ExtractedType typ), `Type ));
772
780
])
773
781
| CPAwait cp -> (
782
+ if Debug. verbose () then print_endline " [ctx_path]--> CPAwait" ;
774
783
match
775
784
cp
776
785
|> getCompletionsForContextPath ~debug ~full ~opens ~raw Opens ~pos ~env
@@ -781,10 +790,12 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env ~exact
781
790
[Completion. create " dummy" ~env ~kind: (Completion. Value typ)]
782
791
| _ -> [] )
783
792
| CPId (path , completionContext ) ->
793
+ if Debug. verbose () then print_endline " [ctx_path]--> CPId" ;
784
794
path
785
795
|> getCompletionsForPath ~debug ~opens ~full ~pos ~exact ~completion Context
786
796
~env ~scope
787
797
| CPApply (cp , labels ) -> (
798
+ if Debug. verbose () then print_endline " [ctx_path]--> CPApply" ;
788
799
match
789
800
cp
790
801
|> getCompletionsForContextPath ~debug ~full ~opens ~raw Opens ~pos ~env
@@ -826,11 +837,13 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env ~exact
826
837
| _ -> [] )
827
838
| _ -> [])
828
839
| CPField (CPId (path , Module), fieldName ) ->
840
+ if Debug. verbose () then print_endline " [ctx_path]--> CPField: M.field" ;
829
841
(* M.field *)
830
842
path @ [fieldName]
831
843
|> getCompletionsForPath ~debug ~opens ~full ~pos ~exact
832
844
~completion Context:Field ~env ~scope
833
845
| CPField (cp , fieldName ) -> (
846
+ if Debug. verbose () then print_endline " [ctx_path]--> CPField" ;
834
847
let completionsForCtxPath =
835
848
cp
836
849
|> getCompletionsForContextPath ~debug ~full ~opens ~raw Opens ~pos ~env
@@ -869,6 +882,7 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env ~exact
869
882
else None ))
870
883
| CPObj (cp , label ) -> (
871
884
(* TODO: Also needs to support ExtractedType *)
885
+ if Debug. verbose () then print_endline " [ctx_path]--> CPObj" ;
872
886
match
873
887
cp
874
888
|> getCompletionsForContextPath ~debug ~full ~opens ~raw Opens ~pos ~env
@@ -896,6 +910,7 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env ~exact
896
910
| None -> [] )
897
911
| None -> [] )
898
912
| CPPipe {contextPath = cp ; id = funNamePrefix ; lhsLoc; inJsx} -> (
913
+ if Debug. verbose () then print_endline " [ctx_path]--> CPPipe" ;
899
914
match
900
915
cp
901
916
|> getCompletionsForContextPath ~debug ~full ~opens ~raw Opens ~pos ~env
@@ -1008,6 +1023,7 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env ~exact
1008
1023
| _ -> completions)
1009
1024
| None -> [] ))
1010
1025
| CTuple ctxPaths ->
1026
+ if Debug. verbose () then print_endline " [ctx_path]--> CTuple" ;
1011
1027
(* Turn a list of context paths into a list of type expressions. *)
1012
1028
let typeExrps =
1013
1029
ctxPaths
@@ -1027,6 +1043,7 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env ~exact
1027
1043
]
1028
1044
else []
1029
1045
| CJsxPropValue {pathToComponent; propName} -> (
1046
+ if Debug. verbose () then print_endline " [ctx_path]--> CJsxPropValue" ;
1030
1047
let findTypeOfValue path =
1031
1048
path
1032
1049
|> getCompletionsForPath ~debug ~completion Context:Value ~exact: true
@@ -1038,6 +1055,7 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env ~exact
1038
1055
| [elName] when Char. lowercase_ascii elName.[0 ] = elName.[0 ] -> true
1039
1056
| _ -> false
1040
1057
in
1058
+ (* TODO(env-stuff) Does this need to potentially be instantiated with type args too? *)
1041
1059
let targetLabel =
1042
1060
if lowercaseComponent then
1043
1061
let rec digToTypeForCompletion path =
@@ -1072,6 +1090,7 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env ~exact
1072
1090
~kind: (Completion. Value (Utils. unwrapIfOption typ));
1073
1091
])
1074
1092
| CArgument {functionContextPath; argumentLabel} -> (
1093
+ if Debug. verbose () then print_endline " [ctx_path]--> CArgument" ;
1075
1094
if Debug. verbose () then
1076
1095
Printf. printf " --> function argument: %s\n "
1077
1096
(match argumentLabel with
@@ -1124,6 +1143,7 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env ~exact
1124
1143
(if expandOption then Utils. unwrapIfOption typ else typ));
1125
1144
])
1126
1145
| CPatternPath {rootCtxPath; nested} -> (
1146
+ if Debug. verbose () then print_endline " [ctx_path]--> CPatternPath" ;
1127
1147
(* TODO(env-stuff) Get rid of innerType etc *)
1128
1148
match
1129
1149
rootCtxPath
@@ -1138,6 +1158,7 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env ~exact
1138
1158
| None -> [] )
1139
1159
| None -> [] )
1140
1160
| CTypeAtPos loc -> (
1161
+ if Debug. verbose () then print_endline " [ctx_path]--> CTypeAtPos" ;
1141
1162
match
1142
1163
References. getLocItem ~full ~pos: (Pos. ofLexing loc.loc_start) ~debug
1143
1164
with
@@ -1872,6 +1893,22 @@ let rec processCompletable ~debug ~full ~scope ~env ~pos ~forHover completable =
1872
1893
fallbackOrEmpty ~items () )
1873
1894
| None -> fallbackOrEmpty () )
1874
1895
| Cexpression {contextPath; prefix; nested} -> (
1896
+ let isAmbigiousRecordBodyOrJsxWrap =
1897
+ match (contextPath, nested) with
1898
+ | CJsxPropValue _ , [NRecordBody _] -> true
1899
+ | _ -> false
1900
+ in
1901
+ if Debug. verbose () then
1902
+ (* This happens in this scenario: `<SomeComponent someProp={<com>}`
1903
+ Here, we don't know whether `{}` is just wraps for the type of
1904
+ `someProp`, or if it's a record body where we want to complete
1905
+ for the fields in the record. We need to look up what the type is
1906
+ first before deciding what completions to show. So we do that here.*)
1907
+ if isAmbigiousRecordBodyOrJsxWrap then
1908
+ print_endline
1909
+ " [process_completable]--> Cexpression special case: JSX prop value \
1910
+ that might be record body or JSX wrap"
1911
+ else print_endline " [process_completable]--> Cexpression" ;
1875
1912
(* Completions for local things like variables in scope, modules in the
1876
1913
project, etc. We only add completions when there's a prefix of some sort
1877
1914
we can filter on, since we know we're in some sort of context, and
@@ -1890,17 +1927,32 @@ let rec processCompletable ~debug ~full ~scope ~env ~pos ~forHover completable =
1890
1927
with
1891
1928
| None ->
1892
1929
if Debug. verbose () then
1893
- print_endline " --> could not get completions for context path" ;
1930
+ print_endline
1931
+ " [process_completable]--> could not get completions for context path" ;
1894
1932
regularCompletions
1895
1933
| Some (typ , env ) -> (
1896
1934
match typ |> TypeUtils. resolveNested ~env ~full ~nested with
1897
1935
| None ->
1898
1936
if Debug. verbose () then
1899
- print_endline " --> could not resolve nested expression path" ;
1900
- regularCompletions
1937
+ print_endline
1938
+ " [process_completable]--> could not resolve nested expression path" ;
1939
+ if isAmbigiousRecordBodyOrJsxWrap then (
1940
+ if Debug. verbose () then
1941
+ print_endline
1942
+ " [process_completable]--> case is ambigious Jsx prop vs record \
1943
+ body case, complete also for the JSX prop value directly" ;
1944
+ let itemsForRawJsxPropValue =
1945
+ typ
1946
+ |> completeTypedValue ~raw Opens ~mode: Expression ~full ~prefix
1947
+ ~completion Context:None
1948
+ in
1949
+ itemsForRawJsxPropValue @ regularCompletions)
1950
+ else regularCompletions
1901
1951
| Some (typ , _env , completionContext , typeArgContext ) -> (
1902
1952
if Debug. verbose () then
1903
- print_endline " --> found type in nested expression completion" ;
1953
+ print_endline
1954
+ " [process_completable]--> found type in nested expression \
1955
+ completion" ;
1904
1956
(* Wrap the insert text in braces when we're completing the root of a
1905
1957
JSX prop value. *)
1906
1958
let wrapInsertTextInBraces =
0 commit comments