@@ -604,6 +604,12 @@ let completionsGetTypeEnv = function
604
604
| {Completion. kind = Field ({typ} , _ ); env} :: _ -> Some (typ, env)
605
605
| _ -> None
606
606
607
+ type getCompletionsForContextPathMode = Regular | Pipe
608
+
609
+ type completionsTypeEnvTyp =
610
+ | TypeExpr of Types .type_expr
611
+ | ExtractedType of completionType
612
+
607
613
let completionsGetCompletionType ~full = function
608
614
| {Completion. kind = Value typ; env} :: _
609
615
| {Completion. kind = ObjLabel typ; env} :: _
@@ -618,9 +624,27 @@ let completionsGetCompletionType ~full = function
618
624
| {Completion. kind = ExtractedType (typ , _ ); env} :: _ -> Some (typ, env)
619
625
| _ -> None
620
626
621
- type getCompletionsForContextPathMode = Regular | Pipe
627
+ let rec completionsGetCompletionType2 ~full ~opens ~rawOpens ~allFiles ~pos
628
+ ~scope = function
629
+ | {Completion. kind = Value typ; env} :: _
630
+ | {Completion. kind = ObjLabel typ; env} :: _
631
+ | {Completion. kind = Field ({typ} , _ ); env} :: _ ->
632
+ Some (TypeExpr typ, env)
633
+ | {Completion. kind = FollowContextPath ctxPath ; env} :: _ ->
634
+ ctxPath
635
+ |> getCompletionsForContextPath ~full ~env ~exact: true ~opens ~raw Opens
636
+ ~all Files ~pos ~scope
637
+ |> completionsGetCompletionType2 ~full ~opens ~raw Opens ~all Files ~pos
638
+ ~scope
639
+ | {Completion. kind = Type typ ; env} :: _ -> (
640
+ match TypeUtils. extractTypeFromResolvedType typ ~env ~full with
641
+ | None -> None
642
+ | Some extractedType -> Some (ExtractedType extractedType, env))
643
+ | {Completion. kind = ExtractedType (typ , _ ); env} :: _ ->
644
+ Some (ExtractedType typ, env)
645
+ | _ -> None
622
646
623
- let rec completionsGetTypeEnv2 (completions : Completion.t list ) ~full ~opens
647
+ and completionsGetTypeEnv2 (completions : Completion.t list ) ~full ~opens
624
648
~rawOpens ~allFiles ~pos ~scope =
625
649
match completions with
626
650
| {Completion. kind = Value typ ; env} :: _ -> Some (typ, env)
@@ -760,29 +784,43 @@ and getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env
760
784
|> getCompletionsForPath ~package ~opens ~all Files ~pos ~exact
761
785
~completion Context:Field ~env ~scope
762
786
| CPField (cp , fieldName ) -> (
763
- match
787
+ let completionsForCtxPath =
764
788
cp
765
789
|> getCompletionsForContextPath ~full ~opens ~raw Opens ~all Files ~pos ~env
766
790
~exact: true ~scope
767
- |> completionsGetTypeEnv2 ~full ~opens ~raw Opens ~all Files ~pos ~scope
768
- with
769
- | Some (typ , env ) -> (
770
- match typ |> TypeUtils. extractRecordType ~env ~package with
771
- | Some (env , fields , typDecl ) ->
772
- fields
773
- |> Utils. filterMap (fun field ->
774
- if Utils. checkName field.fname.txt ~prefix: fieldName ~exact then
775
- Some
776
- (Completion. create field.fname.txt ~env
777
- ~docstring: field.docstring ?deprecated:field.deprecated
778
- ~kind:
779
- (Completion. Field
780
- ( field,
781
- typDecl.item.decl
782
- |> Shared. declToString typDecl.name.txt )))
783
- else None )
784
- | None -> [] )
785
- | None -> [] )
791
+ in
792
+ let extracted =
793
+ match
794
+ completionsForCtxPath
795
+ |> completionsGetCompletionType2 ~full ~opens ~raw Opens ~all Files ~pos
796
+ ~scope
797
+ with
798
+ | Some (TypeExpr typ , env ) -> (
799
+ match typ |> TypeUtils. extractRecordType ~env ~package with
800
+ | Some (env , fields , typDecl ) ->
801
+ Some
802
+ ( env,
803
+ fields,
804
+ typDecl.item.decl |> Shared. declToString typDecl.name.txt )
805
+ | None -> None )
806
+ | Some (ExtractedType typ , env ) -> (
807
+ match typ with
808
+ | Trecord {fields} ->
809
+ Some (env, fields, typ |> TypeUtils. extractedTypeToString)
810
+ | _ -> None )
811
+ | None -> None
812
+ in
813
+ match extracted with
814
+ | None -> []
815
+ | Some (env , fields , recordAsString ) ->
816
+ fields
817
+ |> Utils. filterMap (fun field ->
818
+ if Utils. checkName field.fname.txt ~prefix: fieldName ~exact then
819
+ Some
820
+ (Completion. create field.fname.txt ~env
821
+ ~docstring: field.docstring
822
+ ~kind: (Completion. Field (field, recordAsString)))
823
+ else None ))
786
824
| CPObj (cp , label ) -> (
787
825
match
788
826
cp
0 commit comments