-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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 to show number of references to each symbol #40862
Comments
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. |
@stamblerre, i tried following for the GOPATH mode.
i still dont see the codelens. |
The codelens is off by default, so you will need to turn it on explicitly.
But, if you are using the language server, why not use the |
@hyangah , thanks for the help |
@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. |
@hyangah for variables its the boolean decision (as golang shows unused var as errors this part is already covered) |
@sanket-bhalerao Thanks! I will transfer this to gopls issue tracker. |
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. |
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. |
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 ? |
I think we would be open to this feature being added in |
We implemented this feature in our extension, tooltitude. We focus on augmenting gopls with convenience and productivity features. For example on screenshot you could see the usages of Join in the "stirngs" on kubernetes repo. It computed all reference counts in around 500ms on my M1 Max Macbook pro. On smaller files, and projects it's much faster. On machines with more cores the perf is even better. P.S. You could read more about it here: https://www.tooltitude.com/ You could install from here: https://marketplace.visualstudio.com/items?itemName=tooltitudeteam.tooltitude cc @TerminalFi @stamblerre @hyangah @sanket-bhalerao P.S. Updated check time value to reflect a fix of a bug. |
Looks cool! I am a ST User, and maintain LSP-gopls. I see this is closed source. That is too bad |
@TerminalFi In theory nothing prevents it working from within ST. It's mostly LSP, with some additional requests and notifications to improve integration with VSCode. At some point we will consider it, taking into account that sublime is closed source too and people happily pay for performance (i.e. they are more likely than vscode users to be interested in commercial extension). |
@TerminalFi I have a VS Code extension that is open-source here: https://github.com/tkg-codes/go-interface-annotations. I have also mentioned this in #56695 unfortunately there doesn't seem to be any movement on this one. :( I moved to neovim since making that extension for VSCode and it seems I can't get the same thing working on nvim, which is really, really sad. |
Time to move to Sublime ;) |
Hm, are you getting this data from |
Yes. Essentially this is the logic I am using.
for symbol in symbols:
params = {
'textDocument': {'uri': view_to_uri(self.view)},
'position': symbol['selectionRange']['start']
}
request = Request("textDocument/references", params) |
Hm, this is what I tried. Hm. Maybe I just messed something up the last time. Oh well, got a new weekend project, I guess. Cheers! |
@tkgalk I actually have a working implementation in a branch of gopls. I need to figure out the proper way to open an MR for it though. Seems to be relatively fast @stamblerre I might need a little direction on handling sending the response back to the client. Looks like i need to do something in |
Yeah, I managed to code something for neovim, I'll release it later on GitHub for anyone wanting to use it, but I need to finish some stuff first (filter out declarations, add configuration options and squash a bug or two). Thanks for pointing me in the right direction. :D While making it, I also found that someone had already done something similar, though: https://github.com/VidocqH/lsp-lens.nvim. |
Yeah, just meant that this should be in core once I finish this. So it won't need to be handled by the client. |
Nice extensions !!! |
Any news on this matter? |
any updates on this? |
No, this is a paid extension with pretty mature price ( I think getting JB Goland will be a cheaper option lol), afwul that we does not have such a basic functionality with default vscode extension |
To be fair to Tooltitude, I think that specific part of the reference count is free. https://github.com/tkgalk/go-interface-annotations you can take a look at my extension that does this. It is implemented in a fairly naive way, though, so in big codebases or large files it might be slow, but I haven't tested it thoroughly as I don't use VS Code anymore. But yes, it is a shame, that this isn't part of the gopls itself. |
looks awesome! thank you, definitely will try it |
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:
functions:
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
The text was updated successfully, but these errors were encountered: