From 03bd5109f9407132966c30e0b05ab4f2f45086e4 Mon Sep 17 00:00:00 2001 From: mrkun Date: Sun, 16 Jan 2022 22:12:24 +0300 Subject: [PATCH 1/2] [ghc-9.2.1] Fix refine-imports plugin --- .github/workflows/test.yml | 2 +- cabal-ghc921.project | 1 - ghcide/src/Development/IDE/GHC/Compat/Core.hs | 8 ++++++++ haskell-language-server.cabal | 2 +- .../hls-refine-imports-plugin.cabal | 2 +- .../src/Ide/Plugin/RefineImports.hs | 8 ++++---- stack-9.2.1.yaml | 1 - 7 files changed, 15 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3a61cef4ca..b8a9abf4c2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -198,7 +198,7 @@ jobs: name: Test hls-tactics-plugin test suite run: cabal test hls-tactics-plugin --test-options="$TEST_OPTS" || cabal test hls-tactics-plugin --test-options="$TEST_OPTS" || LSP_TEST_LOG_COLOR=0 LSP_TEST_LOG_MESSAGES=true LSP_TEST_LOG_STDERR=true cabal test hls-tactics-plugin --test-options="$TEST_OPTS" - - if: matrix.test && matrix.ghc != '9.2.1' + - if: matrix.test name: Test hls-refine-imports-plugin test suite run: cabal test hls-refine-imports-plugin --test-options="$TEST_OPTS" || cabal test hls-refine-imports-plugin --test-options="$TEST_OPTS" || LSP_TEST_LOG_COLOR=0 LSP_TEST_LOG_MESSAGES=true LSP_TEST_LOG_STDERR=true cabal test hls-refine-imports-plugin --test-options="$TEST_OPTS" diff --git a/cabal-ghc921.project b/cabal-ghc921.project index 66a6447024..2ad661358a 100644 --- a/cabal-ghc921.project +++ b/cabal-ghc921.project @@ -59,7 +59,6 @@ constraints: -eval -haddockComments -hlint - -refineImports -retrie -splice -stylishhaskell diff --git a/ghcide/src/Development/IDE/GHC/Compat/Core.hs b/ghcide/src/Development/IDE/GHC/Compat/Core.hs index f64984d0cf..d767bb1a7f 100644 --- a/ghcide/src/Development/IDE/GHC/Compat/Core.hs +++ b/ghcide/src/Development/IDE/GHC/Compat/Core.hs @@ -193,6 +193,7 @@ module Development.IDE.GHC.Compat.Core ( getLoc, getLocA, locA, + noLocA, LocatedAn, #if MIN_VERSION_ghc(9,2,0) GHC.AnnListItem(..), @@ -1021,6 +1022,13 @@ getLocA = GHC.getLocA getLocA x = GHC.getLoc x #endif +noLocA :: a -> LocatedAn an a +#if MIN_VERSION_ghc(9,2,0) +noLocA = GHC.noLocA +#else +noLocA = GHC.noLoc +#endif + #if !MIN_VERSION_ghc(9,2,0) type AnnListItem = SrcLoc.SrcSpan #endif diff --git a/haskell-language-server.cabal b/haskell-language-server.cabal index 2e2203263a..919f8bb2c0 100644 --- a/haskell-language-server.cabal +++ b/haskell-language-server.cabal @@ -234,7 +234,7 @@ common importLens cpp-options: -DimportLens common refineImports - if flag(refineImports) && (impl(ghc < 9.2.1) || flag(ignore-plugins-ghc-bounds)) + if flag(refineImports) build-depends: hls-refine-imports-plugin ^>=1.0.0.0 cpp-options: -DrefineImports diff --git a/plugins/hls-refine-imports-plugin/hls-refine-imports-plugin.cabal b/plugins/hls-refine-imports-plugin/hls-refine-imports-plugin.cabal index cee9508f3a..8312a76d80 100644 --- a/plugins/hls-refine-imports-plugin/hls-refine-imports-plugin.cabal +++ b/plugins/hls-refine-imports-plugin/hls-refine-imports-plugin.cabal @@ -1,6 +1,6 @@ cabal-version: 2.4 name: hls-refine-imports-plugin -version: 1.0.0.2 +version: 1.0.0.3 synopsis: Refine imports plugin for Haskell Language Server description: Please see the README on GitHub at diff --git a/plugins/hls-refine-imports-plugin/src/Ide/Plugin/RefineImports.hs b/plugins/hls-refine-imports-plugin/src/Ide/Plugin/RefineImports.hs index 375009af53..6e505377cc 100644 --- a/plugins/hls-refine-imports-plugin/src/Ide/Plugin/RefineImports.hs +++ b/plugins/hls-refine-imports-plugin/src/Ide/Plugin/RefineImports.hs @@ -215,8 +215,8 @@ refineImportsRule = define $ \RefineImports nfp -> do i@(L lim id@ImportDecl {ideclName = L _ mn, ideclHiding = Just (hiding, L _ names)}) (newModuleName, avails) = L lim id - { ideclName = noLoc newModuleName - , ideclHiding = Just (hiding, noLoc newNames) + { ideclName = noLocA newModuleName + , ideclHiding = Just (hiding, noLocA newNames) } where newNames = filter (\n -> any (n `containsAvail`) avails) names constructImport lim _ = lim @@ -247,9 +247,9 @@ refineImportsRule = define $ \RefineImports nfp -> do -------------------------------------------------------------------------------- -mkExplicitEdit :: PositionMapping -> LImportDecl pass -> T.Text -> Maybe TextEdit +mkExplicitEdit :: PositionMapping -> LImportDecl GhcRn -> T.Text -> Maybe TextEdit mkExplicitEdit posMapping (L src imp) explicit - | RealSrcSpan l _ <- src, + | RealSrcSpan l _ <- locA src, L _ mn <- ideclName imp, -- (almost) no one wants to see an refine import list for Prelude mn /= moduleName pRELUDE, diff --git a/stack-9.2.1.yaml b/stack-9.2.1.yaml index 847b56bffb..597fd8b587 100644 --- a/stack-9.2.1.yaml +++ b/stack-9.2.1.yaml @@ -101,7 +101,6 @@ flags: hlint: false importLens: false ormolu: false - refineImports: false retrie: false splice: false stylishhaskell: false From bb383292778a176f1dcf2e24034838634df2b67f Mon Sep 17 00:00:00 2001 From: mrkun Date: Mon, 17 Jan 2022 20:57:46 +0300 Subject: [PATCH 2/2] Drop accidental top-level undefined --- plugins/hls-rename-plugin/src/Ide/Plugin/Rename.hs | 3 --- 1 file changed, 3 deletions(-) diff --git a/plugins/hls-rename-plugin/src/Ide/Plugin/Rename.hs b/plugins/hls-rename-plugin/src/Ide/Plugin/Rename.hs index b13623d8f9..b9ca9798ea 100644 --- a/plugins/hls-rename-plugin/src/Ide/Plugin/Rename.hs +++ b/plugins/hls-rename-plugin/src/Ide/Plugin/Rename.hs @@ -134,9 +134,6 @@ renameModRefs newNameText refs = everywhere $ mkT replace _ -> Unqual newOccName newOccName = mkTcOcc $ T.unpack newNameText - -newRdrName :: RdrName -> RdrName -newRdrName = error "not implemented" ------------------------------------------------------------------------------- -- Reference finding