hsdev 0.2.3.1 → 0.2.3.2
raw patch · 4 files changed
+24/−39 lines, 4 filesdep ~text-region
Dependency ranges changed: text-region
Files
- hsdev.cabal +2/−2
- src/HsDev/Client/Commands.hs +8/−11
- src/HsDev/Tools/AutoFix.hs +5/−13
- tools/hsautofix.hs +9/−13
hsdev.cabal view
@@ -1,5 +1,5 @@ name: hsdev -version: 0.2.3.1 +version: 0.2.3.2 synopsis: Haskell development library description: Haskell development library and tool with support of autocompletion, symbol info, go to declaration, find references, hayoo search etc. @@ -149,7 +149,7 @@ syb >= 0.5.1, template-haskell, text >= 1.2.0, - text-region >= 0.1 && < 0.2, + text-region == 0.2.*, time >= 1.5.0, transformers >= 0.4.0, transformers-base >= 0.4.0,
src/HsDev/Client/Commands.hs view
@@ -229,19 +229,16 @@ runCommand (AutoFix (AutoFixFix ns rest isPure)) = toValue $ do files <- liftM (ordNub . sort) $ mapM findPath $ mapMaybe (preview $ Tools.noteSource . moduleFile) ns let - doFix :: FilePath -> String -> ([Tools.Note AutoFix.Correction], String) - doFix file cts = AutoFix.edit cts fUpCorrs $ do - AutoFix.autoFix fCorrs - State.gets (view AutoFix.regions) - where - findCorrs :: FilePath -> [Tools.Note AutoFix.Correction] -> [Tools.Note AutoFix.Correction] - findCorrs f = filter ((== Just f) . preview (Tools.noteSource . moduleFile)) - fCorrs = map (view Tools.note) $ findCorrs file ns - fUpCorrs = findCorrs file rest + doFix :: FilePath -> Maybe String -> ([Tools.Note AutoFix.Correction], Maybe String) + doFix file mcts = AutoFix.autoFix fCorrs (fUpCorrs, mcts) where + findCorrs :: FilePath -> [Tools.Note AutoFix.Correction] -> [Tools.Note AutoFix.Correction] + findCorrs f = filter ((== Just f) . preview (Tools.noteSource . moduleFile)) + fCorrs = findCorrs file ns + fUpCorrs = findCorrs file rest runFix file - | isPure = return $ fst $ doFix file "" + | isPure = return $ fst $ doFix file Nothing | otherwise = do - (corrs', cts') <- liftM (doFix file) $ liftIO $ readFileUtf8 file + (corrs', Just cts') <- liftM (doFix file) $ liftIO $ Just <$> readFileUtf8 file liftIO $ writeFileUtf8 file cts' return corrs' liftM concat $ mapM runFix files
src/HsDev/Tools/AutoFix.hs view
@@ -3,7 +3,7 @@ module HsDev.Tools.AutoFix ( Correction(..), correctionMessage, corrector, - correct, corrections, + corrections, autoFix, CorrectorMatch, correctors, @@ -15,7 +15,7 @@ ) where import Control.Applicative -import Control.Lens (makeLenses, set, view, (^.), over) +import Control.Lens hiding ((.=), at) import Data.Aeson import Data.Maybe (listToMaybe, mapMaybe) import Data.Text.Region hiding (Region(..)) @@ -41,17 +41,8 @@ v .:: "message" <*> v .:: "corrector" -instance ApplyMap Correction where - applyMap m (Correction msg c) = Correction msg (applyMap m c) - -instance ApplyMap a => ApplyMap (Note a) where - applyMap m = over note (applyMap m) - makeLenses ''Correction -correct :: Correction -> Edit String -correct c = Chain [_corrector c] - corrections :: [Note OutputMessage] -> [Note Correction] corrections = mapMaybe toCorrection where toCorrection :: Note OutputMessage -> Maybe (Note Correction) @@ -68,8 +59,9 @@ n -- | Apply corrections -autoFix :: ApplyMap r => [Correction] -> EditM String r () -autoFix = run . mconcat . map correct +autoFix :: [Note Correction] -> ([Note Correction], Maybe String) -> ([Note Correction], Maybe String) +autoFix ns (upd, mcts) = (over (each . note . corrector . replaceRegion) (update act) upd, over (_Just . contents) (apply act) mcts) where + act = Edit (ns ^.. each . note . corrector) type CorrectorMatch = Note OutputMessage -> Maybe (Note Correction)
tools/hsautofix.hs view
@@ -4,11 +4,10 @@ main ) where -import Control.Lens (view, preview) +import Control.Lens (preview) import Control.Arrow ((***)) import Control.Monad (liftM) import Control.Monad.IO.Class (liftIO) -import Control.Monad.State (gets) import Control.Monad.Except (throwError) import Data.Aeson hiding (Error) import Data.List (partition, sort) @@ -73,19 +72,16 @@ partition (check . fst) $ zip [1..] corrs files <- liftE $ mapM canonicalizePath $ ordNub $ sort $ mapMaybe (preview $ noteSource . moduleFile) corrs let - doFix :: FilePath -> String -> ([Note Correction], String) - doFix file cts = edit cts upCorrs' $ do - autoFix fixCorrs' - gets (view regions) - where - findCorrs :: FilePath -> [Note Correction] -> [Note Correction] - findCorrs f = filter ((== Just f) . preview (noteSource . moduleFile)) - fixCorrs' = map (view note) $ findCorrs file fixCorrs - upCorrs' = findCorrs file upCorrs + doFix :: FilePath -> Maybe String -> ([Note Correction], Maybe String) + doFix file mcts = autoFix fixCorrs' (upCorrs', mcts) where + findCorrs :: FilePath -> [Note Correction] -> [Note Correction] + findCorrs f = filter ((== Just f) . preview (noteSource . moduleFile)) + fixCorrs' = findCorrs file fixCorrs + upCorrs' = findCorrs file upCorrs runFix file - | pure' = return $ fst $ doFix file "" + | pure' = return $ fst $ doFix file Nothing | otherwise = do - (corrs', cts') <- liftM (doFix file) $ liftE $ readFileUtf8 file + (corrs', Just cts') <- liftM (doFix file) $ liftE $ liftM Just $ readFileUtf8 file liftE $ writeFileUtf8 file cts' return corrs' liftM concat $ mapM runFix files