Fix hover on const in as const to display the specific type#3951
Open
Copilot wants to merge 2 commits into
Open
Fix hover on const in as const to display the specific type#3951Copilot wants to merge 2 commits into
const in as const to display the specific type#3951Copilot wants to merge 2 commits into
Conversation
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 May 18, 2026
const in as const to display the specific type
jakebailey
approved these changes
May 18, 2026
Contributor
There was a problem hiding this comment.
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
getQuickInfoAndDeclarationAtLocationto always append= <type>forSymbolFlagsTypeAliasquick info (no longer gated onlen(symbol.Declarations) != 0). - Kept/leveraged the existing
IsConstTypeReferencepath to resolve the asserted type viaGetTypeAtLocation(node.Parent)foras 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hovering on
constin42 as constshowedtype constinstead oftype const = 42.The
SymbolFlagsTypeAliasbranch ingetQuickInfoAndDeclarationAtLocationguarded the type display withif len(symbol.Declarations) != 0. Theconstkeyword inas constresolves to an intrinsic type alias symbol with no declarations, so the type was never printed.symbolDisplay.ts) which unconditionally writes= <type>for type aliasesIsConstTypeReferencecheck already correctly resolves the type viaGetTypeAtLocation(node.Parent)