Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove FeatureSet #1902

Merged
merged 2 commits into from
Jun 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion plugins/hls-tactics-plugin/hls-tactics-plugin.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ library
Wingman.Context
Wingman.Debug
Wingman.EmptyCase
Wingman.FeatureSet
Wingman.GHC
Wingman.Judgements
Wingman.Judgements.SYB
Expand Down
3 changes: 0 additions & 3 deletions plugins/hls-tactics-plugin/src/Wingman/EmptyCase.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import Prelude hiding (span)
import Prelude hiding (span)
import TcRnTypes (tcg_binds)
import Wingman.CodeGen (destructionFor)
import Wingman.FeatureSet
import Wingman.GHC
import Wingman.Judgements
import Wingman.LanguageServer
Expand Down Expand Up @@ -63,8 +62,6 @@ codeLensProvider state plId (CodeLensParams _ _ (TextDocumentIdentifier uri))
cfg <- getTacticConfig plId
ccs <- getClientCapabilities
liftIO $ fromMaybeT (Right $ List []) $ do
guard $ hasFeature FeatureEmptyCase $ cfg_feature_set cfg

dflags <- getIdeDynflags state nfp
TrackedStale pm _ <- stale GetAnnotatedParsedSource
TrackedStale binds bind_map <- stale GetBindings
Expand Down
99 changes: 0 additions & 99 deletions plugins/hls-tactics-plugin/src/Wingman/FeatureSet.hs

This file was deleted.

23 changes: 6 additions & 17 deletions plugins/hls-tactics-plugin/src/Wingman/KnownStrategies.hs
Original file line number Diff line number Diff line change
@@ -1,40 +1,29 @@
module Wingman.KnownStrategies where

import Control.Applicative (empty)
import Control.Monad.Error.Class
import Control.Monad.Reader.Class (asks)
import Data.Foldable (for_)
import OccName (mkVarOcc)
import Refinery.Tactic
import Wingman.Context (getCurrentDefinitions, getKnownInstance)
import Wingman.Judgements (jGoal)
import Wingman.KnownStrategies.QuickCheck (deriveArbitrary)
import Wingman.Machinery (tracing)
import Wingman.Tactics
import Wingman.Types
import Wingman.Judgements (jGoal)
import Data.Foldable (for_)
import Wingman.FeatureSet
import Control.Applicative (empty)
import Control.Monad.Reader.Class (asks)


knownStrategies :: TacticsM ()
knownStrategies = choice
[ known "fmap" deriveFmap
, known "mempty" deriveMempty
, known "arbitrary" deriveArbitrary
, featureGuard FeatureKnownMonoid $ known "<>" deriveMappend
, featureGuard FeatureKnownMonoid $ known "mappend" deriveMappend
, known "<>" deriveMappend
, known "mappend" deriveMappend
]


------------------------------------------------------------------------------
-- | Guard a tactic behind a feature.
featureGuard :: Feature -> TacticsM a -> TacticsM a
featureGuard feat t = do
fs <- asks $ cfg_feature_set . ctxConfig
case hasFeature feat fs of
True -> t
False -> empty


known :: String -> TacticsM () -> TacticsM ()
known name t = do
getCurrentDefinitions >>= \case
Expand Down
12 changes: 1 addition & 11 deletions plugins/hls-tactics-plugin/src/Wingman/LanguageServer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ import Retrie (transformA)
import SrcLoc (containsSpan)
import TcRnTypes (tcg_binds, TcGblEnv (tcg_rdr_env))
import Wingman.Context
import Wingman.FeatureSet
import Wingman.GHC
import Wingman.Judgements
import Wingman.Judgements.SYB (everythingContaining, metaprogramQ)
Expand Down Expand Up @@ -137,7 +136,6 @@ unsafeRunStaleIde herald state nfp a = do
properties :: Properties
'[ 'PropertyKey "hole_severity" ('TEnum (Maybe DiagnosticSeverity))
, 'PropertyKey "max_use_ctor_actions" 'TInteger
, 'PropertyKey "features" 'TString
, 'PropertyKey "timeout_duration" 'TInteger
, 'PropertyKey "auto_gas" 'TInteger
]
Expand All @@ -146,8 +144,6 @@ properties = emptyProperties
"The depth of the search tree when performing \"Attempt to fill hole\". Bigger values will be able to derive more solutions, but will take exponentially more time." 4
& defineIntegerProperty #timeout_duration
"The timeout for Wingman actions, in seconds" 2
& defineStringProperty #features
"Feature set used by Wingman" ""
& defineIntegerProperty #max_use_ctor_actions
"Maximum number of `Use constructor <x>` code actions that can appear" 5
& defineEnumProperty #hole_severity
Expand All @@ -165,16 +161,10 @@ properties = emptyProperties
getTacticConfig :: MonadLsp Plugin.Config m => PluginId -> m Config
getTacticConfig pId =
Config
<$> (parseFeatureSet <$> usePropertyLsp #features pId properties)
<*> usePropertyLsp #max_use_ctor_actions pId properties
<$> usePropertyLsp #max_use_ctor_actions pId properties
<*> usePropertyLsp #timeout_duration pId properties
<*> usePropertyLsp #auto_gas pId properties

------------------------------------------------------------------------------
-- | Get the current feature set from the plugin config.
getFeatureSet :: MonadLsp Plugin.Config m => PluginId -> m FeatureSet
getFeatureSet = fmap cfg_feature_set . getTacticConfig


getIdeDynflags
:: IdeState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ hoverProvider state plId (HoverParams (TextDocumentIdentifier uri) (unsafeMkCurr

cfg <- getTacticConfig plId
liftIO $ fromMaybeT (Right Nothing) $ do
-- guard $ hasFeature FeatureEmptyCase $ cfg_feature_set cfg

holes <- getMetaprogramsAtSpan state nfp $ RealSrcSpan $ unTrack loc

fmap (Right . Just) $
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module Wingman.LanguageServer.TacticProviders
) where

import Control.Monad
import Control.Monad.Reader (runReaderT)
import Data.Aeson
import Data.Bool (bool)
import Data.Coerce
Expand All @@ -30,15 +31,13 @@ import Language.LSP.Types
import OccName
import Prelude hiding (span)
import Wingman.Auto
import Wingman.FeatureSet
import Wingman.GHC
import Wingman.Judgements
import Wingman.Machinery (useNameFromHypothesis)
import Wingman.Metaprogramming.Lexer (ParserContext)
import Wingman.Metaprogramming.Parser (parseMetaprogram)
import Wingman.Tactics
import Wingman.Types
import Control.Monad.Reader (runReaderT)


------------------------------------------------------------------------------
Expand Down Expand Up @@ -115,7 +114,6 @@ commandProvider Destruct =
provide Destruct $ T.pack $ occNameString occ
commandProvider DestructPun =
requireHoleSort (== Hole) $
requireFeature FeatureDestructPun $
filterBindingType destructPunFilter $ \occ _ ->
provide DestructPun $ T.pack $ occNameString occ
commandProvider Homomorphism =
Expand All @@ -134,38 +132,33 @@ commandProvider HomomorphismLambdaCase =
provide HomomorphismLambdaCase ""
commandProvider DestructAll =
requireHoleSort (== Hole) $
requireFeature FeatureDestructAll $
withJudgement $ \jdg ->
case _jIsTopHole jdg && jHasBoundArgs jdg of
True -> provide DestructAll ""
False -> mempty
commandProvider UseDataCon =
requireHoleSort (== Hole) $
withConfig $ \cfg ->
requireFeature FeatureUseDataCon $
filterTypeProjection
( guardLength (<= cfg_max_use_ctor_actions cfg)
. fromMaybe []
. fmap fst
. tacticsGetDataCons
) $ \dcon ->
provide UseDataCon
. T.pack
. occNameString
. occName
$ dataConName dcon
filterTypeProjection
( guardLength (<= cfg_max_use_ctor_actions cfg)
. fromMaybe []
. fmap fst
. tacticsGetDataCons
) $ \dcon ->
provide UseDataCon
. T.pack
. occNameString
. occName
$ dataConName dcon
commandProvider Refine =
requireHoleSort (== Hole) $
requireFeature FeatureRefineHole $
provide Refine ""
commandProvider BeginMetaprogram =
requireGHC88OrHigher $
requireFeature FeatureMetaprogram $
requireHoleSort (== Hole) $
provide BeginMetaprogram ""
commandProvider RunMetaprogram =
requireGHC88OrHigher $
requireFeature FeatureMetaprogram $
withMetaprogram $ \mp ->
provide RunMetaprogram mp

Expand Down Expand Up @@ -213,16 +206,6 @@ data TacticParams = TacticParams
deriving anyclass (ToJSON, FromJSON)


------------------------------------------------------------------------------
-- | Restrict a 'TacticProvider', making sure it appears only when the given
-- 'Feature' is in the feature set.
requireFeature :: Feature -> TacticProvider -> TacticProvider
requireFeature f tp tpd =
case hasFeature f $ cfg_feature_set $ tpd_config tpd of
True -> tp tpd
False -> pure []


requireHoleSort :: (HoleSort -> Bool) -> TacticProvider -> TacticProvider
requireHoleSort p tp tpd =
case p $ tpd_hole_sort tpd of
Expand Down
7 changes: 2 additions & 5 deletions plugins/hls-tactics-plugin/src/Wingman/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import Type (TCvSubst, Var, eqType, nonDetCmpType, emptyTCvSubst)
import UniqSupply (takeUniqFromSupply, mkSplitUniqSupply, UniqSupply)
import Unique (nonDetCmpUnique, Uniquable, getUnique, Unique)
import Wingman.Debug
import Wingman.FeatureSet


------------------------------------------------------------------------------
Expand Down Expand Up @@ -84,17 +83,15 @@ tacticTitle = (mappend "Wingman: " .) . go
------------------------------------------------------------------------------
-- | Plugin configuration for tactics
data Config = Config
{ cfg_feature_set :: FeatureSet
, cfg_max_use_ctor_actions :: Int
{ cfg_max_use_ctor_actions :: Int
, cfg_timeout_seconds :: Int
, cfg_auto_gas :: Int
}
deriving (Eq, Ord, Show)

emptyConfig :: Config
emptyConfig = Config
{ cfg_feature_set = mempty
, cfg_max_use_ctor_actions = 5
{ cfg_max_use_ctor_actions = 5
, cfg_timeout_seconds = 2
, cfg_auto_gas = 4
}
Expand Down
5 changes: 2 additions & 3 deletions plugins/hls-tactics-plugin/test/CodeAction/AutoSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ module CodeAction.AutoSpec where
import Wingman.Types
import Test.Hspec
import Utils
import Wingman.FeatureSet (allFeatures)


spec :: Spec
Expand Down Expand Up @@ -83,6 +82,6 @@ spec = do


describe "messages" $ do
mkShowMessageTest allFeatures Auto "" 2 8 "MessageForallA" TacticErrors
mkShowMessageTest allFeatures Auto "" 7 8 "MessageCantUnify" TacticErrors
mkShowMessageTest Auto "" 2 8 "MessageForallA" TacticErrors
mkShowMessageTest Auto "" 7 8 "MessageCantUnify" TacticErrors

3 changes: 1 addition & 2 deletions plugins/hls-tactics-plugin/test/CodeAction/RefineSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ module CodeAction.RefineSpec where
import Wingman.Types
import Test.Hspec
import Utils
import Wingman.FeatureSet (allFeatures)


spec :: Spec
Expand All @@ -19,5 +18,5 @@ spec = do
refineTest 8 10 "RefineGADT"

describe "messages" $ do
mkShowMessageTest allFeatures Refine "" 2 8 "MessageForallA" TacticErrors
mkShowMessageTest Refine "" 2 8 "MessageForallA" TacticErrors

3 changes: 1 addition & 2 deletions plugins/hls-tactics-plugin/test/CodeLens/EmptyCaseSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ module CodeLens.EmptyCaseSpec where

import Test.Hspec
import Utils
import Wingman.FeatureSet (allFeatures)


spec :: Spec
spec = do
let test = mkCodeLensTest allFeatures
let test = mkCodeLensTest

describe "golden" $ do
test "EmptyCaseADT"
Expand Down