From 2ef0b500efeebe9bca1eb8e870a9d6d6855d0122 Mon Sep 17 00:00:00 2001 From: ayazhafiz Date: Fri, 20 Dec 2019 16:40:23 -0600 Subject: [PATCH] refactor(language-service): rename expression completions method (#34518) This commit renames `addAttributeValuesToCompletions`, which generates expression completions and is not exclusive to processing attributes, to `processExpressionCompletions`. Also removes the expression completion logic in `visitBoundText` for a call to `processExpressionCompletions`. The conditional branch in `visitBoundText` is also removed. This branch was added in one of the first commits to the language service (519a32445407136b9d6b969cd0be6aa42ca73055) and appears to be unnecessary, as the expression AST is constructed from the template position anyway. PR Close #34518 --- packages/language-service/src/completions.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/language-service/src/completions.ts b/packages/language-service/src/completions.ts index 6ced2b6297..acdc478d4d 100644 --- a/packages/language-service/src/completions.ts +++ b/packages/language-service/src/completions.ts @@ -432,14 +432,14 @@ class ExpressionVisitor extends NullTemplateVisitor { get results(): ng.CompletionEntry[] { return Array.from(this.completions.values()); } visitDirectiveProperty(ast: BoundDirectivePropertyAst): void { - this.addAttributeValuesToCompletions(ast.value); + this.processExpressionCompletions(ast.value); } visitElementProperty(ast: BoundElementPropertyAst): void { - this.addAttributeValuesToCompletions(ast.value); + this.processExpressionCompletions(ast.value); } - visitEvent(ast: BoundEventAst): void { this.addAttributeValuesToCompletions(ast.handler); } + visitEvent(ast: BoundEventAst): void { this.processExpressionCompletions(ast.handler); } visitElement(ast: ElementAst): void { // no-op for now @@ -466,7 +466,7 @@ class ExpressionVisitor extends NullTemplateVisitor { // The expression must be reparsed to get a valid AST rather than only template bindings. const expressionAst = this.info.expressionParser.parseBinding( ast.value, ast.sourceSpan.toString(), ast.sourceSpan.start.offset); - this.addAttributeValuesToCompletions(expressionAst); + this.processExpressionCompletions(expressionAst); } } @@ -490,7 +490,7 @@ class ExpressionVisitor extends NullTemplateVisitor { } } - private addAttributeValuesToCompletions(value: AST) { + private processExpressionCompletions(value: AST) { const symbols = getExpressionCompletions( this.getExpressionScope(), value, this.position, this.info.template.query); if (symbols) { @@ -566,7 +566,7 @@ class ExpressionVisitor extends NullTemplateVisitor { } if (binding.expression && inSpan(valueRelativePosition, binding.expression.ast.span)) { - this.addAttributeValuesToCompletions(binding.expression.ast); + this.processExpressionCompletions(binding.expression.ast); return; } @@ -578,7 +578,7 @@ class ExpressionVisitor extends NullTemplateVisitor { if (ofLocation > 0 && valueRelativePosition >= ofLocation + KW_OF.length) { const expressionAst = this.info.expressionParser.parseBinding( attr.value, attr.sourceSpan.toString(), attr.sourceSpan.start.offset); - this.addAttributeValuesToCompletions(expressionAst); + this.processExpressionCompletions(expressionAst); } } }