-
-
Notifications
You must be signed in to change notification settings - Fork 369
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Tactic Featuresets (#1398)
* Implement featuresets * Make Tactics tests run with a full feature set * Respond to feedback from @wz1000 * Cleanup imports in Types Co-authored-by: Javier Neira <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
- Loading branch information
1 parent
ba12bbd
commit ff9a182
Showing
10 changed files
with
206 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
plugins/hls-tactics-plugin/src/Ide/Plugin/Tactic/FeatureSet.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE PatternSynonyms #-} | ||
{-# LANGUAGE ViewPatterns #-} | ||
|
||
module Ide.Plugin.Tactic.FeatureSet | ||
( Feature (..) | ||
, FeatureSet | ||
, hasFeature | ||
, defaultFeatures | ||
, allFeatures | ||
, parseFeatureSet | ||
, prettyFeatureSet | ||
) where | ||
|
||
import Data.List (intercalate) | ||
import Data.Maybe (mapMaybe, listToMaybe) | ||
import Data.Set (Set) | ||
import qualified Data.Set as S | ||
import qualified Data.Text as T | ||
|
||
|
||
------------------------------------------------------------------------------ | ||
-- | All the available features. A 'FeatureSet' describes the ones currently | ||
-- available to the user. | ||
data Feature = CantHaveAnEmptyDataType | ||
deriving (Eq, Ord, Show, Read, Enum, Bounded) | ||
|
||
|
||
------------------------------------------------------------------------------ | ||
-- | A collection of enabled features. | ||
type FeatureSet = Set Feature | ||
|
||
|
||
------------------------------------------------------------------------------ | ||
-- | Parse a feature set. | ||
parseFeatureSet :: T.Text -> FeatureSet | ||
parseFeatureSet | ||
= mappend defaultFeatures | ||
. S.fromList | ||
. mapMaybe (readMaybe . mappend featurePrefix . rot13 . T.unpack) | ||
. T.split (== '/') | ||
|
||
|
||
------------------------------------------------------------------------------ | ||
-- | Features that are globally enabled for all users. | ||
defaultFeatures :: FeatureSet | ||
defaultFeatures = S.fromList | ||
[ | ||
] | ||
|
||
|
||
------------------------------------------------------------------------------ | ||
-- | All available features. | ||
allFeatures :: FeatureSet | ||
allFeatures = S.fromList $ enumFromTo minBound maxBound | ||
|
||
|
||
------------------------------------------------------------------------------ | ||
-- | Pretty print a feature set. | ||
prettyFeatureSet :: FeatureSet -> String | ||
prettyFeatureSet | ||
= intercalate "/" | ||
. fmap (rot13 . drop (length featurePrefix) . show) | ||
. S.toList | ||
|
||
|
||
------------------------------------------------------------------------------ | ||
-- | Is a given 'Feature' currently enabled? | ||
hasFeature :: Feature -> FeatureSet -> Bool | ||
hasFeature = S.member | ||
|
||
|
||
------------------------------------------------------------------------------ | ||
-- | Like 'read', but not partial. | ||
readMaybe :: Read a => String -> Maybe a | ||
readMaybe = fmap fst . listToMaybe . reads | ||
|
||
|
||
featurePrefix :: String | ||
featurePrefix = "Feature" | ||
|
||
|
||
rot13 :: String -> String | ||
rot13 = fmap (toEnum . rot13int . fromEnum) | ||
|
||
|
||
rot13int :: Integral a => a -> a | ||
rot13int x | ||
| (fromIntegral x :: Word) - 97 < 26 = 97 + rem (x - 84) 26 | ||
| (fromIntegral x :: Word) - 65 < 26 = 65 + rem (x - 52) 26 | ||
| otherwise = x | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.