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

Fixed a regression related to determining argument index when spread elements are involved #57637

Merged
merged 6 commits into from Mar 28, 2024

Conversation

Andarist
Copy link
Contributor

@Andarist Andarist commented Mar 4, 2024

fixes #57622 (comment)
likely fixes #57623 (comment)
likely fixes #57826

the issue is a regression from #56372

@@ -485,8 +484,7 @@ function getArgumentIndex(argumentsList: Node, node: Node, checker: TypeChecker)
// The list we got back can include commas. In the presence of errors it may
// also just have nodes without commas. For example "Foo(a b c)" will have 3
// args without commas. We want to find what index we're at. So we count
// forward until we hit ourselves, only incrementing the index if it isn't a
// comma.
// forward until we hit ourselves.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed this part of the comment because I adjusted the behavior (see tests/cases/fourslash/signatureHelpSkippedArgs1.ts). I find the new behavior better and it was easier for me to rewrite those loops while accommodating for that test case.

// The argument count for a list is normally the number of non-comma children it has.
// For example, if you have "Foo(a,b)" then there will be three children of the arg
// list 'a' '<comma>' 'b'. So, in this case the arg count will be 2. However, there
// is a small subtlety. If you have "Foo(a,)", then the child list will just have
// 'a' '<comma>'. So, in the case where the last child is a comma, we increase the
// arg count by one to compensate.
//
// Note: this subtlety only applies to the last comma. If you had "Foo(a,," then
// we'll have: 'a' '<comma>' '<missing>'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The mention of <missing> was added here like 9 years ago but the missing node is not used here for years already (I checked against some 3.x versions). When dealing with fn(,,,,) we just get a list of comma tokens

//// const fn = thisArg[fnName];
//// return function () {
//// return new Promise((resolve) => {
//// fn.call(thisArg, ...arguments, /*1*/);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Crash from #57622 (comment) happens in completions but it's caused by the same underlying issue. If requested I can add an extra completions-oriented test case too

@sandersn sandersn added this to Not started in PR Backlog Mar 18, 2024
@sandersn sandersn moved this from Not started to Waiting on reviewers in PR Backlog Mar 20, 2024
@sandersn sandersn added the For Backlog Bug PRs that fix a backlog bug label Mar 20, 2024
PR Backlog automation moved this from Waiting on reviewers to Needs merge Mar 28, 2024
@jakebailey
Copy link
Member

@typescript-bot cherry-pick this to release-5.4

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 28, 2024

Starting jobs; this comment will be updated as builds start and complete.

Command Status Results
cherry-pick this to release-5.4 ✅ Started ✅ Results

@typescript-bot
Copy link
Collaborator

Hey, @jakebailey! I've created #57987 for you.

Copy link
Member

@DanielRosenwasser DanielRosenwasser left a comment

Choose a reason for hiding this comment

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

I get the general gist here, and I don't see much changing in the way of existing tests which I know we spent a bunch of time on regarding picking the right overload. So I think we can take this PR.

@DanielRosenwasser DanielRosenwasser merged commit 97dc5f0 into microsoft:main Mar 28, 2024
25 checks passed
PR Backlog automation moved this from Needs merge to Done Mar 28, 2024
DanielRosenwasser pushed a commit that referenced this pull request Mar 28, 2024
…e-5.4 (#57987)

Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
@Andarist Andarist deleted the fix/regression-arg-index branch March 28, 2024 23:37
@DanielRosenwasser DanielRosenwasser added this to the TypeScript 5.4.32 milestone Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Backlog Bug PRs that fix a backlog bug
Projects
PR Backlog
  
Done
6 participants