@@ -993,6 +993,105 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env ~exact
993
993
path @ [fieldName]
994
994
|> getCompletionsForPath ~debug ~opens ~full ~pos ~exact
995
995
~completion Context:Field ~env ~scope
996
+ | CPField {contextPath = cp ; fieldName; fieldNameLoc} when Debug. verbose () ->
997
+ (* TODO: this should only happen when the dot completion is at the end of the path *)
998
+ if Debug. verbose () then print_endline " [ctx_path]--> dot completion!" ;
999
+ let completionsForCtxPath =
1000
+ cp
1001
+ |> getCompletionsForContextPath ~debug ~full ~opens ~raw Opens ~pos ~env
1002
+ ~exact: true ~scope
1003
+ |> completionsGetTypeEnv2 ~debug ~full ~opens ~raw Opens ~pos
1004
+ in
1005
+ (* These are the main completions for the dot. *)
1006
+ let mainCompletions =
1007
+ match completionsForCtxPath with
1008
+ | Some (typ, env)
1009
+ when typ |> TypeUtils. extractObjectType ~env ~package |> Option. is_some
1010
+ ->
1011
+ (* Handle obj completion via dot *)
1012
+ if Debug. verbose () then
1013
+ Printf. printf " [dot_completion]--> Obj type found:\n " ;
1014
+ let objEnv, obj =
1015
+ typ |> TypeUtils. extractObjectType ~env ~package |> Option. get
1016
+ in
1017
+ obj |> TypeUtils. getObjFields
1018
+ |> Utils. filterMap (fun (field , typ ) ->
1019
+ if Utils. checkName field ~prefix: fieldName ~exact then
1020
+ let fullObjFieldName = Printf. sprintf " [\" %s\" ]" field in
1021
+ Some
1022
+ (Completion. create fullObjFieldName ~range: fieldNameLoc
1023
+ ~insert Text:fullObjFieldName ~env: objEnv
1024
+ ~kind: (Completion. ObjLabel typ))
1025
+ else None )
1026
+ | Some (typ, env)
1027
+ when typ |> TypeUtils. extractRecordType ~env ~package |> Option. is_some
1028
+ ->
1029
+ let env, fields, decl, _path, _attributes =
1030
+ typ |> TypeUtils. extractRecordType ~env ~package |> Option. get
1031
+ in
1032
+ if Debug. verbose () then
1033
+ Printf. printf " [dot_completion]--> Record type found\n " ;
1034
+ let recordAsString =
1035
+ decl.item.decl |> Shared. declToString decl.name.txt
1036
+ in
1037
+ fields
1038
+ |> Utils. filterMap (fun field ->
1039
+ if Utils. checkName field.fname.txt ~prefix: fieldName ~exact then
1040
+ Some
1041
+ (Completion. create field.fname.txt ~env
1042
+ ?deprecated:field.deprecated ~docstring: field.docstring
1043
+ ~kind: (Completion. Field (field, recordAsString)))
1044
+ else None )
1045
+ | Some (_typ , _env ) ->
1046
+ (* No more primary completions, for now. *)
1047
+ []
1048
+ | None -> []
1049
+ in
1050
+ let pipeCompletions =
1051
+ match completionsForCtxPath with
1052
+ | None -> []
1053
+ | Some (typ , envFromCompletionItem ) -> (
1054
+ let tPath = TypeUtils. pathFromTypeExpr typ in
1055
+ match tPath with
1056
+ | None -> []
1057
+ | Some tPath ->
1058
+ let completionPath =
1059
+ (tPath |> Utils. expandPath |> List. tl |> List. rev)
1060
+ @ (envFromCompletionItem.pathRev |> List. rev)
1061
+ in
1062
+ if List. length completionPath = 0 then []
1063
+ else
1064
+ let completions =
1065
+ completionsForPipeFromCompletionPath ~env CompletionIsMadeFrom
1066
+ ~opens ~pos ~scope ~debug ~prefix: fieldName ~env ~raw Opens ~full
1067
+ completionPath
1068
+ in
1069
+ completions
1070
+ |> TypeUtils. filterPipeableFunctions ~env ~full
1071
+ ~last Path:(Path. last tPath) ~replace Range:fieldNameLoc)
1072
+ in
1073
+ (* Extra completions from configure extra module(s) *)
1074
+ let extraCompletions =
1075
+ match completionsForCtxPath with
1076
+ | None -> []
1077
+ | Some (typ , envFromCompletionItem ) -> (
1078
+ match
1079
+ TypeUtils. getExtraModuleToCompleteFromForType typ
1080
+ ~env: envFromCompletionItem ~full
1081
+ with
1082
+ | None -> []
1083
+ | Some completionPath ->
1084
+ completionsForPipeFromCompletionPath ~env CompletionIsMadeFrom ~opens
1085
+ ~pos ~scope ~debug ~prefix: fieldName ~env ~raw Opens ~full
1086
+ completionPath
1087
+ |> TypeUtils. filterPipeableFunctions ~env ~full
1088
+ ~replace Range:fieldNameLoc
1089
+ ?lastPath:
1090
+ (match TypeUtils. pathFromTypeExpr typ with
1091
+ | None -> None
1092
+ | Some tPath -> Some (Path. last tPath)))
1093
+ in
1094
+ mainCompletions @ pipeCompletions @ extraCompletions
996
1095
| CPField {contextPath = cp ; fieldName; fieldNameLoc} -> (
997
1096
if Debug. verbose () then print_endline " [ctx_path]--> CPField" ;
998
1097
let completionsForCtxPath =
@@ -1056,8 +1155,8 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env ~exact
1056
1155
completionsForPipeFromCompletionPath ~opens ~pos ~scope ~debug
1057
1156
~prefix: fieldName ~env CompletionIsMadeFrom:env ~env: envFromExtracted
1058
1157
~raw Opens ~full completionPath
1059
- |> TypeUtils. filterPipeableFunctions ~env: envFromExtracted ~full ~path
1060
- ~replace Range:fieldNameLoc
1158
+ |> TypeUtils. filterPipeableFunctions ~env: envFromExtracted ~full
1159
+ ~last Path:( Path. last path) ~ replace Range:fieldNameLoc
1061
1160
| None -> []
1062
1161
in
1063
1162
pipeCompletionsForModule
@@ -1081,16 +1180,7 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env ~exact
1081
1180
| Some (typ , env ) -> (
1082
1181
match typ |> TypeUtils. extractObjectType ~env ~package with
1083
1182
| Some (env , tObj ) ->
1084
- let rec getFields (texp : Types.type_expr ) =
1085
- match texp.desc with
1086
- | Tfield (name , _ , t1 , t2 ) ->
1087
- let fields = t2 |> getFields in
1088
- (name, t1) :: fields
1089
- | Tlink te | Tsubst te | Tpoly (te , [] ) -> te |> getFields
1090
- | Tvar None -> []
1091
- | _ -> []
1092
- in
1093
- tObj |> getFields
1183
+ tObj |> TypeUtils. getObjFields
1094
1184
|> Utils. filterMap (fun (field , typ ) ->
1095
1185
if Utils. checkName field ~prefix: label ~exact then
1096
1186
Some
@@ -1175,15 +1265,23 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env ~exact
1175
1265
completionsForPipeFromCompletionPath ~env CompletionIsMadeFrom ~opens
1176
1266
~pos ~scope ~debug ~prefix: funNamePrefix ~env ~raw Opens ~full
1177
1267
completionPath
1178
- |> TypeUtils. filterPipeableFunctions ~env ~full ?path:tPath
1268
+ |> TypeUtils. filterPipeableFunctions ~env ~full
1269
+ ?lastPath:
1270
+ (match tPath with
1271
+ | None -> None
1272
+ | Some tPath -> Some (Path. last tPath))
1179
1273
in
1180
1274
match completionPath with
1181
1275
| Some completionPath -> (
1182
1276
let completionsFromMainFn =
1183
1277
completionsForPipeFromCompletionPath ~env CompletionIsMadeFrom ~opens
1184
1278
~pos ~scope ~debug ~prefix: funNamePrefix ~env ~raw Opens ~full
1185
1279
completionPath
1186
- |> TypeUtils. filterPipeableFunctions ~env ~full ?path:tPath
1280
+ |> TypeUtils. filterPipeableFunctions ~env ~full
1281
+ ?lastPath:
1282
+ (match tPath with
1283
+ | None -> None
1284
+ | Some tPath -> Some (Path. last tPath))
1187
1285
in
1188
1286
let completions = completionsFromMainFn @ completionsFromExtraModule in
1189
1287
(* We add React element functions to the completion if we're in a JSX context *)
0 commit comments