Skip to content

Commit 3e8d37a

Browse files
committed
Fix and reenable the rename plugin
1 parent 8c85ffd commit 3e8d37a

File tree

3 files changed

+40
-12
lines changed

3 files changed

+40
-12
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ jobs:
202202
name: Test hls-call-hierarchy-plugin test suite
203203
run: cabal test hls-call-hierarchy-plugin --test-options="$TEST_OPTS" || 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"
204204

205-
- if: matrix.test && matrix.ghc != '9.2.1'
205+
- if: matrix.test
206206
name: Test hls-rename-plugin test suite
207207
run: cabal test hls-rename-plugin --test-options="$TEST_OPTS" || 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"
208208

cabal-ghc921.project

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,7 @@ constraints:
6565
-retrie
6666
-splice
6767
-stylishhaskell
68-
-tactic
69-
-- the rename plugin builds, but doesn't work
70-
-rename,
68+
-tactic,
7169
ghc-lib-parser ^>= 9.2,
7270
attoparsec ^>= 0.14.3,
7371
ghc-exactprint >= 1.3,

plugins/hls-rename-plugin/src/Ide/Plugin/Rename.hs

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
{-# LANGUAGE CPP #-}
2-
{-# LANGUAGE DataKinds #-}
3-
{-# LANGUAGE GADTs #-}
4-
{-# LANGUAGE NamedFieldPuns #-}
1+
{-# LANGUAGE CPP #-}
2+
{-# LANGUAGE DataKinds #-}
3+
{-# LANGUAGE GADTs #-}
4+
{-# LANGUAGE NamedFieldPuns #-}
5+
{-# LANGUAGE RankNTypes #-}
6+
{-# LANGUAGE ScopedTypeVariables #-}
7+
{-# LANGUAGE TypeApplications #-}
58

69
module Ide.Plugin.Rename (descriptor) where
710

@@ -11,7 +14,7 @@ import Control.Monad.Trans.Class
1114
import Control.Monad.Trans.Except
1215
import Data.Containers.ListUtils
1316
import Data.Generics
14-
import Data.List.Extra hiding (nubOrd)
17+
import Data.List.Extra hiding (nubOrd, replace)
1518
import qualified Data.Map as M
1619
import Data.Maybe
1720
import qualified Data.Text as T
@@ -25,7 +28,10 @@ import GHC.Types.Name
2528
#else
2629
import Name
2730
#endif
31+
import Debug.Trace
2832
import Development.IDE.GHC.ExactPrint (GetAnnotatedParsedSource (GetAnnotatedParsedSource))
33+
import GHC.Parser.Annotation (AnnContext, AnnList,
34+
AnnParen, AnnPragma)
2935
import HieDb.Query
3036
import Ide.Plugin.Config
3137
import Ide.PluginUtils
@@ -44,11 +50,16 @@ renameProvider state pluginId (RenameParams (TextDocumentIdentifier uri) pos _pr
4450
response $ do
4551
nfp <- safeUriToNfp uri
4652
oldName <- getNameAtPos state nfp pos
53+
traceM $ "oldName: " <> prettyPrint oldName
4754
workspaceRefs <- refsAtName state nfp oldName
55+
traceM $ "workspaceRefs: " <> show workspaceRefs
4856
let filesRefs = groupOn locToUri workspaceRefs
4957
getFileEdits = ap (getSrcEdits state . renameModRefs newNameText) (locToUri . head)
5058

59+
traceM $ "\nfilesRefs: " <> show filesRefs
60+
5161
fileEdits <- mapM getFileEdits filesRefs
62+
traceM $ "\nfileEdits: " <> show fileEdits
5263
pure $ foldl' (<>) mempty fileEdits
5364

5465
-------------------------------------------------------------------------------
@@ -95,12 +106,32 @@ renameModRefs ::
95106
HsModule GhcPs
96107
-> HsModule GhcPs
97108
#endif
109+
#if MIN_VERSION_ghc(9,2,1)
110+
renameModRefs newNameText refs = everywhere $
111+
-- there has to be a better way...
112+
mkT (replace @AnnListItem) `extT`
113+
-- replace @AnnList `extT` -- not needed
114+
-- replace @AnnParen `extT` -- not needed
115+
-- replace @AnnPragma `extT` -- not needed
116+
-- replace @AnnContext `extT` -- not needed
117+
-- replace @NoEpAnns `extT` -- not needed
118+
replace @NameAnn
119+
where
120+
replace :: forall an. Typeable an => LocatedAn an RdrName -> LocatedAn an RdrName
121+
replace (L srcSpan oldRdrName)
122+
| isRef (locA srcSpan) = L srcSpan $ newRdrName oldRdrName
123+
replace lOldRdrName = lOldRdrName
124+
#else
98125
renameModRefs newNameText refs = everywhere $ mkT replace
99126
where
100127
replace :: Located RdrName -> Located RdrName
101128
replace (L srcSpan oldRdrName)
102129
| isRef srcSpan = L srcSpan $ newRdrName oldRdrName
103130
replace lOldRdrName = lOldRdrName
131+
#endif
132+
133+
isRef :: SrcSpan -> Bool
134+
isRef = (`elem` refs) . fromJust . srcSpanToLocation
104135

105136
newRdrName :: RdrName -> RdrName
106137
newRdrName oldRdrName = case oldRdrName of
@@ -109,9 +140,8 @@ renameModRefs newNameText refs = everywhere $ mkT replace
109140

110141
newOccName = mkTcOcc $ T.unpack newNameText
111142

112-
isRef :: SrcSpan -> Bool
113-
isRef = (`elem` refs) . fromJust . srcSpanToLocation
114-
143+
newRdrName :: RdrName -> RdrName
144+
newRdrName = error "not implemented"
115145
-------------------------------------------------------------------------------
116146
-- Reference finding
117147

0 commit comments

Comments
 (0)