-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
x/tools/gopls: report unnecessarily exported symbols #67573
Comments
Change https://go.dev/cl/586781 mentions this issue: |
We could easily add this as a code action "Show unnecessarily exported symbols" whose associated command should indicate one of two things (that don't currently exist in LSP, but should):
@findleyr had a neat idea: produce the report as a web page (which we could easily do today), with a list of checkboxes, one per function. The user could select a subset of them then hit an "Apply changes" button, which would cause the server to send one or more ApplyEdit downcalls to do the renamings. |
All of these functions are no longer referenced across packages since we cleaned up the server/lsprpc/golang split. CanExtractVariable EmbedDefinition EnclosingStaticCall FormatNodeFile LinknameDefinition CanExtractFunction Updates golang/go#67573 Change-Id: I18490b333d79bad83eb5fcc34688fb41381771d1 Reviewed-on: https://go-review.googlesource.com/c/tools/+/586781 Reviewed-by: Robert Findley <rfindley@google.com> Auto-Submit: Alan Donovan <adonovan@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
👍 to this feature. As a companion feature, a code action to easily toggle exported-ness of a single symbol (or struct member) would also be helpful! That would make it easier to fix one-off instances as you see them, without needing to explicitly run the analysis for the entire package/workspace. I imagine the necessary pieces of functionality would be very similar to those needed for a report like this. |
Some edge cases one might not expect:
Here are some of the findings of a quick experiment:
|
After a code reorganization, many symbols may continue to be exported even though they are no longer referenced from another package. Just as it is helpful to report dead code within an application, it would be useful to report symbols that could safely be unexported.
Gopls has all the information required to do this; we should expose it on request in the UI somehow.
(Or this could be a feature of cmd/deadcode. But cmd/deadcode could be a feature of gopls, too.)
The text was updated successfully, but these errors were encountered: