Skip to content

Fix renaming data constructors with fields (resolves #2915, resolves #4083) #4635

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 20, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ packages:
./hls-test-utils


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

tests: True
test-show-details: direct
Expand Down
2 changes: 1 addition & 1 deletion ghcide/ghcide.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ library
, hashable
, hie-bios ^>=0.15.0
, hie-compat ^>=0.3.0.0
, hiedb ^>= 0.6.0.2
, hiedb ^>= 0.7.0.0
, hls-graph == 2.11.0.0
, hls-plugin-api == 2.11.0.0
, implicit-hie >= 0.1.4.0 && < 0.1.5
Expand Down
4 changes: 2 additions & 2 deletions haskell-language-server.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ library hls-call-hierarchy-plugin
, containers
, extra
, ghcide == 2.11.0.0
, hiedb ^>= 0.6.0.2
, hiedb ^>= 0.7.0.0
, hls-plugin-api == 2.11.0.0
, lens
, lsp >=2.7
Expand Down Expand Up @@ -594,7 +594,7 @@ library hls-rename-plugin
, containers
, ghcide == 2.11.0.0
, hashable
, hiedb ^>= 0.6.0.2
, hiedb ^>= 0.7.0.0
, hie-compat
, hls-plugin-api == 2.11.0.0
, haskell-language-server:hls-refactor-plugin
Expand Down
7 changes: 7 additions & 0 deletions plugins/hls-rename-plugin/src/Ide/Plugin/Rename.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ import qualified Development.IDE.GHC.ExactPrint as E
import Development.IDE.Plugin.CodeAction
import Development.IDE.Spans.AtPoint
import Development.IDE.Types.Location
import HieDb ((:.) (..))
import HieDb.Query
import HieDb.Types (RefRow (refIsGenerated))
import Ide.Plugin.Error
import Ide.Plugin.Properties
import Ide.PluginUtils
Expand Down Expand Up @@ -196,6 +198,11 @@ refsAtName state nfp name = do
dbRefs <- case nameModule_maybe name of
Nothing -> pure []
Just mod -> liftIO $ mapMaybe rowToLoc <$> withHieDb (\hieDb ->
-- GHC inserts `Use`s of record constructor everywhere where its record selectors are used,
-- which leads to fields being renamed whenever corresponding constructor is renamed.
-- see https://github.com/haskell/haskell-language-server/issues/2915
-- To work around this, we filter out compiler-generated references.
filter (\(refRow HieDb.:. _) -> not $ refIsGenerated refRow) <$>
findReferences
hieDb
True
Expand Down
2 changes: 1 addition & 1 deletion plugins/hls-rename-plugin/test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ goldenWithRename title path act =
goldenWithHaskellDoc (def { plugins = M.fromList [("rename", def { plcConfig = "crossModule" .= True })] })
renamePlugin title testDataDir path "expected" "hs" act

renameExpectError :: (TResponseError Method_TextDocumentRename) -> TextDocumentIdentifier -> Position -> Text -> Session ()
renameExpectError :: TResponseError Method_TextDocumentRename -> TextDocumentIdentifier -> Position -> Text -> Session ()
renameExpectError expectedError doc pos newName = do
let params = RenameParams Nothing doc pos newName
rsp <- request SMethod_TextDocumentRename params
Expand Down
Loading