File tree 3 files changed +33
-6
lines changed
plugins/hls-tactics-plugin
src/Ide/Plugin/Tactic/LanguageServer 3 files changed +33
-6
lines changed Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ import Data.Maybe
22
22
import Data.Monoid
23
23
import qualified Data.Text as T
24
24
import Data.Traversable
25
- import DataCon (dataConName )
25
+ import DataCon (dataConName , dataConCannotMatch )
26
26
import Development.IDE.GHC.Compat
27
27
import GHC.Generics
28
28
import GHC.LanguageExtensions.Type (Extension (LambdaCase ))
@@ -80,9 +80,7 @@ commandProvider UseDataCon =
80
80
requireFeature FeatureUseDataCon $
81
81
filterTypeProjection
82
82
( guardLength (<= cfg_max_use_ctor_actions cfg)
83
- . fromMaybe []
84
- . fmap fst
85
- . tacticsGetDataCons
83
+ . useCtorFilter
86
84
) $ \ dcon ->
87
85
provide UseDataCon
88
86
. T. pack
@@ -231,3 +229,14 @@ destructFilter :: Type -> Type -> Bool
231
229
destructFilter _ (algebraicTyCon -> Just _) = True
232
230
destructFilter _ _ = False
233
231
232
+
233
+ ------------------------------------------------------------------------------
234
+ -- | Only show data cons in "Use constructor" if they can unify with the goal
235
+ useCtorFilter :: Type -> [DataCon ]
236
+ useCtorFilter ty
237
+ | Just (dcs, apps) <- tacticsGetDataCons ty = do
238
+ dc <- dcs
239
+ guard $ not $ dataConCannotMatch apps dc
240
+ pure dc
241
+ useCtorFilter _ = []
242
+
Original file line number Diff line number Diff line change @@ -80,7 +80,7 @@ spec = do
80
80
describe " provider" $ do
81
81
mkTest
82
82
" Suggests all data cons for Either"
83
- " ConProviders.hs" 3 6
83
+ " ConProviders.hs" 5 6
84
84
[ (id , UseDataCon , " Left" )
85
85
, (id , UseDataCon , " Right" )
86
86
, (not , UseDataCon , " :" )
@@ -89,9 +89,16 @@ spec = do
89
89
]
90
90
mkTest
91
91
" Suggests no data cons for big types"
92
- " ConProviders.hs" 9 17 $ do
92
+ " ConProviders.hs" 11 17 $ do
93
93
c <- [1 :: Int .. 10 ]
94
94
pure $ (not , UseDataCon , T. pack $ show c)
95
+ mkTest
96
+ " Suggests only matching data cons for GADT"
97
+ " ConProviders.hs" 20 12
98
+ [ (id , UseDataCon , " IntGADT" )
99
+ , (id , UseDataCon , " VarGADT" )
100
+ , (not , UseDataCon , " BoolGADT" )
101
+ ]
95
102
96
103
describe " golden" $ do
97
104
useTest " (,)" " UseConPair.hs" 2 8
Original file line number Diff line number Diff line change
1
+ {-# LANGUAGE GADTs #-}
2
+
1
3
-- Should suggest Left and Right, but not []
2
4
t1 :: Either a b
3
5
t1 = _
@@ -8,3 +10,12 @@ data ManyConstructors = C1 | C2 | C3 | C4 | C5 | C6 | C7 | C8 | C9 | C10
8
10
noCtorsIfMany :: ManyConstructors
9
11
noCtorsIfMany = _
10
12
13
+
14
+ data GADT a where
15
+ IntGADT :: GADT Int
16
+ BoolGADT :: GADT Bool
17
+ VarGADT :: GADT a
18
+
19
+ gadtCtor :: GADT Int
20
+ gadtCtor = _
21
+
You can’t perform that action at this time.
0 commit comments