File tree Expand file tree Collapse file tree 3 files changed +33
-6
lines changed
plugins/hls-tactics-plugin
src/Ide/Plugin/Tactic/LanguageServer Expand file tree Collapse file tree 3 files changed +33
-6
lines changed Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ import Data.Maybe
2222import Data.Monoid
2323import qualified Data.Text as T
2424import Data.Traversable
25- import DataCon (dataConName )
25+ import DataCon (dataConName , dataConCannotMatch )
2626import Development.IDE.GHC.Compat
2727import GHC.Generics
2828import GHC.LanguageExtensions.Type (Extension (LambdaCase ))
@@ -80,9 +80,7 @@ commandProvider UseDataCon =
8080 requireFeature FeatureUseDataCon $
8181 filterTypeProjection
8282 ( guardLength (<= cfg_max_use_ctor_actions cfg)
83- . fromMaybe []
84- . fmap fst
85- . tacticsGetDataCons
83+ . useCtorFilter
8684 ) $ \ dcon ->
8785 provide UseDataCon
8886 . T. pack
@@ -231,3 +229,14 @@ destructFilter :: Type -> Type -> Bool
231229destructFilter _ (algebraicTyCon -> Just _) = True
232230destructFilter _ _ = False
233231
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
8080 describe " provider" $ do
8181 mkTest
8282 " Suggests all data cons for Either"
83- " ConProviders.hs" 3 6
83+ " ConProviders.hs" 5 6
8484 [ (id , UseDataCon , " Left" )
8585 , (id , UseDataCon , " Right" )
8686 , (not , UseDataCon , " :" )
@@ -89,9 +89,16 @@ spec = do
8989 ]
9090 mkTest
9191 " Suggests no data cons for big types"
92- " ConProviders.hs" 9 17 $ do
92+ " ConProviders.hs" 11 17 $ do
9393 c <- [1 :: Int .. 10 ]
9494 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+ ]
95102
96103 describe " golden" $ do
97104 useTest " (,)" " UseConPair.hs" 2 8
Original file line number Diff line number Diff line change 1+ {-# LANGUAGE GADTs #-}
2+
13-- Should suggest Left and Right, but not []
24t1 :: Either a b
35t1 = _
@@ -8,3 +10,12 @@ data ManyConstructors = C1 | C2 | C3 | C4 | C5 | C6 | C7 | C8 | C9 | C10
810noCtorsIfMany :: ManyConstructors
911noCtorsIfMany = _
1012
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