From a542c2d8c222bb7d4ecfa33796e9f0a8f2b9a7c7 Mon Sep 17 00:00:00 2001 From: Zubin Duggal Date: Mon, 26 Dec 2022 14:16:01 +0530 Subject: [PATCH] Add 9.4.4 binaries and drop 9.4.2 --- .github/workflows/test.yml | 2 +- haskell-language-server.cabal | 2 +- .../hls-rename-plugin/hls-rename-plugin.cabal | 9 +------ .../src/Ide/Plugin/Rename.hs | 25 +++++++++++++++++-- 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3497327883..bfbe8382a1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -225,7 +225,7 @@ jobs: name: Test hls-call-hierarchy-plugin test suite run: cabal test hls-call-hierarchy-plugin --test-options="$TEST_OPTS" || LSP_TEST_LOG_COLOR=0 LSP_TEST_LOG_MESSAGES=true LSP_TEST_LOG_STDERR=true cabal test hls-call-hierarchy-plugin --test-options="$TEST_OPTS" - - if: matrix.test && matrix.os != 'windows-latest' && matrix.ghc != '9.4.2' && matrix.ghc != '9.4.3' + - if: matrix.test && matrix.os != 'windows-latest' name: Test hls-rename-plugin test suite run: cabal test hls-rename-plugin --test-options="$TEST_OPTS" || LSP_TEST_LOG_COLOR=0 LSP_TEST_LOG_MESSAGES=true LSP_TEST_LOG_STDERR=true cabal test hls-rename-plugin --test-options="$TEST_OPTS" diff --git a/haskell-language-server.cabal b/haskell-language-server.cabal index 87d1ed518e..d60e99a9da 100644 --- a/haskell-language-server.cabal +++ b/haskell-language-server.cabal @@ -257,7 +257,7 @@ common refineImports cpp-options: -Dhls_refineImports common rename - if flag(rename) && (impl(ghc < 9.4.1) || flag(ignore-plugins-ghc-bounds)) + if flag(rename) build-depends: hls-rename-plugin ^>= 1.0 cpp-options: -Dhls_rename diff --git a/plugins/hls-rename-plugin/hls-rename-plugin.cabal b/plugins/hls-rename-plugin/hls-rename-plugin.cabal index 3b28121a58..eca7705e84 100644 --- a/plugins/hls-rename-plugin/hls-rename-plugin.cabal +++ b/plugins/hls-rename-plugin/hls-rename-plugin.cabal @@ -21,10 +21,6 @@ source-repository head 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: @@ -36,6 +32,7 @@ library , ghcide ^>=1.8 || ^>= 1.9 , hashable , hiedb + , hie-compat , hls-plugin-api ^>= 1.3 || ^>=1.4 || ^>= 1.5 || ^>= 1.6 , hls-refactor-plugin , lsp @@ -49,10 +46,6 @@ library 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 diff --git a/plugins/hls-rename-plugin/src/Ide/Plugin/Rename.hs b/plugins/hls-rename-plugin/src/Ide/Plugin/Rename.hs index 9b17b65b93..f711eea36a 100644 --- a/plugins/hls-rename-plugin/src/Ide/Plugin/Rename.hs +++ b/plugins/hls-rename-plugin/src/Ide/Plugin/Rename.hs @@ -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.IO.Class 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.PluginUtils 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 @@ renameProvider state pluginId (RenameParams (TextDocumentIdentifier uri) pos _pr 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 @@ handleGetHieAst :: 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