Skip to content

Handle file rename in .cabal file - #4961

Open
VeryMilkyJoe wants to merge 2 commits into
haskell:masterfrom
VeryMilkyJoe:rename-file-cabal
Open

Handle file rename in .cabal file#4961
VeryMilkyJoe wants to merge 2 commits into
haskell:masterfrom
VeryMilkyJoe:rename-file-cabal

Conversation

@VeryMilkyJoe

@VeryMilkyJoe VeryMilkyJoe commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

On a WillRenameFile Notification, we find the responsible .cabal file for the old filepath and replace the corresponding module path with the module path for the new file name.

This is part of the implementation of #4951.
In the next PR, I will propagate the rename in Haskell files, i.e. rename in module declaration and imports.

Screencast.From.2026-06-08.10-19-12.mp4

On WillRename Notification, edit the responsible .cabal file to change
the module name entry of the renamed module  to the new name.
@VeryMilkyJoe
VeryMilkyJoe force-pushed the rename-file-cabal branch 2 times, most recently from f5de604 to 4eece12 Compare August 6, 2026 17:55

@dyniec dyniec left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename yay!
Looks fine,and tests seem alright. Should be fine to merge when CI succeeds

@Aster89 Aster89 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love this!

Some newbie comments below 😆

Comment thread hls-test-utils/src/Test/Hls/Util.hs Outdated
Comment thread hls-test-utils/src/Test/Hls/Util.hs Outdated
Comment thread hls-test-utils/src/Test/Hls/Util.hs Outdated
Comment thread hls-test-utils/src/Test/Hls/Util.hs Outdated
Comment thread plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal/CabalAdd/Rename.hs Outdated
Comment thread plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal/CabalAdd/Rename.hs
Comment thread plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal/CabalAdd/Rename.hs
@VeryMilkyJoe
VeryMilkyJoe force-pushed the rename-file-cabal branch 3 times, most recently from 3d311bb to 2cce790 Compare August 6, 2026 19:49
Comment thread hls-test-utils/src/Test/Hls/Util.hs
runActionE "cabalAdd.getVersionedTextDoc" ideState $
lift $
getVersionedTextDoc $
TextDocumentIdentifier (filePathToUri cabalFilePath)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this take the normalized uri?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it takes a Uri as defined by the type of TextDocumentIdentifier.

Maybe.maybe [] exposedModules $ library pd
LSubLibName _ ->
concat $ Maybe.concatMapM (getExposedModulesForLib compName) $ subLibraries pd
_ -> []

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_ -> []
CNotLibName -> ?

I think executables can have other-modules and need to be handled here but not 100% sure.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is handled later on, the first part here checks only whether the module is in exposed modules if it occurs, since there are more limited cases for this.
If the module still occurs in a field but was not in an exposed module then it has to be in other modules, which would cover the case you proposed.
I changed the code a bit to hopefully improve readability.

@VeryMilkyJoe
VeryMilkyJoe force-pushed the rename-file-cabal branch 2 times, most recently from 80a48ef to 50250f1 Compare August 6, 2026 20:39
Comment thread hls-test-utils/src/Test/Hls/Util.hs Outdated
Comment thread hls-test-utils/src/Test/Hls/Util.hs Outdated
@VeryMilkyJoe
VeryMilkyJoe force-pushed the rename-file-cabal branch 2 times, most recently from 9546635 to 584441e Compare August 9, 2026 12:01
Add tests and corresponding test utils for integration testing of renaming files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants