Skip to content

Conversation

@ahejlsberg
Copy link
Member

Fixes #2460.

Copy link
Contributor

Copilot AI left a 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 prevents textDocument/inlayHint from crashing when it encounters reparsed AST nodes, addressing issue #2460. The change aligns inlay hint traversal with how other language service features treat reparsed nodes.

Changes:

  • Update inlayHintState.visit to skip nodes marked with ast.NodeFlagsReparsed, avoiding attempts to create tokens for reparsed nodes and thus preventing the panic in SourceFile.GetOrCreateToken.

Comment on lines 63 to 65
func (s *inlayHintState) visit(node *ast.Node) bool {
if node == nil || node.End()-node.Pos() == 0 {
if node == nil || node.End()-node.Pos() == 0 || node.Flags&ast.NodeFlagsReparsed != 0 {
return false
Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

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

This change fixes a crash on reparsed function expressions, but there is no new regression test covering the scenario from issue #2460 (inlay hints over a reparsed function expression). Given the existing fourslash-based inlay hint tests (e.g. inlayHintsCrash1, inlayHintsTupleTypeCrash), please add a similar fourslash test that exercises a reparsed function expression so future changes don’t reintroduce this panic without being caught by CI.

Copilot generated this review using guidance from repository custom instructions.
Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think we need a regression test.

@DanielRosenwasser
Copy link
Member

@copilot please add the regression test from #2460 (comment) in another PR

package fourslash_test

import (
	"testing"

	"github.com/microsoft/typescript-go/internal/fourslash"
	"github.com/microsoft/typescript-go/internal/ls/lsutil"
	"github.com/microsoft/typescript-go/internal/testutil"
)

func TestInlayHintsCrash(t *testing.T) {
	t.Parallel()

	defer testutil.RecoverAndFail(t, "Panic on fourslash test")
	const content = `
// @allowJs: true
// @checkJs: true

// @Filename: /a.js
module.exports = function () {
  return 1;
};
`

	f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
	defer done()
	f.VerifyBaselineInlayHints(t, nil /*span*/, &lsutil.UserPreferences{InlayHints: lsutil.InlayHintsPreferences{
		IncludeInlayFunctionLikeReturnTypeHints: true,
		IncludeInlayFunctionParameterTypeHints:  true,
	}})
}

and verify that it fails if the fix here is not applied.

Copy link
Contributor

Copilot AI commented Jan 27, 2026

@DanielRosenwasser I've opened a new pull request, #2595, to work on those changes. Once the pull request is ready, I'll request review from you.

@ahejlsberg ahejlsberg added this pull request to the merge queue Jan 27, 2026
Merged via the queue into main with commit 66d9745 Jan 27, 2026
21 checks passed
@ahejlsberg ahejlsberg deleted the fix-2460 branch January 27, 2026 21:40
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.

textDocument/inlayHint: Cannot create token from reparsed node of kind KindFunctionExpression

4 participants