Skip to content
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

Rename only if the current module compiles (#3799) #3848

Merged
merged 2 commits into from
Apr 21, 2024

Conversation

sgillespie
Copy link
Contributor

This PR resolves #3799 by using useE rather than useWithStaleE. I did not implement the suggestion to have two modi, for local renames only and for cross module renaming, rather I just fixed the issue raised in the issue.

Copy link
Collaborator

@fendor fendor left a comment

Choose a reason for hiding this comment

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

The changes look good to me!

Can we add a test case for this scenario?
E.g. start with a well-typed module, wait for some diagnostics, modify it such that compilation fails, wait for diagnostics, fix the compile error and request to rename an identifier.
I think, the test case should be flaky (e.g. sometimes fail) without this patch and always succeed with this patch applied.

@sgillespie
Copy link
Contributor Author

I've added a new test for hls-rename-plugin, and I've verified it fails for HEAD^ and succeeds for HEAD. I'm not sure about the organization of the new tests (the other tests are straightforward golden tests), so let me know if you want me to change that. I used hls-hlint-plugin for inspiration.

Copy link
Collaborator

@fendor fendor left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@fendor fendor added the status: needs review This PR is ready for review label Oct 22, 2023
handleGetHieAst state nfp =
fmap (first removeGenerated) $ runActionE "Rename.GetHieAst" state $ useWithStaleE GetHieAst nfp
fmap removeGenerated $ runActionE "Rename.GetHieAst" state $ useE GetHieAst nfp
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
fmap removeGenerated $ runActionE "Rename.GetHieAst" state $ useE GetHieAst nfp
-- We explicitly do not want to allow a stale version here - we only want to rename if
-- the module compiles, otherwise we can't guarantee that we'll rename everything,
-- which is bad (see https://github.com/haskell/haskell-language-server/issues/3799)
fmap removeGenerated $ runActionE "Rename.GetHieAst" state $ useE GetHieAst nfp

Copy link
Collaborator

@michaelpj michaelpj left a comment

Choose a reason for hiding this comment

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

Please add a comment, otherwise this subtle but important information will be lost.

@fendor
Copy link
Collaborator

fendor commented Jan 4, 2024

@sgillespie Do you have the time capacity to push this over the finish line? It looks like, resolving merge conflicts and updating the comment should be enough :)

@sgillespie
Copy link
Contributor Author

@fendor I'm sorry I missed everything way back in Nov-Jan. In any case, I've updated from master and added the comment.

Copy link
Collaborator

@fendor fendor left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for being patient with us!

@michaelpj michaelpj merged commit 463eb2f into haskell:master Apr 21, 2024
39 checks passed
soulomoon pushed a commit that referenced this pull request Apr 22, 2024
* Rename only if the current module compiles (#3799)

Prefer `useE` over `useWithStaleE`

* Add a rename test that tests for compilation errors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs review This PR is ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Renaming in presence of type errors
3 participants