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 · 8 comments
Open

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

sanket-bhalerao opened this issue Aug 16, 2020 · 8 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 modified the milestones: Unreleased, gopls/v.0.5.0 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 the Thinking label Aug 28, 2020
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
4 participants
You can’t perform that action at this time.