@@ -993,6 +993,105 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env ~exact
993993 path @ [fieldName]
994994 |> getCompletionsForPath ~debug ~opens ~full ~pos ~exact
995995 ~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
9961095 | CPField {contextPath = cp ; fieldName; fieldNameLoc} -> (
9971096 if Debug. verbose () then print_endline " [ctx_path]--> CPField" ;
9981097 let completionsForCtxPath =
@@ -1056,8 +1155,8 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env ~exact
10561155 completionsForPipeFromCompletionPath ~opens ~pos ~scope ~debug
10571156 ~prefix: fieldName ~env CompletionIsMadeFrom:env ~env: envFromExtracted
10581157 ~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
10611160 | None -> []
10621161 in
10631162 pipeCompletionsForModule
@@ -1081,16 +1180,7 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env ~exact
10811180 | Some (typ , env ) -> (
10821181 match typ |> TypeUtils. extractObjectType ~env ~package with
10831182 | 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
10941184 |> Utils. filterMap (fun (field , typ ) ->
10951185 if Utils. checkName field ~prefix: label ~exact then
10961186 Some
@@ -1175,15 +1265,23 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env ~exact
11751265 completionsForPipeFromCompletionPath ~env CompletionIsMadeFrom ~opens
11761266 ~pos ~scope ~debug ~prefix: funNamePrefix ~env ~raw Opens ~full
11771267 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))
11791273 in
11801274 match completionPath with
11811275 | Some completionPath -> (
11821276 let completionsFromMainFn =
11831277 completionsForPipeFromCompletionPath ~env CompletionIsMadeFrom ~opens
11841278 ~pos ~scope ~debug ~prefix: funNamePrefix ~env ~raw Opens ~full
11851279 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))
11871285 in
11881286 let completions = completionsFromMainFn @ completionsFromExtraModule in
11891287 (* We add React element functions to the completion if we're in a JSX context *)
0 commit comments