Skip to content
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

feat(compiler): add name spans for property reads and method calls #36826

Closed
wants to merge 5 commits into from

Conversation

ayazhafiz
Copy link
Member

ASTs for property read and method calls contain information about
the entire span of the expression, including its receiver. Use cases
like a language service and compile error messages may be more
interested in the span of the direct identifier for which the
expression is constructed (i.e. an accessed property). To support this,
this commit adds a nameSpan property on

  • PropertyReads
  • SafePropertyReads
  • PropertyWrites
  • MethodCalls
  • SafeMethodCalls

The nameSpan property already existed for BindingPipes.

This commit also updates usages of these expressions' sourceSpans in
Ngtsc and the langauge service to use nameSpans where appropriate.

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Feature

Does this PR introduce a breaking change?

  • Yes
  • No

@ayazhafiz ayazhafiz added feature Issue that requests a new feature action: review The PR is still awaiting reviews from at least one requested reviewer area: language-service Issues related to Angular's VS Code language service target: patch This PR is targeted for the next patch release comp: ivy area: compiler Issues related to `ngc`, Angular's template compiler labels Apr 28, 2020
@ngbot ngbot bot modified the milestone: needsTriage Apr 28, 2020
@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

Copy link
Member

@JoostK JoostK left a comment

Choose a reason for hiding this comment

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

Thanks for working on this. I do have some comments on the chosen source spans in the template type checker.

In general, I think our AST nodes could be cleaned up a lot if we were to have something like Identifier, similar to the TypeScript AST. That seems like a large project by itself though, so it's not necessary for this PR. It may also be problematic to push that forward, as tools that depend on the compiler for parsing ASTs would have to be updated. Although the compiler is not technically considered public API, such breakages are still problematic to push through.

@ayazhafiz ayazhafiz requested a review from JoostK May 3, 2020 17:16
@ayazhafiz
Copy link
Member Author

In general, I think our AST nodes could be cleaned up a lot if we were to have something like Identifier, similar to the TypeScript AST.

such breakages are still problematic to push through.

I agree that this would be difficult to push through. IMO the benefit of this isn't worth the churn -- the expression grammar is fairly small, so exposing a common interface for identifier-like ASTs is probably enough.

@ayazhafiz
Copy link
Member Author

@JoostK there are still some minor things that could be improved, for example wrapping method calls for diagnostics and annotating that with the span including any receivers (like is done for property reads). I think this can be done in another PR though, since this one is very large as is.

@ayazhafiz ayazhafiz requested a review from JoostK May 5, 2020 15:40
ASTs for property read and method calls contain information about
the entire span of the expression, including its receiver. Use cases
like a language service and compile error messages may be more
interested in the span of the direct identifier for which the
expression is constructed (i.e. an accessed property). To support this,
this commit adds a `nameSpan` property on

- `PropertyRead`s
- `SafePropertyRead`s
- `PropertyWrite`s
- `MethodCall`s
- `SafeMethodCall`s

The `nameSpan` property already existed for `BindingPipe`s.

This commit also updates usages of these expressions' `sourceSpan`s in
Ngtsc and the langauge service to use `nameSpan`s where appropriate.
Copy link
Member

@JoostK JoostK left a comment

Choose a reason for hiding this comment

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

LGTM for compiler changes.

@ayazhafiz ayazhafiz added action: merge The PR is ready for merge by the caretaker merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels May 5, 2020
@ayazhafiz
Copy link
Member Author

Caretaker: could you run g3sync? (I think there may be some failures with Codelyzer)

@ayazhafiz ayazhafiz removed the request for review from alxhub May 5, 2020 16:34
@alxhub
Copy link
Member

alxhub commented May 5, 2020

Presubmit

@mhevery mhevery removed the merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note label May 8, 2020
@mhevery mhevery closed this in eb34aa5 May 8, 2020
mhevery pushed a commit that referenced this pull request May 8, 2020
…36826)

ASTs for property read and method calls contain information about
the entire span of the expression, including its receiver. Use cases
like a language service and compile error messages may be more
interested in the span of the direct identifier for which the
expression is constructed (i.e. an accessed property). To support this,
this commit adds a `nameSpan` property on

- `PropertyRead`s
- `SafePropertyRead`s
- `PropertyWrite`s
- `MethodCall`s
- `SafeMethodCall`s

The `nameSpan` property already existed for `BindingPipe`s.

This commit also updates usages of these expressions' `sourceSpan`s in
Ngtsc and the langauge service to use `nameSpan`s where appropriate.

PR Close #36826
@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 Jun 8, 2020
profanis pushed a commit to profanis/angular that referenced this pull request Sep 5, 2020
…ngular#36826)

ASTs for property read and method calls contain information about
the entire span of the expression, including its receiver. Use cases
like a language service and compile error messages may be more
interested in the span of the direct identifier for which the
expression is constructed (i.e. an accessed property). To support this,
this commit adds a `nameSpan` property on

- `PropertyRead`s
- `SafePropertyRead`s
- `PropertyWrite`s
- `MethodCall`s
- `SafeMethodCall`s

The `nameSpan` property already existed for `BindingPipe`s.

This commit also updates usages of these expressions' `sourceSpan`s in
Ngtsc and the langauge service to use `nameSpan`s where appropriate.

PR Close angular#36826
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: compiler Issues related to `ngc`, Angular's template compiler area: language-service Issues related to Angular's VS Code language service cla: yes feature Issue that requests a new feature target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants