@@ -2717,15 +2717,16 @@ completionTests
2717
2717
, testGroup " other" otherCompletionTests
2718
2718
]
2719
2719
2720
- completionTest :: String -> [T. Text ] -> Position -> [(T. Text , CompletionItemKind , Bool , Bool )] -> TestTree
2720
+ completionTest :: String -> [T. Text ] -> Position -> [(T. Text , CompletionItemKind , T. Text , Bool , Bool )] -> TestTree
2721
2721
completionTest name src pos expected = testSessionWait name $ do
2722
2722
docId <- createDoc " A.hs" " haskell" (T. unlines src)
2723
2723
_ <- waitForDiagnostics
2724
2724
compls <- getCompletions docId pos
2725
- let compls' = [ (_label, _kind) | CompletionItem {.. } <- compls]
2725
+ let compls' = [ (_label, _kind, _insertText ) | CompletionItem {.. } <- compls]
2726
2726
liftIO $ do
2727
- compls' @?= [ (l, Just k) | (l,k,_,_) <- expected]
2728
- forM_ (zip compls expected) $ \ (CompletionItem {.. }, (_,_,expectedSig, expectedDocs)) -> do
2727
+ let emptyToMaybe x = if T. null x then Nothing else Just x
2728
+ compls' @?= [ (l, Just k, emptyToMaybe t) | (l,k,t,_,_) <- expected]
2729
+ forM_ (zip compls expected) $ \ (CompletionItem {.. }, (_,_,_,expectedSig, expectedDocs)) -> do
2729
2730
when expectedSig $
2730
2731
assertBool (" Missing type signature: " <> T. unpack _label) (isJust _detail)
2731
2732
when expectedDocs $
@@ -2737,42 +2738,43 @@ topLevelCompletionTests = [
2737
2738
" variable"
2738
2739
[" bar = xx" , " -- | haddock" , " xxx :: ()" , " xxx = ()" , " -- | haddock" , " data Xxx = XxxCon" ]
2739
2740
(Position 0 8 )
2740
- [(" xxx" , CiFunction , True , True ),
2741
- (" XxxCon" , CiConstructor , False , True )
2741
+ [(" xxx" , CiFunction , " xxx " , True , True ),
2742
+ (" XxxCon" , CiConstructor , " XxxCon " , False , True )
2742
2743
],
2743
2744
completionTest
2744
2745
" constructor"
2745
2746
[" bar = xx" , " -- | haddock" , " xxx :: ()" , " xxx = ()" , " -- | haddock" , " data Xxx = XxxCon" ]
2746
2747
(Position 0 8 )
2747
- [(" xxx" , CiFunction , True , True ),
2748
- (" XxxCon" , CiConstructor , False , True )
2748
+ [(" xxx" , CiFunction , " xxx " , True , True ),
2749
+ (" XxxCon" , CiConstructor , " XxxCon " , False , True )
2749
2750
],
2750
2751
completionTest
2751
2752
" class method"
2752
2753
[" bar = xx" , " class Xxx a where" , " -- | haddock" , " xxx :: ()" , " xxx = ()" ]
2753
2754
(Position 0 8 )
2754
- [(" xxx" , CiFunction , True , True )],
2755
+ [(" xxx" , CiFunction , " xxx " , True , True )],
2755
2756
completionTest
2756
2757
" type"
2757
2758
[" bar :: Xx" , " xxx = ()" , " -- | haddock" , " data Xxx = XxxCon" ]
2758
2759
(Position 0 9 )
2759
- [(" Xxx" , CiStruct , False , True )],
2760
+ [(" Xxx" , CiStruct , " Xxx " , False , True )],
2760
2761
completionTest
2761
2762
" class"
2762
2763
[" bar :: Xx" , " xxx = ()" , " -- | haddock" , " class Xxx a" ]
2763
2764
(Position 0 9 )
2764
- [(" Xxx" , CiClass , False , True )],
2765
+ [(" Xxx" , CiClass , " Xxx " , False , True )],
2765
2766
completionTest
2766
2767
" records"
2767
2768
[" data Person = Person { _personName:: String, _personAge:: Int}" , " bar = Person { _pers }" ]
2768
2769
(Position 1 19 )
2769
- [(" _personName" , CiFunction , False , True ),
2770
- (" _personAge" , CiFunction , False , True )],
2770
+ [(" _personName" , CiFunction , " _personName " , False , True ),
2771
+ (" _personAge" , CiFunction , " _personAge " , False , True )],
2771
2772
completionTest
2772
2773
" recordsConstructor"
2773
2774
[" data XxRecord = XyRecord { x:: String, y:: Int}" , " bar = Xy" ]
2774
2775
(Position 1 19 )
2775
- [(" XyRecord" , CiConstructor , False , True )]
2776
+ [(" XyRecord" , CiConstructor , " XyRecord" , False , True ),
2777
+ (" XyRecord" , CiSnippet , " XyRecord {x=${1:_x}, y=${2:_y}}" , False , True )]
2776
2778
]
2777
2779
2778
2780
localCompletionTests :: [TestTree ]
@@ -2781,8 +2783,8 @@ localCompletionTests = [
2781
2783
" argument"
2782
2784
[" bar (Just abcdef) abcdefg = abcd" ]
2783
2785
(Position 0 32 )
2784
- [(" abcdef" , CiFunction , True , False ),
2785
- (" abcdefg" , CiFunction , True , False )
2786
+ [(" abcdef" , CiFunction , " abcdef " , True , False ),
2787
+ (" abcdefg" , CiFunction , " abcdefg " , True , False )
2786
2788
],
2787
2789
completionTest
2788
2790
" let"
@@ -2791,8 +2793,8 @@ localCompletionTests = [
2791
2793
," in abcd"
2792
2794
]
2793
2795
(Position 2 15 )
2794
- [(" abcdef" , CiFunction , True , False ),
2795
- (" abcdefg" , CiFunction , True , False )
2796
+ [(" abcdef" , CiFunction , " abcdef " , True , False ),
2797
+ (" abcdefg" , CiFunction , " abcdefg " , True , False )
2796
2798
],
2797
2799
completionTest
2798
2800
" where"
@@ -2801,8 +2803,8 @@ localCompletionTests = [
2801
2803
," abcdefg = let abcd = undefined in undefined"
2802
2804
]
2803
2805
(Position 0 10 )
2804
- [(" abcdef" , CiFunction , True , False ),
2805
- (" abcdefg" , CiFunction , True , False )
2806
+ [(" abcdef" , CiFunction , " abcdef " , True , False ),
2807
+ (" abcdefg" , CiFunction , " abcdefg " , True , False )
2806
2808
],
2807
2809
completionTest
2808
2810
" do/1"
@@ -2813,7 +2815,7 @@ localCompletionTests = [
2813
2815
," pure ()"
2814
2816
]
2815
2817
(Position 2 6 )
2816
- [(" abcdef" , CiFunction , True , False )
2818
+ [(" abcdef" , CiFunction , " abcdef " , True , False )
2817
2819
],
2818
2820
completionTest
2819
2821
" do/2"
@@ -2827,12 +2829,12 @@ localCompletionTests = [
2827
2829
," abcdefghij = undefined"
2828
2830
]
2829
2831
(Position 5 8 )
2830
- [(" abcde" , CiFunction , True , False )
2831
- ,(" abcdefghij" , CiFunction , True , False )
2832
- ,(" abcdef" , CiFunction , True , False )
2833
- ,(" abcdefg" , CiFunction , True , False )
2834
- ,(" abcdefgh" , CiFunction , True , False )
2835
- ,(" abcdefghi" , CiFunction , True , False )
2832
+ [(" abcde" , CiFunction , " abcde " , True , False )
2833
+ ,(" abcdefghij" , CiFunction , " abcdefghij " , True , False )
2834
+ ,(" abcdef" , CiFunction , " abcdef " , True , False )
2835
+ ,(" abcdefg" , CiFunction , " abcdefg " , True , False )
2836
+ ,(" abcdefgh" , CiFunction , " abcdefgh " , True , False )
2837
+ ,(" abcdefghi" , CiFunction , " abcdefghi " , True , False )
2836
2838
]
2837
2839
]
2838
2840
@@ -2842,32 +2844,41 @@ nonLocalCompletionTests =
2842
2844
" variable"
2843
2845
[" module A where" , " f = hea" ]
2844
2846
(Position 1 7 )
2845
- [(" head" , CiFunction , True , True )],
2847
+ [(" head" , CiFunction , " head ${1:[a]} " , True , True )],
2846
2848
completionTest
2847
2849
" constructor"
2848
2850
[" module A where" , " f = Tru" ]
2849
2851
(Position 1 7 )
2850
- [ (" True" , CiConstructor , True , True ),
2851
- (" truncate" , CiFunction , True , True )
2852
+ [ (" True" , CiConstructor , " True " , True , True ),
2853
+ (" truncate" , CiFunction , " truncate ${1:a} " , True , True )
2852
2854
],
2853
2855
completionTest
2854
2856
" type"
2855
2857
[" {-# OPTIONS_GHC -Wall #-}" , " module A () where" , " f :: Bo" , " f = True" ]
2856
2858
(Position 2 7 )
2857
- [ (" Bounded" , CiClass , True , True ),
2858
- (" Bool" , CiStruct , True , True )
2859
+ [ (" Bounded" , CiClass , " Bounded ${1:*} " , True , True ),
2860
+ (" Bool" , CiStruct , " Bool " , True , True )
2859
2861
],
2860
2862
completionTest
2861
2863
" qualified"
2862
2864
[" {-# OPTIONS_GHC -Wunused-binds #-}" , " module A () where" , " f = Prelude.hea" ]
2863
2865
(Position 2 15 )
2864
- [ (" head" , CiFunction , True , True )
2866
+ [ (" head" , CiFunction , " head ${1:[a]} " , True , True )
2865
2867
],
2866
2868
completionTest
2867
2869
" duplicate import"
2868
2870
[" module A where" , " import Data.List" , " import Data.List" , " f = perm" ]
2869
2871
(Position 3 8 )
2870
- [ (" permutations" , CiFunction , False , False )
2872
+ [ (" permutations" , CiFunction , " permutations ${1:[a]}" , False , False )
2873
+ ],
2874
+ completionTest
2875
+ " record snippet on import"
2876
+ [" module A where" , " import Text.Printf (FormatParse(FormatParse))" , " FormatParse" ]
2877
+ (Position 2 10 )
2878
+ [(" FormatParse" , CiStruct , " FormatParse " , False , False ),
2879
+ (" FormatParse" , CiConstructor , " FormatParse ${1:String} ${2:Char} ${3:String}" , False , False ),
2880
+ (" FormatParse" , CiSnippet ,
2881
+ " FormatParse {fpModifiers=${1:_fpModifiers}, fpChar=${2:_fpChar}, fpRest=${3:_fpRest}}" , False , False )
2871
2882
]
2872
2883
]
2873
2884
@@ -2877,7 +2888,7 @@ otherCompletionTests = [
2877
2888
" keyword"
2878
2889
[" module A where" , " f = newty" ]
2879
2890
(Position 1 9 )
2880
- [(" newtype" , CiKeyword , False , False )],
2891
+ [(" newtype" , CiKeyword , " " , False , False )],
2881
2892
completionTest
2882
2893
" type context"
2883
2894
[ " {-# OPTIONS_GHC -Wunused-binds #-}" ,
@@ -2889,7 +2900,7 @@ otherCompletionTests = [
2889
2900
-- This should be sufficient to detect that we are in a
2890
2901
-- type context and only show the completion to the type.
2891
2902
(Position 3 11 )
2892
- [(" Integer" , CiStruct , True , True )]
2903
+ [(" Integer" , CiStruct , " Integer " , True , True )]
2893
2904
]
2894
2905
2895
2906
highlightTests :: TestTree
0 commit comments