Skip to content

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ivanwonder
Copy link
Contributor

@ivanwonder ivanwonder commented Jul 1, 2023

…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.

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.io application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@angular-robot angular-robot bot added the detected: feature PR contains a feature commit label Jul 1, 2023
@ivanwonder ivanwonder force-pushed the codefix-for-require-input branch from aa9d62a to f0c16b0 Compare July 1, 2023 04:03
@ivanwonder ivanwonder marked this pull request as ready for review July 1, 2023 04:17
@pullapprove pullapprove bot requested review from alxhub and JoostK July 1, 2023 04:17
@pkozlowski-opensource pkozlowski-opensource added the area: language-service Issues related to Angular's VS Code language service label Jul 5, 2023
@ngbot ngbot bot added this to the Backlog milestone Jul 5, 2023
@thePunderWoman thePunderWoman marked this pull request as draft May 21, 2025 15:24
@thePunderWoman
Copy link
Contributor

@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.

@thePunderWoman thePunderWoman force-pushed the codefix-for-require-input branch from f0c16b0 to b5f7c12 Compare June 4, 2025 15:42
@thePunderWoman
Copy link
Contributor

@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.

Actually, nevermind on the rebase. I was able to resolve those for you.

@thePunderWoman thePunderWoman marked this pull request as ready for review June 4, 2025 15:43
@thePunderWoman thePunderWoman requested a review from atscott June 4, 2025 15:43
@thePunderWoman thePunderWoman added action: review The PR is still awaiting reviews from at least one requested reviewer target: patch This PR is targeted for the next patch release labels Jun 4, 2025
@thePunderWoman thePunderWoman force-pushed the codefix-for-require-input branch 2 times, most recently from de4f346 to 8360b43 Compare June 4, 2025 16:21
@thePunderWoman
Copy link
Contributor

@ivanwonder Yeah, looks like even with resolving the conflicts, this is broken. Can you take a look?

@thePunderWoman thePunderWoman added action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Jun 4, 2025
@ivanwonder
Copy link
Contributor Author

@ivanwonder Yeah, looks like even with resolving the conflicts, this is broken. Can you take a look?

OK, I'll take a look.

@ivanwonder
Copy link
Contributor Author

@ivanwonder Yeah, looks like even with resolving the conflicts, this is broken. Can you take a look?

@thePunderWoman Done. It seems that the NgModule does not recognize the standalone component in the test case.

@thePunderWoman thePunderWoman removed the action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews label Jun 5, 2025
@ivanwonder ivanwonder force-pushed the codefix-for-require-input branch from da3c507 to 06b6bd1 Compare June 5, 2025 14:05
…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.
@ivanwonder ivanwonder force-pushed the codefix-for-require-input branch from 06b6bd1 to efc2a14 Compare June 5, 2025 14:05
@atscott atscott added target: minor This PR is targeted for the next minor release and removed target: patch This PR is targeted for the next patch release labels Jun 11, 2025
},
],
});
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
} 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}]=""`;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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,
Copy link
Contributor

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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
} 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) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: language-service Issues related to Angular's VS Code language service detected: feature PR contains a feature commit target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants