fix(language-service): get the right 'ElementAst' in the nested HTML tag (#35317)

For example, '<div><p string-model~{cursor}></p></div>', when provide the hover info for 'string-model', the 'path.head' is root tag 'div'. Use the parent of 'path.tail' instead.

PR Close #35317
This commit is contained in:
ivanwonder 2020-02-10 19:27:41 +08:00 committed by Miško Hevery
parent 0a1a989fa9
commit 8e354dae00
2 changed files with 4 additions and 3 deletions

View File

@ -123,8 +123,8 @@ function locateSymbol(ast: TemplateAst, path: TemplateAstPath, info: AstResult):
},
visitElementProperty(ast) { attributeValueSymbol(ast.value); },
visitAttr(ast) {
const element = path.head;
if (!element || !(element instanceof ElementAst)) return;
const element = path.first(ElementAst);
if (!element) return;
// Create a mapping of all directives applied to the element from their selectors.
const matcher = new SelectorMatcher<DirectiveAst>();
for (const dir of element.directives) {

View File

@ -109,7 +109,8 @@ describe('hover', () => {
});
it('should be able to find a reference to a directive', () => {
const content = mockHost.override(TEST_TEMPLATE, `<div string-model~{cursor}></div>`);
const content =
mockHost.override(TEST_TEMPLATE, `<div><div string-model~{cursor}></div></div>`);
const marker = mockHost.getLocationMarkerFor(TEST_TEMPLATE, 'cursor');
const quickInfo = ngLS.getQuickInfoAtPosition(TEST_TEMPLATE, marker.start);
expect(quickInfo).toBeDefined();