-
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: show full comments for constant or variable declaration #48200
Comments
Thanks for the request, and the analysis. I think if there's a way of presenting all relevant doc comments such that no context is lost, we'd welcome it. Considering the suggestion:
One problem I see with this is that the last sentence looks out of place: absent context it's not entirely clear what it's modifying. This isn't that egregious an example, but one can imagine other cases where the spec.Comment is even more out of place. I wonder if we should format an abbreviated declaration. Perhaps something like this?
We're unlikely to have time to prioritize this soon, but we'd welcome a contribution. However, before contributing we should decide on an ideal presentation here. |
We've just discussed this issue, and consensus was that formatting a truncated form of the full const decl (as shown in #48200 (comment)) makes sense. However, it isn't something we're likely to work on soon, so leaving this as 'help wanted'. |
Hi @findleyr, thanks for the reply. With respect to your suggestion, I think it's reasonable but there are some problems around:
const (
O_TRUNC int = 512 // truncate regular writable file when opened.
)
os.O_TRUNC on pkg.go.dev
Flags to OpenFile wrapping those of the underlying system. Not all flags may be implemented on a given system. As there seems no relevant documentation which explicitly defines commentary specification, I use this picture to explain the corresponding comment scope in my view: Based on above, I think we can change the signature of the const/var declaration to make it's presentation more comprehensive. It's unrealistic to restraint user's comment behaviour without mechanical check but currently gopls can try to make all context present. 9/23 update: The old deisgn is too miscellaneous and may not deserve too much work to implement. In order to unify the presentation style, make decl.Doc always(if has) at the position of documentation and the rest like findleyr suggested. I will work on it next few days and paste the capture of hover result here.
|
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
O_TRUNC
in following code.What did you expect to see?
Show
truncate regular writable file when opened
, which tells more than the general comments for all flags.What did you see instead?
Appendix:
1. rpc trace log
2. possible reason
In following code it seems that currently gopls prefers spec.Doc > decl.Doc > spec.Comment,
which means they will not coexist and gopls will lose some key information in hover result.
https://github.com/golang/tools/blob/master/internal/lsp/source/hover.go#L476-L498
3. inconsistent behaviour
If you hover for O_RDONLY or O_APPEND, gopls will only return the comment of previous line,
which doesn't tell useful information and leads to an inconsistent behaviour with other flags.
https://github.com/golang/go/blob/master/src/os/file.go#L71-L84
The text was updated successfully, but these errors were encountered: