golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.52k stars 17.6k forks source link

x/tools/gopls: reference shadow warning should provide more context #53052

Open pjweinb opened 2 years ago

pjweinb commented 2 years ago

gopls version

at tip

What did you do?

I try to rename a symbol

What did you see ?

A message in a box saying renaming this type "Limit" to "int" would shadow this reference to the type declared here

The message is unhelpful, as there is no information about where in the code the mysterious problem occurs.

hyangah commented 2 years ago

Indeed error messages without context are cryptic. I guess the error message was from https://github.com/golang/tools/blob/d5f48fca5379171ebce583082a3dd683c8f8ad75/internal/lsp/source/rename_check.go#L181

I see the context like position is ignored.
@suzmue Is there any reason that this position info needs to be dropped? On the other hand, if this error is surfaced as a popup like this, we need more than token.Pos

suzmue commented 2 years ago

I believe the positions were dropped during the migration from gorename to gopls just as a matter of making the error messages more readable. We absolutely can / probably should add the positions back in to the error messages.