hls-rename-plugin 1.0.2.0 → 1.0.2.1
raw patch · 3 files changed
+28/−13 lines, 3 filesdep +hie-compatdep ~hls-test-utilsPVP ok
version bump matches the API change (PVP)
Dependencies added: hie-compat
Dependency ranges changed: hls-test-utils
API changes (from Hackage documentation)
Files
- hls-rename-plugin.cabal +4/−11
- src/Ide/Plugin/Rename.hs +23/−2
- test/Main.hs +1/−0
hls-rename-plugin.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.4 name: hls-rename-plugin-version: 1.0.2.0+version: 1.0.2.1 synopsis: Rename plugin for Haskell Language Server description: Please see the README on GitHub at <https://github.com/haskell/haskell-language-server#readme>@@ -21,10 +21,6 @@ location: https://github.com/haskell/haskell-language-server.git library- if impl(ghc >= 9.3)- buildable: False- else- buildable: True exposed-modules: Ide.Plugin.Rename hs-source-dirs: src build-depends:@@ -33,9 +29,10 @@ , extra , ghc , ghc-exactprint- , ghcide ^>=1.8 || ^>= 1.9+ , ghcide ^>= 1.9 || ^>= 1.10 , hashable , hiedb+ , hie-compat , hls-plugin-api ^>= 1.3 || ^>=1.4 || ^>= 1.5 || ^>= 1.6 , hls-refactor-plugin , lsp@@ -49,10 +46,6 @@ default-language: Haskell2010 test-suite tests- if impl(ghc >= 9.3)- buildable: False- else- buildable: True type: exitcode-stdio-1.0 default-language: Haskell2010 hs-source-dirs: test@@ -65,4 +58,4 @@ , filepath , hls-plugin-api , hls-rename-plugin- , hls-test-utils ^>=1.5+ , hls-test-utils ^>=1.6
src/Ide/Plugin/Rename.hs view
@@ -8,6 +8,7 @@ {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeApplications #-}+{-# LANGUAGE RecordWildCards #-} module Ide.Plugin.Rename (descriptor, E.Log) where @@ -21,11 +22,13 @@ import Control.Monad.Trans.Class import Control.Monad.Trans.Except import Data.Generics+import Data.Bifunctor (first) import Data.Hashable import Data.HashSet (HashSet) import qualified Data.HashSet as HS import Data.List.Extra hiding (length) import qualified Data.Map as M+import qualified Data.Set as S import Data.Maybe import Data.Mod.Word import qualified Data.Text as T@@ -51,6 +54,7 @@ import Ide.Types import Language.LSP.Server import Language.LSP.Types+import Compat.HieTypes instance Hashable (Mod a) where hash n = hash (unMod n) @@ -74,7 +78,10 @@ See the `IndirectPuns` test for an example. -} indirectOldNames <- concat . filter ((>1) . Prelude.length) <$> mapM (uncurry (getNamesAtPos state) . locToFilePos) directRefs- let oldNames = indirectOldNames ++ directOldNames+ let oldNames = (filter matchesDirect indirectOldNames) ++ directOldNames+ matchesDirect n = occNameFS (nameOccName n) `elem` directFS+ where+ directFS = map (occNameFS. nameOccName) directOldNames refs <- HS.fromList . concat <$> mapM (refsAtName state nfp) oldNames -- Validate rename@@ -220,7 +227,21 @@ ExceptT String m (HieAstResult, PositionMapping) handleGetHieAst state nfp = handleMaybeM ("No AST for file: " ++ show nfp)- (liftIO $ runAction "Rename.GetHieAst" state $ useWithStale GetHieAst nfp)+ (liftIO $ fmap (fmap (first removeGenerated)) $ runAction "Rename.GetHieAst" state $ useWithStale GetHieAst nfp)++-- | We don't want to rename in code generated by GHC as this gives false positives.+-- So we restrict the HIE file to remove all the generated code.+removeGenerated :: HieAstResult -> HieAstResult+removeGenerated HAR{..} = HAR{hieAst = go hieAst,..}+ where+ go :: HieASTs a -> HieASTs a+ go hf =+#if MIN_VERSION_ghc(9,2,1)+ HieASTs (fmap goAst (getAsts hf))+ goAst (Node nsi sp xs) = Node (SourcedNodeInfo $ M.restrictKeys (getSourcedNodeInfo nsi) (S.singleton SourceInfo)) sp (map goAst xs)+#else+ hf+#endif handleUriToNfp :: (Monad m) => Uri -> ExceptT String m NormalizedFilePath handleUriToNfp uri = handleMaybe
test/Main.hs view
@@ -6,6 +6,7 @@ import qualified Data.Map as M import Ide.Plugin.Config import qualified Ide.Plugin.Rename as Rename+import Ide.Types (IdePlugins (IdePlugins)) import System.FilePath import Test.Hls