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: format constant time.Duration in hover tooltip #44667

Closed
ShoshinNikita opened this issue Feb 27, 2021 · 4 comments
Closed

x/tools/gopls: format constant time.Duration in hover tooltip #44667

ShoshinNikita opened this issue Feb 27, 2021 · 4 comments
Labels
FeatureRequest FrozenDueToAge gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@ShoshinNikita
Copy link

The current hover tooltip for const X time.Duration is not very useful because it displays nanoseconds:

image

I guess it's not possible to display an actual declaration (20 * time.Second in this example). But I think it would be a good solution to display formatted duration as a comment. Something like this:

const duration time.Duration = 20000000000 // 20s
@hyangah
Copy link
Contributor

hyangah commented Feb 27, 2021

Thanks for the feature request, @ShoshinNikita
I like the idea as long as we can reliably use String().
Forwarding this to the gopls issue tracker to evaluate.

@hyangah hyangah changed the title Format constant time.Duration in hover tooltip x/tools/gopls: Format constant time.Duration in hover tooltip Feb 27, 2021
@hyangah hyangah transferred this issue from golang/vscode-go Feb 27, 2021
@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Feb 27, 2021
@gopherbot gopherbot added this to the Unreleased milestone Feb 27, 2021
@stamblerre stamblerre changed the title x/tools/gopls: Format constant time.Duration in hover tooltip x/tools/gopls: format constant time.Duration in hover tooltip Feb 27, 2021
ShoshinNikita added a commit to ShoshinNikita/tools that referenced this issue Feb 27, 2021
The current hover information for constant time.Duration is not very
useful because it displays nanoseconds. So, show formatted duration
as an inline comment.

Fixes golang/go#44667
@gopherbot
Copy link

Change https://golang.org/cl/297310 mentions this issue: internal/lsp: show human-readable const time.Duration as a comment

@muirdm
Copy link

muirdm commented Feb 28, 2021

I guess it's not possible to display an actual declaration (20 * time.Second in this example).

It should be possible to do that. I wonder if that might be the most useful thing in general:

const flagA = 1
const flagB = 2
// Showing "3" isn't very useful. Showing "flagA | flagB" might be useful.
const someMask = flagA | flagB

const durA = 1*time.Minute
const durB = 1*time.Second
// Showing nanoseconds is not helpful. Showing "59s" might be helpful, but showing "durA - durB" might have the most meaning.
const timeout = durA - durB

@ShoshinNikita
Copy link
Author

I agree const someMask = flagA | flagB can be useful. I also think const someMask = flagA | flagB // 3 is even better

@golang golang locked and limited conversation to collaborators Mar 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FeatureRequest FrozenDueToAge gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants