fix: signature help's active overload not updating - #320980
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Updates TypeScript signature help retrigger behavior to reduce overload-selection flicker while still respecting TypeScript’s updated overload choice when arguments narrow the applicable overload set.
Changes:
- Add detailed rationale for how retrigger overload selection should behave.
- Only keep the previously active overload on retrigger when it matches TypeScript’s current
selectedItemIndex.
77c263d to
a344241
Compare
|
Ok, but we probably need before/after unit-tests to make sure we don't regress anything here. |
397850f to
9d77b3d
Compare
9d77b3d to
fe70677
Compare
2311a92 to
114544a
Compare
114544a to
9fdf4b3
Compare
|
Hi Dmitriy Vasyura (@dmitrivMS), after iterating on the code a few times I ended up removing getActiveSignature entirely. The original fix caused both branches of the function to return the same value (info.selectedItemIndex), making it a no-op. The simplest correct approach was to assign result.activeSignature = info.selectedItemIndex directly in provideSignatureHelp, which produces the same behavior without the unnecessary indirection. For the tests, I did my best to address Copilot's feedback, but I wasn't always sure what it was asking for. I've added unit tests using a mock TS client via _TypeScriptSignatureHelpProvider (VS Code's underscore convention for test-only exports). Happy to hear any suggestions on the test suite if the approach isn't quite right. |
- Active overload now updates when typed arguments narrow the overload set
- Instead of searching signatures by label to get an index and comparing it to info.selectedItemIndex, look up signatures[info.selectedItemIndex] directly so both sides of the comparison use the same index source
- Extract getActiveSignature as an exported function so unit tests can import it without the extension host - Add BEFORE suite documenting the original bug: on retrigger, old code returned the stale overload index even after TypeScript updated selectedItemIndex (e.g. after a string argument narrows the overload set on the comma trigger) - Add AFTER suite verifying the fix: retrigger now honours TypeScript's updated selectedItemIndex; the BUG test case that returned 0 now correctly returns 1 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Rename exported helper to computeActiveSignatureIndex to avoid identifier collision with the private method - Stop returning activeSignatureHelp.activeSignature: that index refers to the previous signature list, which is stale if the list reorders between invocations; always use tsSelectedItemIndex instead - Add regression test for the reordering case: verifies that when the list reorders and TS still selects the same overload by label, the current index is returned, not the stale one
- Simplify computeActiveSignatureIndex to only accept tsSelectedItemIndex; the context and signatures params were unused and made the API misleading - Add @internal JSDoc to signal the computeActiveSignatureIndex export is for unit testing only, not public API - Replace assertion-based BEFORE suite with block comment documenting the original bug; asserting known-wrong behaviour institutionalizes incorrect expectations
- Replace the label-matching retrigger guard with result.activeSignature = info.selectedItemIndex; the guard became a no-op after the existingIndex === selectedItemIndex fix and its removal is the correct minimal change - Export TypeScriptSignatureHelpProvider as _TypeScriptSignatureHelpProvider (VS Code underscore-prefix convention for test-only exports) - Add unit tests via mock ITypeScriptServiceClient: documents the old buggy guard behavior and verifies the fix — the FIX test would fail if the label-matching guard were reintroduced
- Move CancellationTokenSource into setup/teardown so it is properly disposed after each test - Add success: true and message: '' to mock response to match the protocol shape - Add @internal test-only export JSDoc to _TypeScriptSignatureHelpProvider to make the export intent explicit
9fdf4b3 to
e5d1bec
Compare
Track TypeScript-selected and user-selected overloads separately so retriggers follow updated recommendations without resetting manual selections. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Updated the implementation in The direct The new approach:
The focused unit tests cover #268728, #94834, automatic and manual selection across reordering, removal of the selected overload, missing or unrelated prior state, and obsolete requests. Validation completed with 7 passing tests, a clean TypeScript extension compile, and hygiene checks. |
2026-06-11.12-08-10.mp4
Edit: this is consistent with https://www.typescriptlang.org/play/
https://github.com/user-attachments/assets/0c6f8315-dcd9-4487-a655-c3b4f0d7a5bc