-
Notifications
You must be signed in to change notification settings - Fork 763
Fix contextual type for array completions #2309
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
Conversation
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.
Pull request overview
This PR fixes issues with contextual type determination for array completions introduced in #2258. The changes address two key problems: (1) ensuring comma-separated contexts fall through to argument list handling when not in array literals, and (2) properly tracking spread element indices when computing contextual types for array elements.
- Refactored the
getContextualTypefunction to restructure control flow, removing the fallthrough fromKindColonTokenand movingKindCommaTokenhandling to properly support both array literals and argument lists - Replaced the oversimplified contextual type computation with
GetContextualTypeForArrayLiteralAtPosition, which now tracks spread element positions - Added test coverage for argument completions with both function calls and array literals with spread elements
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| internal/ls/completions.go | Restructured switch cases to properly handle comma tokens in both array literals and argument lists, removed problematic fallthrough behavior |
| internal/checker/services.go | Implemented GetContextualTypeForArrayLiteralAtPosition to replace simplified logic, adding spread element tracking and position-based element index calculation |
| internal/fourslash/tests/argumentCompletions_test.go | Added test cases verifying contextual type completions for function arguments and array literals with spread elements |
| contextualType := typeChecker.GetContextualType(previousToken, checker.ContextFlagsCompletions) | ||
| if contextualType != nil { | ||
| return contextualType | ||
| case ast.KindCommaToken: |
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 might still co-locate the [ and ] cases, but this is fine.
I was thinking about whether there are cases where we should also guard on ], but I couldn't imagine where you'd want or have a contextual type immediately after a ].
Fixes some problems caused by #2258: