@@ -722,93 +722,52 @@ let rec getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env
722
722
~exact: true ~scope
723
723
|> completionsGetTypeEnv
724
724
with
725
+ | None -> []
725
726
| Some (typ , envFromCompletionItem ) -> (
726
727
let env, typ =
727
- typ |> TypeUtils. resolveTypeForPipeCompletion ~env ~package
728
- in
729
-
730
- (* If the type we're completing on is a type parameter, we won't be able to do
731
- completion unless we know what that type parameter is compiled as. This
732
- attempts to look up the compiled type for that type parameter by looking
733
- for compiled information at the loc of that expression. *)
734
- let typ =
735
- match typ with
736
- | {Types. desc = Tvar _ } -> (
737
- match
738
- TypeUtils. findReturnTypeOfFunctionAtLoc lhsLoc ~env ~full
739
- ~debug: false
740
- with
741
- | None -> typ
742
- | Some typFromLoc -> typFromLoc)
743
- | _ -> typ
744
- in
745
- let {
746
- arrayModulePath;
747
- optionModulePath;
748
- stringModulePath;
749
- intModulePath;
750
- floatModulePath;
751
- promiseModulePath;
752
- listModulePath;
753
- resultModulePath;
754
- } =
755
- package.builtInCompletionModules
756
- in
757
- let getBuiltinTypePath path =
758
- match path with
759
- | Path. Pident id when Ident. name id = " array" -> Some arrayModulePath
760
- | Path. Pident id when Ident. name id = " option" -> Some optionModulePath
761
- | Path. Pident id when Ident. name id = " string" -> Some stringModulePath
762
- | Path. Pident id when Ident. name id = " int" -> Some intModulePath
763
- | Path. Pident id when Ident. name id = " float" -> Some floatModulePath
764
- | Path. Pident id when Ident. name id = " promise" ->
765
- Some promiseModulePath
766
- | Path. Pident id when Ident. name id = " list" -> Some listModulePath
767
- | Path. Pident id when Ident. name id = " result" -> Some resultModulePath
768
- | Path. Pident id when Ident. name id = " lazy_t" -> Some [" Lazy" ]
769
- | Path. Pident id when Ident. name id = " char" -> Some [" Char" ]
770
- | Pdot (Pident id , "result" , _ ) when Ident. name id = " Pervasives" ->
771
- Some resultModulePath
772
- | _ -> None
773
- in
774
- let rec expandPath (path : Path.t ) =
775
- match path with
776
- | Pident id -> [Ident. name id]
777
- | Pdot (p , s , _ ) -> s :: expandPath p
778
- | Papply _ -> []
779
- in
780
- let getTypePath typ =
781
- match typ.Types. desc with
782
- | Tconstr (path, _typeArgs, _)
783
- | Tlink {desc = Tconstr (path, _typeArgs, _)}
784
- | Tsubst {desc = Tconstr (path, _typeArgs, _)}
785
- | Tpoly ({desc = Tconstr (path , _typeArgs , _ )} , [] ) ->
786
- Some path
787
- | _ -> None
788
- in
789
- let rec removeRawOpen rawOpen modulePath =
790
- match (rawOpen, modulePath) with
791
- | [_], _ -> Some modulePath
792
- | s :: inner , first :: restPath when s = first ->
793
- removeRawOpen inner restPath
794
- | _ -> None
795
- in
796
- let rec removeRawOpens rawOpens modulePath =
797
- match rawOpens with
798
- | rawOpen :: restOpens -> (
799
- let newModulePath = removeRawOpens restOpens modulePath in
800
- match removeRawOpen rawOpen newModulePath with
801
- | None -> newModulePath
802
- | Some mp -> mp)
803
- | [] -> modulePath
728
+ typ
729
+ |> TypeUtils. resolveTypeForPipeCompletion ~env ~package ~full ~lhs Loc
804
730
in
805
731
let completionPath =
806
- match getTypePath typ with
807
- | Some typePath -> (
808
- match getBuiltinTypePath typePath with
809
- | Some path -> Some path
810
- | None -> (
811
- match expandPath typePath with
732
+ match typ with
733
+ | Builtin (builtin , _ ) ->
734
+ let {
735
+ arrayModulePath;
736
+ optionModulePath;
737
+ stringModulePath;
738
+ intModulePath;
739
+ floatModulePath;
740
+ promiseModulePath;
741
+ listModulePath;
742
+ resultModulePath;
743
+ } =
744
+ package.builtInCompletionModules
745
+ in
746
+ Some
747
+ (match builtin with
748
+ | Array -> arrayModulePath
749
+ | Option -> optionModulePath
750
+ | String -> stringModulePath
751
+ | Int -> intModulePath
752
+ | Float -> floatModulePath
753
+ | Promise -> promiseModulePath
754
+ | List -> listModulePath
755
+ | Result -> resultModulePath
756
+ | Lazy -> [" Lazy" ]
757
+ | Char -> [" Char" ])
758
+ | TypExpr t -> (
759
+ let rec expandPath (path : Path.t ) =
760
+ match path with
761
+ | Pident id -> [Ident. name id]
762
+ | Pdot (p , s , _ ) -> s :: expandPath p
763
+ | Papply _ -> []
764
+ in
765
+ match t.Types. desc with
766
+ | Tconstr (path, _typeArgs, _)
767
+ | Tlink {desc = Tconstr (path, _typeArgs, _)}
768
+ | Tsubst {desc = Tconstr (path, _typeArgs, _)}
769
+ | Tpoly ({desc = Tconstr (path , _typeArgs , _ )} , [] ) -> (
770
+ match expandPath path with
812
771
| _ :: pathRev ->
813
772
(* type path is relative to the completion environment
814
773
express it from the root of the file *)
@@ -823,11 +782,27 @@ let rec getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env
823
782
else envFromCompletionItem.file.moduleName :: pathFromEnv_
824
783
in
825
784
Some pathFromEnv
826
- | _ -> None ))
827
- | None -> None
785
+ | _ -> None )
786
+ | _ -> None )
828
787
in
829
788
match completionPath with
830
789
| Some completionPath -> (
790
+ let rec removeRawOpen rawOpen modulePath =
791
+ match (rawOpen, modulePath) with
792
+ | [_], _ -> Some modulePath
793
+ | s :: inner , first :: restPath when s = first ->
794
+ removeRawOpen inner restPath
795
+ | _ -> None
796
+ in
797
+ let rec removeRawOpens rawOpens modulePath =
798
+ match rawOpens with
799
+ | rawOpen :: restOpens -> (
800
+ let newModulePath = removeRawOpens restOpens modulePath in
801
+ match removeRawOpen rawOpen newModulePath with
802
+ | None -> newModulePath
803
+ | Some mp -> mp)
804
+ | [] -> modulePath
805
+ in
831
806
let completionPathMinusOpens =
832
807
completionPath
833
808
|> removeRawOpens package.opens
@@ -855,17 +830,16 @@ let rec getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env
855
830
(* We add React element functions to the completion if we're in a JSX context *)
856
831
let forJsxCompletion =
857
832
if inJsx then
858
- match getTypePath typ with
859
- | Some (Path. Pident id ) when Ident. name id = " int" -> Some " int"
860
- | Some (Path. Pident id ) when Ident. name id = " float" -> Some " float"
861
- | Some (Path. Pident id ) when Ident. name id = " string" ->
862
- Some " string"
863
- | Some (Path. Pident id ) when Ident. name id = " array" -> Some " array"
833
+ match typ with
834
+ | Builtin (Int, t ) -> Some (" int" , t)
835
+ | Builtin (Float, t ) -> Some (" float" , t)
836
+ | Builtin (String, t ) -> Some (" string" , t)
837
+ | Builtin (Array, t ) -> Some (" array" , t)
864
838
| _ -> None
865
839
else None
866
840
in
867
841
match forJsxCompletion with
868
- | Some builtinNameToComplete
842
+ | Some ( builtinNameToComplete, typ)
869
843
when Utils. checkName builtinNameToComplete ~prefix: funNamePrefix
870
844
~exact: false ->
871
845
[
@@ -881,8 +855,7 @@ let rec getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env
881
855
]
882
856
@ completions
883
857
| _ -> completions)
884
- | None -> [] )
885
- | None -> [] )
858
+ | None -> [] ))
886
859
| CTuple ctxPaths ->
887
860
(* Turn a list of context paths into a list of type expressions. *)
888
861
let typeExrps =
0 commit comments