Skip to content

Commit 1ca33e3

Browse files
committed
Prevent renaming record fields whenever record constructor is renamed
1 parent 4c7e56a commit 1ca33e3

File tree

5 files changed

+12
-5
lines changed

5 files changed

+12
-5
lines changed

cabal.project

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ packages:
88
./hls-test-utils
99

1010

11-
index-state: 2025-06-07T14:57:40Z
11+
index-state: 2025-06-16T09:44:13Z
1212

1313
tests: True
1414
test-show-details: direct

ghcide/ghcide.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ library
7575
, hashable
7676
, hie-bios ^>=0.15.0
7777
, hie-compat ^>=0.3.0.0
78-
, hiedb ^>= 0.6.0.2
78+
, hiedb ^>= 0.7.0.0
7979
, hls-graph == 2.11.0.0
8080
, hls-plugin-api == 2.11.0.0
8181
, implicit-hie >= 0.1.4.0 && < 0.1.5

haskell-language-server.cabal

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ library hls-call-hierarchy-plugin
407407
, containers
408408
, extra
409409
, ghcide == 2.11.0.0
410-
, hiedb ^>= 0.6.0.2
410+
, hiedb ^>= 0.7.0.0
411411
, hls-plugin-api == 2.11.0.0
412412
, lens
413413
, lsp >=2.7
@@ -594,7 +594,7 @@ library hls-rename-plugin
594594
, containers
595595
, ghcide == 2.11.0.0
596596
, hashable
597-
, hiedb ^>= 0.6.0.2
597+
, hiedb ^>= 0.7.0.0
598598
, hie-compat
599599
, hls-plugin-api == 2.11.0.0
600600
, haskell-language-server:hls-refactor-plugin

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ import qualified Development.IDE.GHC.ExactPrint as E
4242
import Development.IDE.Plugin.CodeAction
4343
import Development.IDE.Spans.AtPoint
4444
import Development.IDE.Types.Location
45+
import HieDb ((:.) (..))
4546
import HieDb.Query
47+
import HieDb.Types (RefRow (refIsGenerated))
4648
import Ide.Plugin.Error
4749
import Ide.Plugin.Properties
4850
import Ide.PluginUtils
@@ -196,6 +198,11 @@ refsAtName state nfp name = do
196198
dbRefs <- case nameModule_maybe name of
197199
Nothing -> pure []
198200
Just mod -> liftIO $ mapMaybe rowToLoc <$> withHieDb (\hieDb ->
201+
-- GHC inserts `Use`s of record constructor everywhere where its record selectors are used,
202+
-- which leads to fields being renamed whenever corresponding constructor is renamed.
203+
-- see https://github.com/haskell/haskell-language-server/issues/2915
204+
-- To work around this, we filter out compiler-generated references.
205+
filter (\(refRow HieDb.:. _) -> not $ refIsGenerated refRow) <$>
199206
findReferences
200207
hieDb
201208
True

plugins/hls-rename-plugin/test/Main.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ goldenWithRename title path act =
113113
goldenWithHaskellDoc (def { plugins = M.fromList [("rename", def { plcConfig = "crossModule" .= True })] })
114114
renamePlugin title testDataDir path "expected" "hs" act
115115

116-
renameExpectError :: (TResponseError Method_TextDocumentRename) -> TextDocumentIdentifier -> Position -> Text -> Session ()
116+
renameExpectError :: TResponseError Method_TextDocumentRename -> TextDocumentIdentifier -> Position -> Text -> Session ()
117117
renameExpectError expectedError doc pos newName = do
118118
let params = RenameParams Nothing doc pos newName
119119
rsp <- request SMethod_TextDocumentRename params

0 commit comments

Comments
 (0)