refactor(language-service): find expression ASTs using absolute spans (#33387)

Moves to using the absolute span of an expression AST (relative to an
entire template) rather than a relative span (relative to the start
of the expression) to find an expression AST given a position in a
template.

This is part of the changes needed to support text replacement in
templates (#33091).

PR Close #33387
This commit is contained in:
ayazhafiz
2019-10-24 19:07:04 -04:00
committed by Andrew Kushnir
parent 3f195fefa9
commit ee4fc12e42
3 changed files with 9 additions and 10 deletions

View File

@ -370,7 +370,7 @@ class ExpressionVisitor extends NullTemplateVisitor {
new PropertyRead(
span, span.toAbsolute(offset),
new ImplicitReceiver(span, span.toAbsolute(offset)), ''),
valueRelativePosition);
this.position);
} else {
keyCompletions();
}
@ -379,10 +379,9 @@ class ExpressionVisitor extends NullTemplateVisitor {
}
visitBoundText(ast: BoundTextAst) {
const expressionPosition = this.position - ast.sourceSpan.start.offset;
if (inSpan(expressionPosition, ast.value.span)) {
if (inSpan(this.position, ast.value.sourceSpan)) {
const completions = getExpressionCompletions(
this.getExpressionScope(), ast.value, expressionPosition, this.info.template.query);
this.getExpressionScope(), ast.value, this.position, this.info.template.query);
if (completions) {
this.result = this.symbolsToCompletions(completions);
}
@ -410,7 +409,7 @@ class ExpressionVisitor extends NullTemplateVisitor {
private get attributeValuePosition() {
if (this.attr && this.attr.valueSpan) {
return this.position - this.attr.valueSpan.start.offset;
return this.position;
}
return 0;
}