-
Notifications
You must be signed in to change notification settings - Fork 26.3k
feat(language-service): support to fix missing required inputs diagno… #50911
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
base: main
Are you sure you want to change the base?
Conversation
aa9d62a
to
f0c16b0
Compare
@ivanwonder Sorry for the long wait on getting this looked at. If you're still willing to get this landed, can you rebase and resolve the conflicts. It looks like a nice feature to get landed. |
f0c16b0
to
b5f7c12
Compare
Actually, nevermind on the rebase. I was able to resolve those for you. |
de4f346
to
8360b43
Compare
@ivanwonder Yeah, looks like even with resolving the conflicts, this is broken. Can you take a look? |
OK, I'll take a look. |
@thePunderWoman Done. It seems that the |
da3c507
to
06b6bd1
Compare
…stic Support to add the missing required inputs into the element and append after the last attribute of the element. But it skips the structural directive shorthand attribute. For example, `<a *ngFor=""></a>`, its shorthand is `<ng-template ngFor>`, the `valueSpan` of the `ngFor` is empty, and the info is lost, so it can't use to insert the missing attribute after it.
06b6bd1
to
efc2a14
Compare
}, | ||
], | ||
}); | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} else { | |
} else { | |
// For other input types (numbers, objects, etc.), no type-specific shorthand | |
// attribute suggestion is generated here. The general property binding suggestion | |
// `[inputName]=""` (added below for all missing inputs) covers these cases. |
} else { | ||
} | ||
|
||
const insertBoundText = `[${input.bindingPropertyName}]=""`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const insertBoundText = `[${input.bindingPropertyName}]=""`; | |
// As a general solution, always offer a property binding suggestion (e.g., `[inputName]=""`). | |
// This is the most versatile way for users to satisfy a required input, | |
// allowing them to bind to component properties or provide initial literal values. | |
const insertBoundText = `[${input.bindingPropertyName}]=""`; |
} | ||
|
||
const memberType = typeCheck.getTypeOfSymbol(memberSymbol); | ||
if (memberType.flags & tss.TypeFlags.BooleanLike) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (memberType.flags & tss.TypeFlags.BooleanLike) { | |
// For boolean inputs, suggest adding the attribute name directly (e.g., `attrName`). | |
// This is a common way to set boolean inputs to true. | |
if (memberType.flags & tss.TypeFlags.BooleanLike) { |
if (memberType.flags & tss.TypeFlags.BooleanLike) { | ||
const insertText = input.bindingPropertyName; | ||
codeActions.push({ | ||
fixName: FixIdForCodeFixesAll.FIX_SPELLING, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is FIX_SPELLING a historical choice or a way to categorize simple attribute additions that don't involve values or brackets, making it a common fix ID? Should the commented out lines be removed below?
}, | ||
], | ||
}); | ||
} else if (memberType.flags & tss.TypeFlags.StringLike) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} else if (memberType.flags & tss.TypeFlags.StringLike) { | |
// For string inputs, suggest adding an empty string binding (e.g., `attrName=""`). | |
} else if (memberType.flags & tss.TypeFlags.StringLike) { |
…stic
Support to add the missing required inputs into the element and append after the last attribute of the element.
But it skips the structural directive shorthand attribute. For example,
<a *ngFor=""></a>
, its shorthand is<ng-template ngFor>
, thevalueSpan
of thengFor
is empty, and the info is lost, so it can't use to insert the missing attribute after it.PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: N/A
What is the new behavior?
Does this PR introduce a breaking change?
Other information