Skip to content

Add missing whitespace after type parameter's modifiers in interactive inlay hints #62246

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/services/inlayHints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@ export function provideInlayHints(context: InlayHintsContext): InlayHint[] {
Debug.assertNode(node, isTypeParameterDeclaration);
if (node.modifiers) {
visitDisplayPartList(node.modifiers, " ");
parts.push({ text: " " });
Copy link
Preview

Copilot AI Aug 9, 2025

Choose a reason for hiding this comment

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

This code duplicates the exact same logic that already exists in the visitForDisplayParts function for SyntaxKind.TypeParameter case (line 584-586 in context). The spacing logic should be handled consistently in one place rather than duplicated.

Copilot uses AI. Check for mistakes.

}
visitForDisplayParts(node.name);
if (node.constraint) {
Expand All @@ -597,6 +598,7 @@ export function provideInlayHints(context: InlayHintsContext): InlayHint[] {
Debug.assertNode(node, isParameter);
if (node.modifiers) {
visitDisplayPartList(node.modifiers, " ");
parts.push({ text: " " });
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have added this for consistency but I don't know if there is a sane way to test this. Parameter modifiers are only allowed in constructors, right? I think there might not be a way to have them displayed in an inlay hint

}
Copy link
Preview

Copilot AI Aug 9, 2025

Choose a reason for hiding this comment

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

This code duplicates the exact same logic that already exists in the visitForDisplayParts function for SyntaxKind.Parameter case (line 600-602 in context). The spacing logic should be handled consistently in one place rather than duplicated.

Suggested change
}
if (node.modifiers) {
visitDisplayPartList(node.modifiers, " ");
}

Copilot uses AI. Check for mistakes.

if (node.dotDotDotToken) {
parts.push({ text: "..." });
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// === Inlay Hints ===
function test1() {
^
{
"text": "",
"displayParts": [
{
"text": ": "
},
{
"text": "<"
},
{
"text": "const"
},
{
"text": " "
},
{
"text": "T",
"span": {
"start": 44,
"length": 1
},
"file": "/tests/cases/fourslash/inlayHintsTypeParameterModifiers1.ts"
},
{
"text": ">"
},
{
"text": "("
},
{
"text": "a"
},
{
"text": ": "
},
{
"text": "T",
"span": {
"start": 44,
"length": 1
},
"file": "/tests/cases/fourslash/inlayHintsTypeParameterModifiers1.ts"
},
{
"text": ")"
},
{
"text": " => "
},
{
"text": "void"
}
],
"position": 16,
"kind": "Type",
"whitespaceBefore": true
}

return function <const T>(a: T) {};
^
{
"text": "",
"displayParts": [
{
"text": ": "
},
{
"text": "void"
}
],
"position": 52,
"kind": "Type",
"whitespaceBefore": true
}
10 changes: 10 additions & 0 deletions tests/cases/fourslash/inlayHintsTypeParameterModifiers1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
///<reference path="fourslash.ts" />

//// function test1() {
//// return function <const T>(a: T) {};
//// }

verify.baselineInlayHints(undefined, {
interactiveInlayHints: true,
includeInlayFunctionLikeReturnTypeHints: true,
});
Loading