Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(language-service): resolve the variable from the template context first #35982

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

Conversation

ivanwonder
Copy link
Contributor

fixed: angular/vscode-ng-language-service#670

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

@pullapprove pullapprove bot requested a review from kyliau March 10, 2020 04:38
@ivanwonder ivanwonder force-pushed the resolve-variable-from-template-context-first branch from eba8652 to 48d6c89 Compare March 10, 2020 05:12
@ivanwonder ivanwonder requested a review from kyliau March 10, 2020 05:14

it('should not report error if template context conflict with component context', () => {
mockHost.override(TEST_TEMPLATE, `
<div *ngFor="let h of heroes; let i = index">
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please add a comment here to call out index refers to the directive context and not the component context? Thank you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe it's no need to add the test case for it. the index only can refer to the directive context.

Copy link
Contributor

Choose a reason for hiding this comment

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

There should already be a test for this when checking the type of an ngFor export.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just add index to the component context.

@kyliau kyliau added area: language-service Issues related to Angular's VS Code language service target: patch This PR is targeted for the next patch release labels Mar 10, 2020
@ngbot ngbot bot modified the milestone: needsTriage Mar 10, 2020
@kyliau kyliau added the action: merge The PR is ready for merge by the caretaker label Mar 10, 2020
}
// Try to resolve the variable from directive context first, then the component context.
let symbol = getVariableTypeFromDirectiveContext(variable.value, info.query, current) ||
info.members.get(variable.value) || info.query.getBuiltinType(BuiltinType.Any);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kyliau I think it's wrong to get the type of the variable from component context.

*ngIf="let a = b.c.d()"

the RHS of a let expression cannot be an expression

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed the component context.


it('should not report error if template context conflict with component context', () => {
mockHost.override(TEST_TEMPLATE, `
<div *ngFor="let h of heroes; let i = index">
Copy link
Contributor

Choose a reason for hiding this comment

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

There should already be a test for this when checking the type of an ngFor export.

@ivanwonder ivanwonder force-pushed the resolve-variable-from-template-context-first branch from 48d6c89 to 7112cb8 Compare March 10, 2020 06:18
matsko pushed a commit that referenced this pull request Mar 10, 2020
@matsko matsko closed this in 3d46a45 Mar 10, 2020
@ivanwonder ivanwonder deleted the resolve-variable-from-template-context-first branch April 1, 2020 12:17
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators May 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: language-service Issues related to Angular's VS Code language service cla: yes target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The index of a ngFor is not recongnized as a number again
4 participants