diff --git a/packages/language-service/src/locate_symbol.ts b/packages/language-service/src/locate_symbol.ts index 63423b8671..36d09f80d7 100644 --- a/packages/language-service/src/locate_symbol.ts +++ b/packages/language-service/src/locate_symbol.ts @@ -148,12 +148,16 @@ function findAttribute(info: AstResult, position: number): Attribute|undefined { return path.first(Attribute); } +// TODO: remove this function after the path includes 'DirectiveAst'. +// Find the directive that corresponds to the specified 'binding' +// at the specified 'position' in the 'ast'. function findParentOfBinding( - ast: TemplateAst[], binding: BoundDirectivePropertyAst, position: number) { + ast: TemplateAst[], binding: BoundDirectivePropertyAst, position: number): DirectiveAst| + undefined { let res: DirectiveAst|undefined; const visitor = new class extends RecursiveTemplateAstVisitor { visit(ast: TemplateAst): any { - let span = spanOf(ast); + const span = spanOf(ast); if (!inSpan(position, span)) { // Returning a value here will result in the children being skipped. return true; diff --git a/packages/language-service/test/definitions_spec.ts b/packages/language-service/test/definitions_spec.ts index 3c13af8087..1d9da99af6 100644 --- a/packages/language-service/test/definitions_spec.ts +++ b/packages/language-service/test/definitions_spec.ts @@ -314,11 +314,8 @@ describe('definitions', () => { expect(def.name).toBe('model'); expect(def.kind).toBe('property'); const content = mockHost.readFile(refFileName) !; - const ref = `@Input() model: string = 'model';`; - expect(def.textSpan).toEqual({ - start: content.indexOf(ref), - length: ref.length, - }); + expect(content.substring(def.textSpan.start, def.textSpan.start + def.textSpan.length)) + .toEqual(`@Input() model: string = 'model';`); }); it('should be able to find a template from a url', () => {