-
Notifications
You must be signed in to change notification settings - Fork 766
Fix signature help crash when nested call has trailing comma #2315
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
28 changes: 28 additions & 0 deletions
28
internal/fourslash/tests/signatureHelpNestedCallTrailingComma_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,28 @@ | ||
| package fourslash_test | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/microsoft/typescript-go/internal/fourslash" | ||
| "github.com/microsoft/typescript-go/internal/lsp/lsproto" | ||
| "github.com/microsoft/typescript-go/internal/testutil" | ||
| ) | ||
|
|
||
| func TestSignatureHelpNestedCallTrailingComma(t *testing.T) { | ||
| t.Parallel() | ||
| defer testutil.RecoverAndFail(t, "Panic on fourslash test") | ||
| // Regression test for crash when requesting signature help on a call target | ||
| // where the nested call has a trailing comma. | ||
| // Both outer and inner calls must have trailing commas, and outer must be generic. | ||
| const content = `declare function outer<T>(range: T): T; | ||
| declare function inner(a: any): any; | ||
| outer(inner/*1*/(undefined,),);` | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Also, worth noting that this crash happens at several locations in the identifier |
||
| f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) | ||
| defer done() | ||
| f.GoToMarker(t, "1") | ||
| f.VerifySignatureHelpPresent(t, &lsproto.SignatureHelpContext{ | ||
| IsRetrigger: false, | ||
| TriggerKind: lsproto.SignatureHelpTriggerKindInvoked, | ||
| }) | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.
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 spent a lot of time being convinced this was wrong, but this is actually an acceptable fix - in signature help, we resolve the signature with a higher argument count if there's a trailing comma.
In Strada, we used to slice instead of indexing by
maxCount.This never failed because you can never have a trailing comma on zero elements - you'll always have an omitted expression.(This isn't true! See below)We could go back to the same approach here.
It felt weird that we even try to report errors - but I think signature help does rely on actually resolving the signature in the error path. We have a call to
where the result is just unchecked, so I assume that's just for side-effects.
So I couldn't just adjust
reportErrorslike so:because tests would start failing.
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.
Actually, I think Strada has the same bug!
microsoft/TypeScript#55732
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.
What happens to the diag? Does it just keep accumulating them?
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.
Probably, just like every other similar operation in the LS.
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.
(and keep in mind, it was always doing that - it just doesn't crash now in this one case)