Skip to content

fix: signature help's active overload not updating - #320980

Merged
Dmitriy Vasyura (dmitrivMS) merged 11 commits into
microsoft:mainfrom
peterdanwan:issue-268728
Jul 29, 2026
Merged

fix: signature help's active overload not updating#320980
Dmitriy Vasyura (dmitrivMS) merged 11 commits into
microsoft:mainfrom
peterdanwan:issue-268728

Conversation

@peterdanwan

@peterdanwan Peter Wan (peterdanwan) commented Jun 11, 2026

Copy link
Copy Markdown
Contributor
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

Copilot AI review requested due to automatic review settings June 11, 2026 16:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread extensions/typescript-language-features/src/languageFeatures/signatureHelp.ts Outdated
@peterdanwan Peter Wan (peterdanwan) changed the title fix: signature help active overload not updating fix: signature help's active overload not updating Jun 11, 2026
@dmitrivMS

Copy link
Copy Markdown
Contributor

Ok, but we probably need before/after unit-tests to make sure we don't regress anything here.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 1

Comment thread extensions/typescript-language-features/src/languageFeatures/signatureHelp.ts Outdated
@peterdanwan
Peter Wan (peterdanwan) force-pushed the issue-268728 branch 2 times, most recently from 397850f to 9d77b3d Compare June 11, 2026 22:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

Comment thread extensions/typescript-language-features/src/languageFeatures/signatureHelp.ts Outdated
Comment thread extensions/typescript-language-features/src/test/unit/signatureHelp.test.ts Outdated
Comment thread extensions/typescript-language-features/src/languageFeatures/signatureHelp.ts Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

Comment thread extensions/typescript-language-features/src/languageFeatures/signatureHelp.ts Outdated
Comment thread extensions/typescript-language-features/src/test/unit/signatureHelp.test.ts Outdated
Comment thread extensions/typescript-language-features/src/languageFeatures/signatureHelp.ts Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

Comment thread extensions/typescript-language-features/src/test/unit/signatureHelp.test.ts Outdated
Comment thread extensions/typescript-language-features/src/languageFeatures/signatureHelp.ts Outdated
Comment thread extensions/typescript-language-features/src/languageFeatures/signatureHelp.ts Outdated
Comment thread extensions/typescript-language-features/src/test/unit/signatureHelp.test.ts Outdated
Comment thread extensions/typescript-language-features/src/test/unit/signatureHelp.test.ts Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

Comment thread extensions/typescript-language-features/src/test/unit/signatureHelp.test.ts Outdated
Comment thread extensions/typescript-language-features/src/test/unit/signatureHelp.test.ts Outdated
Comment thread extensions/typescript-language-features/src/languageFeatures/signatureHelp.ts Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread extensions/typescript-language-features/src/languageFeatures/signatureHelp.ts Outdated
Comment thread extensions/typescript-language-features/src/test/unit/signatureHelp.test.ts Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread extensions/typescript-language-features/src/test/unit/signatureHelp.test.ts Outdated
Comment thread extensions/typescript-language-features/src/languageFeatures/signatureHelp.ts Outdated
@peterdanwan

Copy link
Copy Markdown
Contributor Author

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.

Peter Wan (peterdanwan) and others added 3 commits June 12, 2026 15:53
- 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
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>
@dmitrivMS

Copy link
Copy Markdown
Contributor

Updated the implementation in b05a6e0a648 with a stateful approach.

The direct result.activeSignature = info.selectedItemIndex change fixes #268728, but it also removes the behavior added for #94834: if a user manually selects an overload, that selection should survive subsequent signature-help retriggers.

The new approach:

  • Records the last signature-help result per document.
  • Distinguishes the overload automatically selected by TypeScript from an overload explicitly selected by the user through context.activeSignatureHelp.
  • Follows TypeScript's new selectedItemIndex when argument changes narrow or otherwise change the recommended overload.
  • Preserves a user-selected overload by label across retriggers and signature-list reordering, falling back to TypeScript when that overload disappears.
  • Uses per-document request IDs so an obsolete async response cannot overwrite selection state.
  • Computes the active parameter against the overload that is actually displayed.
  • Removes the production provider export and protocol-client mock that were added only for tests.

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.

@dmitrivMS
Dmitriy Vasyura (dmitrivMS) enabled auto-merge (squash) July 29, 2026 10:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review details

  • Files reviewed: 3/3 changed files
  • Comments generated: 0 new
  • Review effort level: Medium

@dmitrivMS
Dmitriy Vasyura (dmitrivMS) merged commit 69e459e into microsoft:main Jul 29, 2026
29 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.132.0 milestone Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Intellisense no longer works for TypeScript function overload

5 participants