-
Notifications
You must be signed in to change notification settings - Fork 18k
x/tools/go/analysis: overlapping suggested fixes result in a single, unhelpful error message #56535
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
Comments
You are getting overlapping suggestions. The first is to move One action that can be taken is to improve the error message to be less obscure. We can give the conflicting diffs that were not applied in the error message instead of giving the byte offsets. That way a user can apply one fix manually and then rerun the tool. We do not want to modify the tool to give one error message with a single fix. That would be misleading in other contexts (gopls or without -fix). We also do not want to the tool to pick one, try it, reapply the tool to see if it gets new edits, and repeat. This loop or other automated strategies seem like they are best done by a human. One option is to try to capture a "group edit" from checkers when generating a Diagnostic. These group edits could be applied when present and they do not overlapping with other groups of edits. Checkers that want to support these would need to produce them. This group edit idea would be a good candidate for a community contribution. Yet another strategy would be to leave the code in a state with merge conflicts. Something like git's https://git-scm.com/docs/git-merge#_how_conflicts_are_presented. This would usually break compilation. If this happened to be in the middle of a string, the code may still compile. Among these options I think the best is to give a better error message and to let users fix one of the issues until there are no overlapping edits. |
@timothy-king thanks for the reply, now it is clear to me. However, what do you think about another option, how about to add a flag to the tool, toggling which will skip fixing all such overlaping places in the code and will only fix those which it can without conflicts. Something like I propose that because this I issue I have encountered is actually in a very big project in which |
So the request would be that if To keep the implementation feasible this would need to go into x/tools/go/analysis/internal/checker and apply to all singlechecker and multichecker. A proposal is likely needed. I feel like this would be a somewhat reasonable extension of the
FWIW progress can be made in this situation by fixing the 1 overlap that is indicated manually. The tool can solve the rest when it is rerun. I understand that this might not be the smoothest user experience. |
+1 I just ran into this while trying to optimize https://github.com/onflow/cadence:
It would be great to have the suggested continuation feature, but before, it would be even more useful to just include the paths for the suggested edits. The path is missing right now, which requires tedious bisecting by trial and error of subpackages. After tracking down the problem, it turned out the given position ranges were not even line numbers, but file offsets, so very unhelpful and confusing. |
Change https://go.dev/cl/457615 mentions this issue: |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I have a project with a single file
main.go
. It has the code:I tried running
fieldalignment
tool on that:So, I see 2 issues and then I tried to fix them by adding
-fix
flag:And I get this weird error. Googling it gives me an issue about the case when the same piece of code get's replaced twice, it was fixed about 2 months ago.
However, in my case, there are pieces of code which both need to be fixed and one is inside of the other.
What did you expect to see?
I expect
fieldalignment
tool to process my file correctly and to do its fixesWhat did you see instead?
Error
The text was updated successfully, but these errors were encountered: