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 sourceSpan and keySpan to TemplateBinding #35897

Closed
wants to merge 1 commit into from

Conversation

kyliau
Copy link
Contributor

@kyliau kyliau commented Mar 6, 2020

This commit adds fine-grained text spans to TemplateBinding for microsyntax expressions.

  1. Source span
    By convention, source span refers to the entire span of the binding,
    including its key and value.
  2. Key span
    Span of the binding key, without any whitespace or keywords like let
  3. Value span
    The value span is captured by the value expression AST.

These spans are primarily needed by the language service to provide precise autocomplete
suggestions and quick hover info at particular position.

The tests for microsyntax expressions are totally overhauled for better coverage, conciseness, and organization.

This is part of a series of PRs to fix source span mapping in microsyntax expression.
For more info, please see the design doc https://docs.google.com/document/d/1mEVF2pSSMSnOloqOPQTYNiAJO0XQxA1H0BZyESASOrE/edit?usp=sharing

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

@kyliau kyliau added area: compiler Issues related to `ngc`, Angular's template compiler target: patch This PR is targeted for the next patch release labels Mar 6, 2020
@ngbot ngbot bot added this to the needsTriage milestone Mar 6, 2020
@kyliau kyliau force-pushed the key-value-span-2 branch 3 times, most recently from b0431bd to d2c1044 Compare March 6, 2020 18:30
@kyliau kyliau marked this pull request as ready for review March 6, 2020 20:19
Copy link
Contributor

@AndrewKushnir AndrewKushnir 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 the changes and additional docs @kyliau 👍

I've added a couple comments, could you please have a look?

Thank you.

packages/compiler/src/expression_parser/parser.ts Outdated Show resolved Hide resolved
packages/compiler/src/expression_parser/parser.ts Outdated Show resolved Hide resolved
packages/compiler/src/expression_parser/ast.ts Outdated Show resolved Hide resolved
packages/compiler/src/expression_parser/parser.ts Outdated Show resolved Hide resolved
packages/compiler/src/expression_parser/parser.ts Outdated Show resolved Hide resolved
packages/language-service/src/completions.ts Show resolved Hide resolved
packages/language-service/src/completions.ts Show resolved Hide resolved
packages/language-service/src/locate_symbol.ts Outdated Show resolved Hide resolved
@kyliau kyliau force-pushed the key-value-span-2 branch 2 times, most recently from 8efd373 to 6958f69 Compare March 9, 2020 23:08
Copy link
Contributor Author

@kyliau kyliau left a comment

Choose a reason for hiding this comment

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

@AndrewKushnir @ayazhafiz Thank you for the valuable feedback!
After analyzing the structure of the code, I realized much of the complexity comes from the decision to use ASTWithSource to represent the value of the binding for both variable binding and expression binding.
ASTWithSource is messy to work with because it contains both relative span and absolute span, so we had to keep track of both.
The fundamental problem stems from the usage of field variable keyIsVar to differentiate the data types for variable binding and expression binding. The right thing to do here is to use the type information to represent the data, and I've created two separate classes, VariableBinding and ExpressionBinding to reflect this.
With this change, there is no more confusing relative spans to deal with. All spans handled within the microsyntax expression parsing are absolute spans. The implementation should be much cleaner now. Please take a look and let me know what you think. Thank you!

packages/compiler/src/expression_parser/parser.ts Outdated Show resolved Hide resolved
packages/compiler/src/expression_parser/parser.ts Outdated Show resolved Hide resolved
packages/language-service/src/completions.ts Show resolved Hide resolved
packages/language-service/src/completions.ts Show resolved Hide resolved
packages/language-service/src/locate_symbol.ts Outdated Show resolved Hide resolved
packages/compiler/src/expression_parser/ast.ts Outdated Show resolved Hide resolved
Copy link
Member

@ayazhafiz ayazhafiz left a comment

Choose a reason for hiding this comment

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

LGTM, just a comment regarding testing spans

packages/compiler/src/expression_parser/ast.ts Outdated Show resolved Hide resolved
packages/compiler/test/expression_parser/parser_spec.ts Outdated Show resolved Hide resolved
packages/language-service/src/completions.ts Show resolved Hide resolved
@kyliau kyliau force-pushed the key-value-span-2 branch 3 times, most recently from 714ff0a to ac8dd2c Compare March 10, 2020 18:04
@kyliau
Copy link
Contributor Author

kyliau commented Mar 10, 2020

@ayazhafiz @AndrewKushnir I've addressed all comments, could you please take another look? Thank you!

Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @kyliau 👍

I left a few comments (mostly docs and minor refactoring proposals), please have a look when you get a chance.

Thank you.

@AndrewKushnir
Copy link
Contributor

@kyliau I think it'd make sense to also run a Global TAP (in addition to Blueprint one) to make sure everything looks good. Thank you.

This commit adds fine-grained text spans to TemplateBinding for microsyntax expressions.

1. Source span
   By convention, source span refers to the entire span of the binding,
   including its key and value.
2. Key span
   Span of the binding key, without any whitespace or keywords like `let`

The value span is captured by the value expression AST.

This is part of a series of PRs to fix source span mapping in microsyntax expression.
For more info, see the doc https://docs.google.com/document/d/1mEVF2pSSMSnOloqOPQTYNiAJO0XQxA1H0BZyESASOrE/edit?usp=sharing
@kyliau
Copy link
Contributor Author

kyliau commented Mar 11, 2020

@kyliau kyliau requested a review from ayazhafiz March 11, 2020 04:50
Copy link
Member

@ayazhafiz ayazhafiz left a comment

Choose a reason for hiding this comment

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

Could we add span tests for all test cases? Sorry..

@kyliau
Copy link
Contributor Author

kyliau commented Mar 11, 2020

Could we add span tests for all test cases? Sorry..

My intention was to separate the testing for key value and their spans, so that the tests are focused. There is a dedicated section for testing spans only from line 482-552.

@kyliau kyliau added the action: merge The PR is ready for merge by the caretaker label Mar 11, 2020
@matsko matsko added target: major This PR is targeted for the next major release and removed target: patch This PR is targeted for the next patch release labels Mar 11, 2020
@matsko matsko closed this in 06779cf Mar 11, 2020
kyliau pushed a commit to kyliau/angular that referenced this pull request Mar 11, 2020
…r#35897)

This commit adds fine-grained text spans to TemplateBinding for microsyntax expressions.

1. Source span
   By convention, source span refers to the entire span of the binding,
   including its key and value.
2. Key span
   Span of the binding key, without any whitespace or keywords like `let`

The value span is captured by the value expression AST.

This is part of a series of PRs to fix source span mapping in microsyntax expression.
For more info, see the doc https://docs.google.com/document/d/1mEVF2pSSMSnOloqOPQTYNiAJO0XQxA1H0BZyESASOrE/edit?usp=sharing

PR Close angular#35897

(cherry picked from commit 06779cf)
@kyliau kyliau deleted the key-value-span-2 branch March 11, 2020 20:20
@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 Apr 11, 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: compiler Issues related to `ngc`, Angular's template compiler cla: yes target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants