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