fix(language-service): fix calculation of pipe spans (#35986)
This commit accomplishes two tasks: - Fixes the span of queried pipes to only be applied on pipe names - By consequence, fixes how pipes are located in arguments (previously, pipes with arguments could not be found because the span of a pipe uses a relative span, while the template position is absolute) The screenshots attached to the PR for this commit demonstrate the change. Closes https://github.com/angular/vscode-ng-language-service/issues/677 PR Close #35986
This commit is contained in:

committed by
Matias Niemelä

parent
a73e125c04
commit
406419bc0f
@ -96,6 +96,14 @@ export function getExpressionCompletions(
|
||||
return result && result.values();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the expression symbol at a particular position in a template.
|
||||
*
|
||||
* @param scope symbols in scope of the template
|
||||
* @param ast template AST
|
||||
* @param position absolute location in template to retrieve symbol at
|
||||
* @param query type symbol query for the template scope
|
||||
*/
|
||||
export function getExpressionSymbol(
|
||||
scope: SymbolTable, ast: AST, position: number,
|
||||
query: SymbolQuery): {symbol: Symbol, span: Span}|undefined {
|
||||
@ -129,14 +137,19 @@ export function getExpressionSymbol(
|
||||
span = ast.span;
|
||||
},
|
||||
visitPipe(ast) {
|
||||
if (position >= ast.exp.span.end &&
|
||||
(!ast.args || !ast.args.length || position < (<AST>ast.args[0]).span.start)) {
|
||||
if (inSpan(position, ast.nameSpan, /* exclusive */ true)) {
|
||||
// We are in a position a pipe name is expected.
|
||||
const pipes = query.getPipes();
|
||||
if (pipes) {
|
||||
symbol = pipes.get(ast.name);
|
||||
span = ast.span;
|
||||
}
|
||||
symbol = pipes.get(ast.name);
|
||||
|
||||
// `nameSpan` is an absolute span, but the span expected by the result of this method is
|
||||
// relative to the start of the expression.
|
||||
// TODO(ayazhafiz): migrate to only using absolute spans
|
||||
const offset = ast.sourceSpan.start - ast.span.start;
|
||||
span = {
|
||||
start: ast.nameSpan.start - offset,
|
||||
end: ast.nameSpan.end - offset,
|
||||
};
|
||||
}
|
||||
},
|
||||
visitPrefixNot(ast) {},
|
||||
|
Reference in New Issue
Block a user