Skip to content

Align inlay hints with trailing tuple arguments - #64410

Open
Jake Bailey (jakebailey) wants to merge 8 commits into
microsoft:mainfrom
jakebailey:inlay-hints-tuple-rest-reuse
Open

Jake Bailey (jakebailey) wants to merge 8 commits into
microsoft:mainfrom
jakebailey:inlay-hints-tuple-rest-reuse

Conversation

@jakebailey

@jakebailey Jake Bailey (jakebailey) commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

It was easier to just write what I meant on #64363 than to describe it better.

Fixes #59979
Closes #64363

Trailing fixed tuple elements correspond to the last arguments, not
the first positions after a rest element. Without aligning from the
end, inlay hints point to the wrong parameter and can hide names of
later parameters.

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 review overview

🔵 Needs a closer look

Trailing fixed elements are still mapped incorrectly when tuples contain multiple generic variadic elements.

Review effort: Balanced
Findings: None

What changed in this PR

Aligns language-service inlay hints with trailing tuple arguments and preserves hints after unnamed parameters.

Changes:

  • Matches trailing tuple elements from the end.
  • Shares tuple-element counting helpers.
  • Adds regression tests and baseline expectations.
File Description
tsc/​testdata/​baselines/​reference/​fourslash/​inlayHints/​inlayHintsTupleRestTrailing.baseline Records expected inlay hints.
tsc/​internal/​ls/​signaturehelp.go Shares required tuple-element counting.
tsc/​internal/​ls/​inlay_hints.go Adjusts hint mapping; multiple generic variadic elements remain unresolved.
tsc/​internal/​fourslash/​tests/​inlayHintsTupleRestTrailing_test.go Adds regression coverage.
tsc/​internal/​checker/​exports.go Exposes trailing tuple-element counting.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@github-project-automation github-project-automation Bot moved this from Not started to Needs merge in PR Backlog Sep 23, 2026
@jakebailey

Copy link
Copy Markdown
Member Author

Needs a closer look

Trailing fixed elements are still mapped incorrectly when tuples contain multiple generic variadic elements.

This is a review comment in disguise 😄

A spread can leave the effective argument count unknown even when
explicit arguments follow it. Those trailing arguments still have
known positions from the end of the call.
Optional tuple elements may be omitted, so their names cannot always
be inferred from the end of a call. An argument before a known
trailing suffix must not be labeled as that suffix either.

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 review overview

🔵 Needs a closer look

Tuple spreads and omitted optional suffixes can still produce incorrect parameter hints.

Review effort: Balanced
Findings: None

Optional and variable tuple elements make the next parameter position
uncertain. Keep hints for positions known from the end of a required
tuple suffix, but omit names that could refer to a different argument.
@jakebailey
Jake Bailey (jakebailey) requested a balanced review from Copilot September 23, 2026 22:24
@jakebailey

Copy link
Copy Markdown
Member Author

Leave it to copilot review to keep finding weird edge cases, sigh

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 review overview

🔵 Needs a closer look

Multiple moderate inlay-hint mapping regressions remain unresolved.

Review effort: Balanced
Findings: None

Previously missed (1)

In code that hasn't changed since last review

Medium severity Avoid aligning optional trailing tuple elements as required

tsc/​internal/​ls/​inlay_hints.go:897

This alignment uses trailingCount, so an optional suffix is treated as present whenever the call has enough arguments. For declare function f(...args: [...head: number[], tail?: string]); f(1), index == 0 is remapped to tail, even though the optional tail may be omitted and 1 belongs to head; this regresses the existing start-to-end mapping for optional trailing tuples. Only apply this known-arity remapping when all trailing fixed elements are required (and add a regression case for an omitted optional suffix).

associatedName := associatedNames[index]
restArgumentCount := argumentCount - paramCount
firstVariableIndex := tupleType.FixedLength()
trailingCount := checker.GetEndElementCount(tupleType, checker.ElementFlagsFixed)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe trailingFixedCount

index = len(elementInfos) - offsetFromEnd
case offsetFromEnd > trailingCount:
return nil
case argumentCount >= 0 && restArgumentCount >= firstVariableIndex+trailingCount:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I have mostly been able to track this stuff, but I'm starting to find it hard to keep track of in this branch. Maybe you could add some comments at each branch to show concrete situations that we're trying to handle?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Author: Team For Backlog Bug PRs that fix a backlog bug

Projects

Status: Needs merge

Development

Successfully merging this pull request may close these issues.

Inlay parameter hints don't account for trailing required parameters

4 participants