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

x/tools/gopls: add codelens for references to symbols #40862

Open
sanket-bhalerao opened this issue Aug 16, 2020 · 12 comments
Open

x/tools/gopls: add codelens for references to symbols #40862

sanket-bhalerao opened this issue Aug 16, 2020 · 12 comments

Comments

@sanket-bhalerao
Copy link

@sanket-bhalerao sanket-bhalerao commented Aug 16, 2020

Issue Type: Feature Request

it would be nice to see if a function is referenced in the code or not.
click on the codelens and see all the places the variable, function being referenced.

variable:
image

functions:
image

Extension version: 2020.8.1301
VS Code version: Code - Insiders 1.49.0-insider (bd08768fd310d34cdd4423a53e5f3ca77340fea5, 2020-08-14T05:56:40.601Z)
OS version: Windows_NT x64 10.0.18363

@stamblerre
Copy link
Contributor

@stamblerre stamblerre commented Aug 17, 2020

I believe that this feature is supported in GOPATH mode, but is not yet available via the language server. I have been hesitant to add it, since users should just be able to call "Find References" on a symbol to get this information. I would be curious to hear input from others before we move forward with this.

@sanket-bhalerao
Copy link
Author

@sanket-bhalerao sanket-bhalerao commented Aug 17, 2020

@stamblerre, i tried following for the GOPATH mode.

  • set GOPATH to current working directory
  • install all the tools required for the extension
  • my settings for go are
    image

i still dont see the codelens.
am i missing something?

@hyangah
Copy link
Contributor

@hyangah hyangah commented Aug 17, 2020

The codelens is off by default, so you will need to turn it on explicitly.

"go.enableCodeLens": {
        "references": true,
    }

But, if you are using the language server, why not use the Find References feature which is faster and doesn't add much visual noise to the code.

@sanket-bhalerao
Copy link
Author

@sanket-bhalerao sanket-bhalerao commented Aug 17, 2020

@hyangah , thanks for the help
as to why not use find reference, i work mainly with angular and now just habituated with the codelens. i feel more comfortable with it i guess

@hyangah
Copy link
Contributor

@hyangah hyangah commented Aug 17, 2020

@sanket-bhalerao Is your goal to simply check whether the variable or function is used or not (boolean decision), or you use it to really find all the locations they are used? For former, I think we can do better with color or other visualization than with codelens. For latter, maybe we should discuss more.

@sanket-bhalerao
Copy link
Author

@sanket-bhalerao sanket-bhalerao commented Aug 18, 2020

@hyangah for variables its the boolean decision (as golang shows unused var as errors this part is already covered)
for functions and methods I use it for find if it is referenced at alss and all the places its used.

@hyangah hyangah changed the title codelens for functions, variables x/tools/gopls: consider codelens for functions, variables references Aug 18, 2020
@hyangah
Copy link
Contributor

@hyangah hyangah commented Aug 18, 2020

@sanket-bhalerao Thanks! I will transfer this to gopls issue tracker.

@hyangah hyangah transferred this issue from golang/vscode-go Aug 18, 2020
@gopherbot gopherbot added this to the Unreleased milestone Aug 18, 2020
@stamblerre stamblerre removed this from the Unreleased milestone Aug 25, 2020
@stamblerre stamblerre added this to the gopls/v.0.5.0 milestone Aug 25, 2020
@stamblerre stamblerre removed this from the gopls/v.0.5.0 milestone Aug 25, 2020
@stamblerre stamblerre changed the title x/tools/gopls: consider codelens for functions, variables references x/tools/gopls: add codelens for references to symbols Aug 25, 2020
@stamblerre
Copy link
Contributor

@stamblerre stamblerre commented Aug 25, 2020

Thanks for the feature request, @sanket-bhalerao. I'd like to hear from others about the benefits of this feature. Currently, my preference would be to add the 'unused' checks from staticcheck (#36602), which might make this feature a little redundant.

@stamblerre stamblerre added this to the gopls/unplanned milestone Oct 21, 2020
@TheSecEng
Copy link

@TheSecEng TheSecEng commented Jun 14, 2021

references is a quick insight into how many times a function is being called an generally would allow the end click to create a view into where the functions / etc are being used for quick looks. I think this is much more valuable than what is being shown here. And completely different from staticcheck. Just look at elm language server for instance

@stamblerre
Copy link
Contributor

@stamblerre stamblerre commented Jun 14, 2021

references is a quick insight into how many times a function is being called an generally would allow the end click to create a view into where the functions / etc are being used for quick looks. I think this is much more valuable than what is being shown here. And completely different from staticcheck. Just look at elm language server for instance

This feature is already available by right-clicking an identifier and selecting "Find all references". The code lens would make it easy to tell if a symbol is referenced, which is typically used to see if it is used anywhere in the workspace--much like the staticcheck 'unused' check.

@TheSecEng
Copy link

@TheSecEng TheSecEng commented Jun 14, 2021

I guess a workaround to get this feature would just have the client implementation make the request automatically rather than having to click and request them. 🤷‍♂️ Seems like it may be more of a personal preference thing at that point ?

@stamblerre
Copy link
Contributor

@stamblerre stamblerre commented Jun 21, 2021

I think we would be open to this feature being added in gopls, but it would have to be off by default, because it would be expensive to constantly call "find references" on every symbol in a given file. Still, we will not prioritize work on this, so if a community member would like to pick this up and send a CL, please follow up here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants