-
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: highlight deprecated symbols #40447
Comments
May I have a take on this? I would be happy to support Actually, I already started to investigate and think I might found the correct place to implement: Do you agree that this is the correct place this needs to be implemented or would you recommend somewhere else? |
@jotdl: Absolutely, we'd love to have you contribute! You're right that this would be another analysis pass, though the feature may already be available through Staticcheck (which is off-by-default right now): https://staticcheck.io/docs/checks#SA1019. LSP also has a diagnostic tag that allows us to mark something as deprecated (https://microsoft.github.io/language-server-protocol/specifications/specification-3-16/#diagnostic), so one option might be to enable this particular check by default and set the tag for any of its warnings. |
Yes, you are absolutely right. I didn't know yet that gopls comes with staticcheck. Sorry about that! So it seems that in order to solve this, we actually don't need to implement the analysis part itself and could rely on staticcheck instead. I did give this a try, but couldn't get it to work. A look into the staticcheck analysis code for deprecation warnings shows that it relies on facts produced by package dependencies (deprecated.go L59). After a bit of debugging I found that we currently don't execute analysis for package dependencies anymore (due #35089 ): After reenabling this code the analysis rule works again and then it's just a matter of adding the correct diagnostic tag which should be as easy as (as addition to if e.Category == "SA1019" {
tags = append(tags, protocol.Deprecated)
} But I am not sure how to proceed in perspective to #35089 . Are there any plans to reenable it? |
Thank you for doing all of this investigation, and I'm sorry you had to do so much digging! Re-enabling that logic more correctly is now tracked by #38278, which will not happen for a while, but it seems like we can probably re-enable it for this case. The changes you describe seem reasonable to me, so if you'd like to mail them, we'd love to get your contribution! One note is that we will be freezing the |
No worries, I didn't expect something different as language servers are usually quite complicated and it's fun to read through all the code and get an idea of what's happening :) So just to sum up things:
Please correct me if I misunderstood something. I'll try to get a PR up this evening. But I also need to check the contribution guidelines as this would be my first contribution. Edit: Sorry, I didn't make it tonight. Everything is setup now, but I am not sure yet how and where this change is supposed to be tested. Need to look more into the testing part of |
Yep, that all sounds correct to me! The contribution guidelines can be found at https://golang.org/doc/contribute.html, and there are some testing-related docs here: https://github.com/golang/tools/tree/master/internal/lsp/tests. |
I am still on it, but sadly I am currently stuck: When I enable the analyzation of package dependencies for SA1019 in analysis.go line 117 via
running the tests via It took me a while to figure out which tests are causing this behaviour and it seems like
are the cause of this issue. At least removing them fixes the hanging tests. I could already mail the changes. But without fixing the tests I guess the changes are not worth much. |
If you'd like to mail the changes, I'd be happy to take a look and see if I can identify the issue. |
There doesn't seem to be any standard way of saying that something is deprecated. For instance, io/ioutil just says that there are better alternatives, while net/http uses the word Deprecated. Is the list the staticcheck uses (https://github.com/dominikh/go-tools/blob/v0.0.1-2020.1.6/deprecated/stdlib.go) hand generated? (last updated for go1.14) |
@pjweinb There is no "enforced" way of marking something as deprecated, but I think it's widely accepted to use the Deprecated word as documented in https://github.com/golang/go/wiki/Deprecated and the majority of go developers deprecate code as documented there. I am not sure if t the staticcheck list you mentioned is written by hand, but it looks to me like it was. I could think of a couple of reasons why they did so, but that's something you would better ask in the staticcheck repository as I sadly don't know a lot about it. |
@stamblerre I am really sorry that I was unable to push this further during the last two months. As I was unable to test this and just got stuck I felt like it's not worth to push my changes as they are so minimal and even not tested. Anyways, I'll rebase my changes and check what the current state is. Maybe I can figure out now what needs to be done in order to get the tests running. |
Yes. I apologize for the misunderstanding. My point was about trying to automate the process of finding out what was obsolete, and I thought this would be a good place to remember what I found. Some languages use @deprecated in function documentation, but Go doesn't. |
I don't know enough information, and now it comes to this question. I want to make sure that this problem still exists. I use vscode to develop the go language, and I find that it doesn't work when the method is annotated as follows
If the previous line next to the deprecated also has a comment, it will not work properly,Add a newline to the deprecated comment and it will work properly my gopls version is:
|
@eryajf, the comment in that code does not conform to the deprecation notice convention. The deprecation notice must be on in separate paragraph and have a short comment. |
So should the correct usage be like this?
At this point, the original comment |
@eryajf, that is a separate comment, not a paragraph within the same comment. The Wiki page has an example. Something like: // TestFunc is a test func.
//
// Deprecated: use NewTestFunc instead. |
@ainar-g When I write like this, it doesn't work. |
@eryajf, I've only now noticed that this issue is not closed. So it's no wonder that The format is correct now, and if you need some checker right now, you can use |
Maybe it's just vscode's problem. When I use goland, the problem disappears I came here from this question golang/vscode-go/issues/599 . The problem on the other side has been closed, but it doesn't seem to be solved. |
vscode-go side issue was closed because it's a duplicate of this issue. |
I understand. I hope gopls can pay attention to this problem again here, so that it can be solved in vscode development. |
This comment was marked as off-topic.
This comment was marked as off-topic.
Gopls also has However, some may prefer strikethrough to this squiggle presentation. I played a bit with SA1019 diagnostics in gopls. It looks like if we change SA1019 diagnostics to be mapped to Diagnostics with severity=hint(4), tags=[Deprecated], this will produce the effect we want: The easiest path I see to enable this is to use honnef.co/go/tools/analysis/facts/deprecated which already is x/tools/go/analysis.Analyzer. (@dominikh ) We also need to sort out
Another minor caveat is staticcheck module requires go1.19+. Not sure if the In addition to this diagnostics that are presented on the callsites, I think it is also cool if we can add deprecation info to
☝️ Help wanted. |
It does.
There is a good chance that the It's also worth noting that |
Change https://go.dev/cl/508508 mentions this issue: |
How to enable this 'highlight depreated symbols' feature? I installed gopls from the master branch, which contains the merged PR: https://go-review.googlesource.com/c/tools/+/508508, And I also restart the vscode. |
It's enabled by default and the feature is available in the latest release. |
@hyangah Here's my example code: this is my gopls setting in settings.json:
gopls version is v0.13.1 (latest now): gopls version
golang.org/x/tools/gopls v0.13.1
golang.org/x/tools/[email protected] h1:Q0cfPbEG1WVfgxcRZ9uKTA6/ckIRNXx6Ym7KgT/VFE4= go version is go1.19.5:
|
@hitzhangjie Can you hover over the For example, editor setting errors (build tags), or issues related to the module boundary (doc) are some of the common issues we've seen. |
@hyangah Sorry for this example. I put the example under a module but I doesn't use go.work. After I put the main.go, add.go under a new clean project folder, the yellow error message gone, and: I also tried another example, |
Thanks @hitzhangjie |
@hyangah OK. Thanks for the explaination. |
@hyangah In my case i want it to highlight to colleagues use another private methods because they (method, not colleagues %) ) will be removed in short time, but can't be removed just now for backward compatibility. And visually highlighting this would be better, that if i just say it. It would be very helpful. |
I'm using
gopls
(see version information below) with Vim (version8.1
) andnatebosch/vim-lsc
(version632d49bf7a
).Currently, when I hover over a deprecated symbol, I don't see any messages about the deprecation in Vim's statusline, and the symbol isn't highlighted. I assume, it's because
gopls
doesn't support that. I would like to see those messages.The text was updated successfully, but these errors were encountered: