Skip to content

Fix hover on const in as const to display the specific type#3951

Open
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-hover-type-const
Open

Fix hover on const in as const to display the specific type#3951
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-hover-type-const

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 18, 2026

Hovering on const in 42 as const showed type const instead of type const = 42.

The SymbolFlagsTypeAlias branch in getQuickInfoAndDeclarationAtLocation guarded the type display with if len(symbol.Declarations) != 0. The const keyword in as const resolves to an intrinsic type alias symbol with no declarations, so the type was never printed.

  • Removed the declarations length guard, matching the TypeScript source (symbolDisplay.ts) which unconditionally writes = <type> for type aliases
  • The existing IsConstTypeReference check already correctly resolves the type via GetTypeAtLocation(node.Parent)
const foo = 42 as const
//                ^^^^^ was: "type const", now: "type const = 42"

Remove the `if len(symbol.Declarations) != 0` guard that prevented
type display for intrinsic type aliases with no declarations (like the
`const` keyword in `as const` assertions). This aligns the behavior
with the TypeScript source which unconditionally writes the type.

Agent-Logs-Url: https://github.com/microsoft/typescript-go/sessions/7e1ae8e8-dd19-43f7-ab0f-5256779d1b7f

Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix hovering on type const to display specific type Fix hover on const in as const to display the specific type May 18, 2026
Copilot AI requested a review from jakebailey May 18, 2026 14:53
@jakebailey jakebailey marked this pull request as ready for review May 18, 2026 15:32
Copilot AI review requested due to automatic review settings May 18, 2026 15:32
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes Language Service hover output for the const keyword in as const assertions so it shows the resolved literal/specific type (e.g. type const = 42) rather than only type const. This aligns the Go port’s type-alias quick info formatting with upstream TypeScript behavior and is validated via updated fourslash baselines plus a focused regression test.

Changes:

  • Updated getQuickInfoAndDeclarationAtLocation to always append = <type> for SymbolFlagsTypeAlias quick info (no longer gated on len(symbol.Declarations) != 0).
  • Kept/leveraged the existing IsConstTypeReference path to resolve the asserted type via GetTypeAtLocation(node.Parent) for as const.
  • Added/updated fourslash coverage (new targeted test + updated reference baseline).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
internal/ls/hover.go Always emits type <alias> = <type> for type-alias quick info; ensures as const’s intrinsic alias renders the asserted type.
testdata/baselines/reference/fourslash/quickInfo/quickInfoForConstAssertions.baseline Updates expected hover output for as const markers to include = <specific type>.
internal/fourslash/tests/quickInfoConstAssertion_test.go Adds a focused regression test asserting hover on const in 42 as const shows type const = 42.

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.

Hovering on type const does not display the specific type

3 participants