From 4604fe9ed21d908cad3ffb7a428fefb0224b66aa Mon Sep 17 00:00:00 2001 From: Andrew Scott Date: Fri, 2 Oct 2020 12:13:25 -0700 Subject: [PATCH] feat(language-service): Add module name to directive quick info (#39121) This commit adds the module name as the `containerName` to the quick info for directives. PR Close #39121 --- packages/language-service/ivy/quick_info.ts | 9 +++++++-- packages/language-service/ivy/test/quick_info_spec.ts | 8 ++------ packages/language-service/src/ts_utils.ts | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/language-service/ivy/quick_info.ts b/packages/language-service/ivy/quick_info.ts index cab76ba08e..9673e0e54e 100644 --- a/packages/language-service/ivy/quick_info.ts +++ b/packages/language-service/ivy/quick_info.ts @@ -143,9 +143,14 @@ export class QuickInfoBuilder { ts.QuickInfo { const kind = dir.isComponent ? QuickInfoKind.COMPONENT : QuickInfoKind.DIRECTIVE; const documentation = this.getDocumentationFromTypeDefAtLocation(dir.shimLocation); + let containerName: string|undefined; + if (ts.isClassDeclaration(dir.tsSymbol.valueDeclaration) && dir.ngModule !== null) { + containerName = dir.ngModule.name.getText(); + } + return createQuickInfo( - this.typeChecker.typeToString(dir.tsType), kind, getTextSpanOfNode(node), - undefined /* containerName */, undefined, documentation); + this.typeChecker.typeToString(dir.tsType), kind, getTextSpanOfNode(node), containerName, + undefined, documentation); } private getDocumentationFromTypeDefAtLocation(shimLocation: ShimLocation): diff --git a/packages/language-service/ivy/test/quick_info_spec.ts b/packages/language-service/ivy/test/quick_info_spec.ts index ac262b78cd..15f5cc8e2a 100644 --- a/packages/language-service/ivy/test/quick_info_spec.ts +++ b/packages/language-service/ivy/test/quick_info_spec.ts @@ -47,9 +47,7 @@ describe('quick info', () => { expectQuickInfo({ templateOverride: `
`, expectedSpanText: 'string-model', - // TODO(atscott): Find a way to include the module - // expectedDisplayParts: '(directive) AppModule.StringModel' - expectedDisplayString: '(directive) StringModel' + expectedDisplayString: '(directive) AppModule.StringModel' }); }); @@ -57,9 +55,7 @@ describe('quick info', () => { const {documentation} = expectQuickInfo({ templateOverride: ``, expectedSpanText: '', - // TODO(atscott): Find a way to include the module - // expectedDisplayParts: '(component) AppModule.TestComponent' - expectedDisplayString: '(component) TestComponent' + expectedDisplayString: '(component) AppModule.TestComponent' }); expect(toText(documentation)).toBe('This Component provides the `test-comp` selector.'); }); diff --git a/packages/language-service/src/ts_utils.ts b/packages/language-service/src/ts_utils.ts index 741201765c..581e9c921f 100644 --- a/packages/language-service/src/ts_utils.ts +++ b/packages/language-service/src/ts_utils.ts @@ -86,7 +86,7 @@ interface DirectiveClassLike { * For example, * v---------- `decoratorId` * @NgModule({ < - * declarations: [], < classDecl + * declarations: [], < classDecln-al * }) < * class AppModule {} < * ^----- `classId`