haskell-tools-refactor 0.8.0.0 → 0.8.1.0
raw patch · 7 files changed
+45/−12 lines, 7 filesdep ~Cabaldep ~ghcdep ~haskell-tools-refactorPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: Cabal, ghc, haskell-tools-refactor, template-haskell, time
API changes (from Hackage documentation)
+ Language.Haskell.Tools.Refactor.GetModules: lookupSourceFileColl :: FilePath -> [ModuleCollection] -> Maybe (ModuleCollection)
Files
- Language/Haskell/Tools/Refactor/GetModules.hs +5/−0
- Language/Haskell/Tools/Refactor/Predefined/OrganizeImports.hs +4/−1
- Language/Haskell/Tools/Refactor/Session.hs +4/−2
- examples/Refactor/OrganizeImports/Coerce.hs +11/−0
- examples/Refactor/OrganizeImports/Coerce_res.hs +11/−0
- haskell-tools-refactor.cabal +9/−9
- test/Main.hs +1/−0
Language/Haskell/Tools/Refactor/GetModules.hs view
@@ -82,6 +82,9 @@ lookupModuleColl :: String -> [ModuleCollection] -> Maybe (ModuleCollection) lookupModuleColl moduleName = find (any ((moduleName ==) . (^. sfkModuleName)) . Map.keys . (^. mcModules)) +lookupSourceFileColl :: FilePath -> [ModuleCollection] -> Maybe (ModuleCollection) +lookupSourceFileColl fp = find (any ((fp ==) . (^. sfkFileName)) . Map.keys . (^. mcModules)) + lookupModInSCs :: SourceFileKey -> [ModuleCollection] -> Maybe (SourceFileKey, ModuleRecord) lookupModInSCs moduleName = find (((moduleName ^. sfkFileName) ==) . (^. sfkFileName) . fst) . concatMap (Map.assocs . (^. mcModules)) @@ -180,6 +183,8 @@ ++ catMaybes (map (toModuleCollection pkg) (benchmarks pkg)) toModuleCollection :: ToModuleCollection tmc => PackageDescription -> tmc -> Maybe ModuleCollection + toModuleCollection PackageDescription{ buildType = Just Custom } tmc + = error "While parsing cabal file \"build-type: custom\" is not supported" toModuleCollection pkg tmc = let bi = getBuildInfo tmc packageName = pkgName $ package pkg
Language/Haskell/Tools/Refactor/Predefined/OrganizeImports.hs view
@@ -20,9 +20,10 @@ import Language.Haskell.TH.LanguageExtensions as GHC (Extension(..)) import Name (NamedThing(..)) import OccName (HasOccName(..), isSymOcc) -import qualified PrelNames as GHC (fromStringName) +import qualified PrelNames as GHC (fromStringName, coerceKey) import TyCon (TyCon(..), tyConFamInst_maybe) import SrcLoc +import Unique (getUnique) import Control.Applicative ((<$>), Alternative(..)) import Control.Monad @@ -50,6 +51,7 @@ = xopt TemplateHaskell dfs -- no narrowing if TH is present (we don't know what will be used) || xopt QuasiQuotes dfs -- no narrowing if TH quotes are present (we don't know what will be used) || (xopt FlexibleInstances dfs && noNarrowingSubspecs) -- arbitrary ctors might be needed when using imported data families + || hasCoerce -- the presence of coerce implicitely requires the constructors to be present noNarrowingSubspecs = -- both standalone deriving and FFI marshalling can cause constructors to be used in the generated code xopt GHC.StandaloneDeriving dfs || hasMarshalling @@ -83,6 +85,7 @@ -- Checks if the module uses foreign import/export that requires marshalling. In this case no -- subspecifiers could be narrowed because constructors might be needed. hasMarshalling = not $ null @[] (mod ^? modDecl & annList & declForeignType) + hasCoerce = GHC.coerceKey `elem` map getUnique usedNames -- Can this name be part of the source code? -- isSourceName n = ':' `notElem` occNameString (occName n)
Language/Haskell/Tools/Refactor/Session.hs view
@@ -5,6 +5,7 @@ -- | Common operations for managing refactoring sessions, for example loading packages, re-loading modules. module Language.Haskell.Tools.Refactor.Session where +import Control.Applicative ((<|>)) import Control.Exception import Control.Monad.State.Strict import Control.Reference @@ -125,9 +126,10 @@ reloadModule :: IsRefactSessionState st => (ModSummary -> IO a) -> ModSummary -> StateT st Ghc a reloadModule report ms = do mcs <- gets (^. refSessMCs) - let modName = modSumName ms + let fp = getModSumOrig ms + modName = modSumName ms codeGen = needsGeneratedCode (keyFromMS ms) mcs - case lookupModuleColl modName mcs of + case lookupSourceFileColl fp mcs <|> lookupModuleColl modName mcs of Just mc -> do let dfs = ms_hspp_opts ms dfs' <- liftIO $ compileInContext mc mcs dfs
+ examples/Refactor/OrganizeImports/Coerce.hs view
@@ -0,0 +1,11 @@+module Refactor.OrganizeImports.Coerce where + +import Prelude () +import Data.Maybe (Maybe(Just, Nothing)) +import Data.List +import Data.Coerce (coerce) + +newtype Mayb' a = Mayb' (Maybe a) + +a :: Mayb' a -> Maybe a +a = coerce
+ examples/Refactor/OrganizeImports/Coerce_res.hs view
@@ -0,0 +1,11 @@+module Refactor.OrganizeImports.Coerce where + +import Data.Coerce (coerce) +import Data.List +import Data.Maybe (Maybe(Just, Nothing)) +import Prelude () + +newtype Mayb' a = Mayb' (Maybe a) + +a :: Mayb' a -> Maybe a +a = coerce
haskell-tools-refactor.cabal view
@@ -1,5 +1,5 @@ name: haskell-tools-refactor -version: 0.8.0.0 +version: 0.8.1.0 synopsis: Refactoring Tool for Haskell description: Contains a set of refactorings based on the Haskell-Tools framework to easily transform a Haskell program. For the descriptions of the implemented refactorings, see the homepage. homepage: https://github.com/haskell-tools/haskell-tools @@ -88,9 +88,9 @@ , references >= 0.3 && < 0.4 , split >= 0.2 && < 0.3 , filepath >= 1.4 && < 1.5 - , template-haskell >= 2.11 && < 2.12 - , ghc >= 8.0 && < 8.1 - , Cabal >= 1.24 && < 1.25 + , template-haskell >= 2.11 && < 2.13 + , ghc >= 8.0 && < 8.3 + , Cabal >= 1.24 && < 2.1 , haskell-tools-ast >= 0.8 && < 0.9 , haskell-tools-backend-ghc >= 0.8 && < 0.9 , haskell-tools-rewrite >= 0.8 && < 0.9 @@ -114,16 +114,16 @@ , directory >= 1.2 && < 1.4 , references >= 0.3 && < 0.4 , split >= 0.2 && < 0.3 - , time >= 1.6 && < 1.7 - , template-haskell >= 2.11 && < 2.12 - , ghc >= 8.0 && < 8.1 + , time >= 1.6 && < 1.9 + , template-haskell >= 2.11 && < 2.13 + , ghc >= 8.0 && < 8.3 , ghc-paths >= 0.1 && < 0.2 - , Cabal >= 1.24 && < 1.25 + , Cabal >= 1.24 && < 2.1 , haskell-tools-ast >= 0.8 && < 0.9 , haskell-tools-backend-ghc >= 0.8 && < 0.9 , haskell-tools-rewrite >= 0.8 && < 0.9 , haskell-tools-prettyprint >= 0.8 && < 0.9 - , haskell-tools-refactor >= 0.8 && < 0.9 + , haskell-tools-refactor -- libraries used by the examples , old-time >= 1.1 && < 1.2 , polyparse >= 1.12 && < 1.13
test/Main.hs view
@@ -232,6 +232,7 @@ , "Refactor.OrganizeImports.Reorder" , "Refactor.OrganizeImports.Ctor" , "Refactor.OrganizeImports.Class" + , "Refactor.OrganizeImports.Coerce" , "Refactor.OrganizeImports.Fields" , "Refactor.OrganizeImports.Operator" , "Refactor.OrganizeImports.SameName"