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

gopls/internal/lsp/source: show both the original declaration and the value of constants in hover #432

Closed

Conversation

ShoshinNikita
Copy link
Contributor

@ShoshinNikita ShoshinNikita commented Mar 30, 2023

This change improves the hover information for constants by showing
both the original declaration and the value. The value is displayed
as an inline comment. If the original declaration and the value are
the same, there will be no inline comment.

Examples:

const duration time.Duration = 15*time.Minute + 10*time.Second // 15m10s

const octal untyped int = 0o777 // 511

const expr untyped int = 2 << (0b111&0b101 - 2) // 16

const boolean untyped bool = (55 - 3) == (26 * 2) // true

const dec untyped int = 500

Other changes:

  • Calls to objectString that format methods or variables have been
    replaced with types.ObjectString.
  • The logic of inferred signature formatting has been extracted from
    objectString to a new function inferredSignatureString.
  • Remove unused function extractFieldList.
  • Port gopls/internal/lsp/testdata/godef/a/g.go to the new marker
    tests.
  • Fix -min_go constraint for marker tests by replacing hardcoded
    1.18 with an actual flag value.

Fixes golang/go#47453

… value of constants in hover

This change improves the hover information for constants by showing both
the original declaration and the value. The value is displayed as
an inline comment. If the original declaration and the value are the same,
there will be no inline comment.

Examples:

```go
const duration time.Duration = 15*time.Minute + 10*time.Second // 15m10s

const octal untyped int = 0o777 // 511

const expr untyped int = 2 << (0b111&0b101 - 2) // 16

const boolean untyped bool = (55 - 3) == (26 * 2) // true

const dec untyped int = 500
```

Other changes:

* Calls to `objectString` that format methods or variables have been
  replaced with `types.ObjectString`.
* The logic of inferred signature formatting has been extracted from
  `objectString` to a new function `inferredSignatureString`.
* Remove unused function `extractFieldList`.

Fixes golang/go#47453
@gopherbot
Copy link
Contributor

This PR (HEAD: a7fbd1e) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/tools/+/480695 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link
Contributor

Message from Nikita Shoshin:

Patch Set 2:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/480695.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Robert Findley:

Patch Set 2: Run-TryBot+1


Please don’t reply on this GitHub thread. Visit golang.org/cl/480695.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Gopher Robot:

Patch Set 2:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/480695.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from kokoro:

Patch Set 2:

Kokoro presubmit build starting for golang/tools/gopls-legacy/presubmit
Logs at:
https://source.cloud.google.com/results/invocations/b4e98e76-f880-4d1a-b8e5-5f0f4135c4be


Please don’t reply on this GitHub thread. Visit golang.org/cl/480695.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Gopher Robot:

Patch Set 2: TryBot-Result+1

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/480695.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from kokoro:

Patch Set 2: gopls-CI-1

Kokoro presubmit build finished with status: FAILURE
Logs at: https://source.cloud.google.com/results/invocations/b4e98e76-f880-4d1a-b8e5-5f0f4135c4be


Please don’t reply on this GitHub thread. Visit golang.org/cl/480695.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Robert Findley:

Patch Set 2: Code-Review+1

(9 comments)


Please don’t reply on this GitHub thread. Visit golang.org/cl/480695.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Robert Findley:

Patch Set 2:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/480695.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

This PR (HEAD: 8cc75a7) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/tools/+/480695 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link
Contributor

Message from Nikita Shoshin:

Patch Set 3:

(2 comments)


Please don’t reply on this GitHub thread. Visit golang.org/cl/480695.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Nikita Shoshin:

Patch Set 3:

(4 comments)


Please don’t reply on this GitHub thread. Visit golang.org/cl/480695.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Robert Findley:

Patch Set 4: Code-Review+2 Run-TryBot+1

(7 comments)


Please don’t reply on this GitHub thread. Visit golang.org/cl/480695.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Gopher Robot:

Patch Set 4:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/480695.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from kokoro:

Patch Set 4:

Kokoro presubmit build starting for golang/tools/gopls-legacy/presubmit
Logs at:
https://source.cloud.google.com/results/invocations/c6047d5c-c048-4cfb-96a2-767738fefdc8


Please don’t reply on this GitHub thread. Visit golang.org/cl/480695.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from kokoro:

Patch Set 4: gopls-CI+1

Kokoro presubmit build finished with status: SUCCESS
Logs at: https://source.cloud.google.com/results/invocations/c6047d5c-c048-4cfb-96a2-767738fefdc8


Please don’t reply on this GitHub thread. Visit golang.org/cl/480695.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Gopher Robot:

Patch Set 4:

(2 comments)


Please don’t reply on this GitHub thread. Visit golang.org/cl/480695.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Gopher Robot:

Patch Set 4: TryBot-Result+1

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/480695.
After addressing review feedback, remember to publish your drafts!

gopherbot pushed a commit that referenced this pull request Apr 5, 2023
… value of constants in hover

This change improves the hover information for constants by showing
both the original declaration and the value. The value is displayed
as an inline comment. If the original declaration and the value are
the same, there will be no inline comment.

Examples:

```go
const duration time.Duration = 15*time.Minute + 10*time.Second // 15m10s

const octal untyped int = 0o777 // 511

const expr untyped int = 2 << (0b111&0b101 - 2) // 16

const boolean untyped bool = (55 - 3) == (26 * 2) // true

const dec untyped int = 500
```

Other changes:

- Calls to `objectString` that format methods or variables have been
  replaced with `types.ObjectString`.
- The logic of inferred signature formatting has been extracted from
  `objectString` to a new function `inferredSignatureString`.
- Remove unused function `extractFieldList`.
- Port `gopls/internal/lsp/testdata/godef/a/g.go` to the new marker
  tests.
- Fix `-min_go` constraint for marker tests by replacing hardcoded
  `1.18` with an actual flag value.

Fixes golang/go#47453

Change-Id: Ib9012dae8554a3b646c3059d2f8967e425974fbf
GitHub-Last-Rev: 8cc75a7
GitHub-Pull-Request: #432
Reviewed-on: https://go-review.googlesource.com/c/tools/+/480695
Run-TryBot: Robert Findley <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
Reviewed-by: Michael Knyszek <[email protected]>
gopls-CI: kokoro <[email protected]>
Reviewed-by: Robert Findley <[email protected]>
@gopherbot
Copy link
Contributor

This PR is being closed because golang.org/cl/480695 has been merged.

@gopherbot gopherbot closed this Apr 5, 2023
@ShoshinNikita ShoshinNikita deleted the const-original-declaration branch April 5, 2023 19:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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