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: show hex/binary literal with which a const was declared on mouse over #47453

Open
soypat opened this issue Jul 29, 2021 · 3 comments · May be fixed by golang/tools#361
Open

x/tools/gopls: show hex/binary literal with which a const was declared on mouse over #47453

soypat opened this issue Jul 29, 2021 · 3 comments · May be fixed by golang/tools#361
Labels
FeatureRequest gopls help wanted Tools

Comments

@soypat
Copy link

@soypat soypat commented Jul 29, 2021

What did you do?

Mouse over a hex/binary notation integer

const hex, bin, oct = 0xe34e, 0b10101, 071

// Mouse over variable name `hex` or `bin` shows decimal representation
c := hex * bin

What did you expect to see?

The literal used to declare the const. Usually when one declares a const in hex, binary or octal representation it carries with it a significance, to aid the reader of the code. If we wrote programs for machines gofmt would convert these literals to decimals or whatever the computer like.

With the philosophy out of the way, I expected to see:

  • const hex untyped int = 0xe34e (58190)
  • const bin untyped int = 0b10101 (21).

What did you see instead?

The usual gopls help string of

  • const hex untyped int = 58190
  • const bin untyped int = 21.
@gopherbot gopherbot added Tools gopls labels Jul 29, 2021
@gopherbot gopherbot added this to the Unreleased milestone Jul 29, 2021
@hyangah
Copy link
Contributor

@hyangah hyangah commented Jul 29, 2021

Isn't it a duplicate of #45802? Can you please check if the fix in golang.org/x/tools/gopls@v0.7.1-pre.1 meets what you want?

@hyangah hyangah added the WaitingForInfo label Jul 29, 2021
@soypat
Copy link
Author

@soypat soypat commented Jul 29, 2021

@hyangah negative. The issues are similar in nature though. I'm not asking for literal evaluation but rather that gopls show me how the author initialized a const integer since there are around 5 ways of initializing the same number and usually non-decimal form carries useful information about certain bits (i.e. bitfields, masks)

@hyangah hyangah added FeatureRequest and removed WaitingForInfo labels Jul 30, 2021
@hyangah hyangah removed this from the Unreleased milestone Jul 30, 2021
@hyangah hyangah added this to the gopls/unplanned milestone Jul 30, 2021
ShoshinNikita added a commit to ShoshinNikita/tools that referenced this issue Jan 30, 2022
…iables and constants

This change improves the hover information for variables and constants by showing
both an original declaration and a value. The value is shown as an inline comment.

Two kinds of declarations are currently supported:

1. Basic literals of type int:

	* var x int64 = 0xff // 255
	* const x untyped int = 0b11 // 3
	* const x uint = 1_000_000 // 1000000

2. Binary expressions with bitwise operators:

	* var x uint = 0b10 | 0b1 // 3
	* const x untyped int = 10 << 20 // 10485760

This change also removes TestHoverIntLiteral in favor of marker tests

Fixes golang/go#47453
@gopherbot
Copy link

@gopherbot gopherbot commented Jan 30, 2022

Change https://golang.org/cl/381961 mentions this issue: internal/lsp/source: show an original declaration and a value for variables and constants

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest gopls help wanted Tools
Projects
None yet
3 participants