-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Catching errors in code fix using Renamer #197
Comments
You should avoid doing anything computationally expensive when determining whether to offer a code fix action. Finding rename conflicts can be very expensive. Save expensive work to run under the code action. Also, you can use ConflictAnnotation and WarningAnnotation to identify the places where the user should be notified and/or agree to before the code fix is applied. The Renamer should be adding conflict annotations where conflicts occur. Do you not get conflict warnings in the code fix preview if the rename has identified conflicts? |
Right now I only tested this functionality within unit tests. I need to run the same functionality in-IDE and I'll let you know the results. I agree with the performance implications. Several code fixes we have need to be updated to lazily compute the results. That is mostly a separate issue, but relates here because it means we should always propose the rename, even if it results in a conflict. |
Normally when there's a need to rename something in a codefix, it's best to just attach a For this particular fix, you want to simply add a I to the front of the interface name - even there it might be reasonable to make that change and start the inline rename session and have the user commit the rename explicitly - that way they can choose to accept or decline based on conflicts etc. |
@mattwar The preview UI did not behave as expected, because renaming the symbol caused the problem to appear on the identifier for the second interface definition, which is not visible in the preview for the code fix. BeforePreviewAfter |
@srivatsn I applied
|
You are right. The Meanwhile, with regards to your other reply, I think the preview is supposed to show the conflicts when there are conflict annotations. I wonder if the Renamer API strips them out before handing out the final solution. Either way it sounds like a problem worth thinking more about. |
Regardless, the rename API should probably return the conflicts as well instead of just the new solution. |
We have a couple internal work items tracking this, including 917587 & 916524.
We currently remove all rename annotations before returning the updated Solution.
👍 |
@jmarolf This is the bug ("It would be nice if the RenameAnnotation took a string called initialText and populated the rename session with that text - that would solve your problem.") I mentioned to you a couple days ago. |
Closing due to lack of movement. |
We have a Code Fix which uses
Renamer
to rename a symbol according to naming conventions for a project. While the diagnostic we use for breaking the naming convention should always be reported, we would like to either suppress the code fix or revert its behavior if the rename operation results in two symbols with conflicting names.❓ What is the recommended practice for this scenario?
For reference, the issue was initially raised in DotNetAnalyzers/StyleCopAnalyzers#436, where we hope to establish a standard practice for code fixes that rename symbols.
The text was updated successfully, but these errors were encountered: