-
Notifications
You must be signed in to change notification settings - Fork 14.5k
Fix inlay hints for trailing required rest elements #64363
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
Open
雪代 / Yukishiro (yksr-melt)
wants to merge
1
commit into
microsoft:main
Choose a base branch
from
yksr-melt:fix/tsgo-inlay-hints-trailing-required-rest
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
tsc/internal/fourslash/tests/inlayHintsParameterNames_destructuredParameter_test.go
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package fourslash_test | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/microsoft/TypeScript/tsc/internal/fourslash" | ||
| "github.com/microsoft/TypeScript/tsc/internal/ls/lsutil" | ||
| "github.com/microsoft/TypeScript/tsc/internal/testutil" | ||
| ) | ||
|
|
||
| func TestInlayHintsParameterNames_destructuredParameter(t *testing.T) { | ||
| t.Parallel() | ||
| defer testutil.RecoverAndFail(t, "Panic on fourslash test") | ||
| const content = `function foo({ a }: { a: number }, b: number) {} | ||
| foo({ a: 1 }, 2)` | ||
| f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) | ||
| defer done() | ||
| f.VerifyBaselineInlayHints(t, nil /*span*/, &lsutil.UserPreferences{InlayHints: lsutil.InlayHintsPreferences{IncludeInlayParameterNameHints: lsutil.IncludeInlayParameterNameHintsAll}}) | ||
| } |
31 changes: 31 additions & 0 deletions
31
tsc/internal/fourslash/tests/inlayHintsRestParameters_trailingRequired_test.go
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package fourslash_test | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/microsoft/TypeScript/tsc/internal/fourslash" | ||
| "github.com/microsoft/TypeScript/tsc/internal/ls/lsutil" | ||
| "github.com/microsoft/TypeScript/tsc/internal/testutil" | ||
| ) | ||
|
|
||
| func TestInlayHintsRestParameters_trailingRequired(t *testing.T) { | ||
| t.Parallel() | ||
| defer testutil.RecoverAndFail(t, "Panic on fourslash test") | ||
| const content = `function test(...rest: [first: number, ...middle: string[], last: string]) {} | ||
| test(10, 'a', 'b', 'c') | ||
| test(10, 'a', 'c') | ||
| test(10, 'c') | ||
|
|
||
| function head(...rest: [...init: string[], last: number]) {} | ||
| head('a', 'b', 1) | ||
| head(1) | ||
|
|
||
| function mixed(a: boolean, ...rest: [x: number, ...ys: string[], z: string]) {} | ||
| mixed(true, 1, 'a', 'b', 'c') | ||
|
|
||
| function noTrailing(...rest: [first: number, ...middle: string[]]) {} | ||
| noTrailing(1, 'a', 'b')` | ||
| f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) | ||
| defer done() | ||
| f.VerifyBaselineInlayHints(t, nil /*span*/, &lsutil.UserPreferences{InlayHints: lsutil.InlayHintsPreferences{IncludeInlayParameterNameHints: lsutil.IncludeInlayParameterNameHintsAll}}) | ||
| } |
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
32 changes: 32 additions & 0 deletions
32
...es/reference/fourslash/inlayHints/inlayHintsParameterNames_destructuredParameter.baseline
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| // === Inlay Hints === | ||
| foo({ a: 1 }, 2) | ||
| ^ | ||
| { | ||
| "position": { | ||
| "line": 1, | ||
| "character": 14 | ||
| }, | ||
| "label": [ | ||
| { | ||
| "value": "b", | ||
| "location": { | ||
| "uri": "file:///inlayHintsParameterNames_destructuredParameter.ts", | ||
| "range": { | ||
| "start": { | ||
| "line": 0, | ||
| "character": 35 | ||
| }, | ||
| "end": { | ||
| "line": 0, | ||
| "character": 36 | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| { | ||
| "value": ":" | ||
| } | ||
| ], | ||
| "kind": 2, | ||
| "paddingRight": true | ||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Vaguely surprised there's no code reuse for this and sig help, which I think does something quite similar? I've definitely read code like this before somewhere, just not sure where.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked for something to share with, but I couldn't find an existing helper that does this. Signature help doesn't map arguments to tuple elements from the end; it builds its labels from
GetExpandedParameters, whose synthetic symbols have no declarations, so inlay hints can't use them for the label locations (the hint names link to the tuple element's declaration). The closest thing isgetEndElementCountin the checker, which inference and relations use to count the fixed elements after a rest element, but it isn't exported.I did try a prototype that exports it as
TupleType.EndElementCountand uses it together withFixedLength()ingetRestTupleElementIndex. It replaces the scan over the element infos, and all the inlay hint tests pass with unchanged baselines. I left it out to keep this PR to the language service, but I'm happy to add it if you'd prefer.