diff --git a/packages/language-service/src/locate_symbol.ts b/packages/language-service/src/locate_symbol.ts index d46e542896..f91a315166 100644 --- a/packages/language-service/src/locate_symbol.ts +++ b/packages/language-service/src/locate_symbol.ts @@ -29,6 +29,8 @@ export function locateSymbols(info: AstResult, position: number): SymbolInfo[] { const templatePosition = position - info.template.span.start; // TODO: update `findTemplateAstAt` to use absolute positions. const path = findTemplateAstAt(info.templateAst, templatePosition); + const attribute = findAttribute(info, position); + if (!path.tail) return []; const narrowest = spanOf(path.tail); @@ -38,6 +40,11 @@ export function locateSymbols(info: AstResult, position: number): SymbolInfo[] { toVisit.push(node); } + // For the structural directive, only care about the last template AST. + if (attribute?.name.startsWith('*')) { + toVisit.splice(0, toVisit.length - 1); + } + return toVisit.map(ast => locateSymbol(ast, path, info)) .filter((sym): sym is SymbolInfo => sym !== undefined); } diff --git a/packages/language-service/test/definitions_spec.ts b/packages/language-service/test/definitions_spec.ts index 44c8aaab16..9b0455dd68 100644 --- a/packages/language-service/test/definitions_spec.ts +++ b/packages/language-service/test/definitions_spec.ts @@ -311,7 +311,7 @@ describe('definitions', () => { expect(definitions).toBeDefined(); // The two definitions are setter and getter of 'ngForTrackBy'. - expect(definitions !.length).toBe(4); + expect(definitions !.length).toBe(2); const refFileName = '/node_modules/@angular/common/common.d.ts'; definitions !.forEach(def => { @@ -335,7 +335,7 @@ describe('definitions', () => { expect(textSpan).toEqual(marker); expect(definitions).toBeDefined(); - expect(definitions !.length).toBe(2); + expect(definitions !.length).toBe(1); const refFileName = '/app/parsing-cases.ts'; const def = definitions ![0];