@@ -588,6 +588,12 @@ let completionsGetTypeEnv = function
588
588
| {Completion. kind = Field ({typ} , _ ); env} :: _ -> Some (typ, env)
589
589
| _ -> None
590
590
591
+ type getCompletionsForContextPathMode = Regular | Pipe
592
+
593
+ type completionsTypeEnvTyp =
594
+ | TypeExpr of Types .type_expr
595
+ | ExtractedType of completionType
596
+
591
597
let completionsGetCompletionType ~full = function
592
598
| {Completion. kind = Value typ; env} :: _
593
599
| {Completion. kind = ObjLabel typ; env} :: _
@@ -602,9 +608,27 @@ let completionsGetCompletionType ~full = function
602
608
| {Completion. kind = ExtractedType (typ , _ ); env} :: _ -> Some (typ, env)
603
609
| _ -> None
604
610
605
- type getCompletionsForContextPathMode = Regular | Pipe
611
+ let rec completionsGetCompletionType2 ~full ~opens ~rawOpens ~allFiles ~pos
612
+ ~scope = function
613
+ | {Completion. kind = Value typ; env} :: _
614
+ | {Completion. kind = ObjLabel typ; env} :: _
615
+ | {Completion. kind = Field ({typ} , _ ); env} :: _ ->
616
+ Some (TypeExpr typ, env)
617
+ | {Completion. kind = FollowContextPath ctxPath ; env} :: _ ->
618
+ ctxPath
619
+ |> getCompletionsForContextPath ~full ~env ~exact: true ~opens ~raw Opens
620
+ ~all Files ~pos ~scope
621
+ |> completionsGetCompletionType2 ~full ~opens ~raw Opens ~all Files ~pos
622
+ ~scope
623
+ | {Completion. kind = Type typ ; env} :: _ -> (
624
+ match TypeUtils. extractTypeFromResolvedType typ ~env ~full with
625
+ | None -> None
626
+ | Some extractedType -> Some (ExtractedType extractedType, env))
627
+ | {Completion. kind = ExtractedType (typ , _ ); env} :: _ ->
628
+ Some (ExtractedType typ, env)
629
+ | _ -> None
606
630
607
- let rec completionsGetTypeEnv2 (completions : Completion.t list ) ~full ~opens
631
+ and completionsGetTypeEnv2 (completions : Completion.t list ) ~full ~opens
608
632
~rawOpens ~allFiles ~pos ~scope =
609
633
match completions with
610
634
| {Completion. kind = Value typ ; env} :: _ -> Some (typ, env)
@@ -744,29 +768,43 @@ and getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env
744
768
|> getCompletionsForPath ~package ~opens ~all Files ~pos ~exact
745
769
~completion Context:Field ~env ~scope
746
770
| CPField (cp , fieldName ) -> (
747
- match
771
+ let completionsForCtxPath =
748
772
cp
749
773
|> getCompletionsForContextPath ~full ~opens ~raw Opens ~all Files ~pos ~env
750
774
~exact: true ~scope
751
- |> completionsGetTypeEnv2 ~full ~opens ~raw Opens ~all Files ~pos ~scope
752
- with
753
- | Some (typ , env ) -> (
754
- match typ |> TypeUtils. extractRecordType ~env ~package with
755
- | Some (env , fields , typDecl ) ->
756
- fields
757
- |> Utils. filterMap (fun field ->
758
- if Utils. checkName field.fname.txt ~prefix: fieldName ~exact then
759
- Some
760
- (Completion. create field.fname.txt ~env
761
- ~docstring: field.docstring
762
- ~kind:
763
- (Completion. Field
764
- ( field,
765
- typDecl.item.decl
766
- |> Shared. declToString typDecl.name.txt )))
767
- else None )
768
- | None -> [] )
769
- | None -> [] )
775
+ in
776
+ let extracted =
777
+ match
778
+ completionsForCtxPath
779
+ |> completionsGetCompletionType2 ~full ~opens ~raw Opens ~all Files ~pos
780
+ ~scope
781
+ with
782
+ | Some (TypeExpr typ , env ) -> (
783
+ match typ |> TypeUtils. extractRecordType ~env ~package with
784
+ | Some (env , fields , typDecl ) ->
785
+ Some
786
+ ( env,
787
+ fields,
788
+ typDecl.item.decl |> Shared. declToString typDecl.name.txt )
789
+ | None -> None )
790
+ | Some (ExtractedType typ , env ) -> (
791
+ match typ with
792
+ | Trecord {fields} ->
793
+ Some (env, fields, typ |> TypeUtils. extractedTypeToString)
794
+ | _ -> None )
795
+ | None -> None
796
+ in
797
+ match extracted with
798
+ | None -> []
799
+ | Some (env , fields , recordAsString ) ->
800
+ fields
801
+ |> Utils. filterMap (fun field ->
802
+ if Utils. checkName field.fname.txt ~prefix: fieldName ~exact then
803
+ Some
804
+ (Completion. create field.fname.txt ~env
805
+ ~docstring: field.docstring
806
+ ~kind: (Completion. Field (field, recordAsString)))
807
+ else None ))
770
808
| CPObj (cp , label ) -> (
771
809
match
772
810
cp
0 commit comments