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
This commit is contained in:
Andrew Scott 2020-10-02 12:13:25 -07:00 committed by atscott
parent 01ec0f0933
commit 4604fe9ed2
3 changed files with 10 additions and 9 deletions

View File

@ -143,9 +143,14 @@ export class QuickInfoBuilder {
ts.QuickInfo { ts.QuickInfo {
const kind = dir.isComponent ? QuickInfoKind.COMPONENT : QuickInfoKind.DIRECTIVE; const kind = dir.isComponent ? QuickInfoKind.COMPONENT : QuickInfoKind.DIRECTIVE;
const documentation = this.getDocumentationFromTypeDefAtLocation(dir.shimLocation); 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( return createQuickInfo(
this.typeChecker.typeToString(dir.tsType), kind, getTextSpanOfNode(node), this.typeChecker.typeToString(dir.tsType), kind, getTextSpanOfNode(node), containerName,
undefined /* containerName */, undefined, documentation); undefined, documentation);
} }
private getDocumentationFromTypeDefAtLocation(shimLocation: ShimLocation): private getDocumentationFromTypeDefAtLocation(shimLocation: ShimLocation):

View File

@ -47,9 +47,7 @@ describe('quick info', () => {
expectQuickInfo({ expectQuickInfo({
templateOverride: `<div string-model¦></div>`, templateOverride: `<div string-model¦></div>`,
expectedSpanText: 'string-model', expectedSpanText: 'string-model',
// TODO(atscott): Find a way to include the module expectedDisplayString: '(directive) AppModule.StringModel'
// expectedDisplayParts: '(directive) AppModule.StringModel'
expectedDisplayString: '(directive) StringModel'
}); });
}); });
@ -57,9 +55,7 @@ describe('quick info', () => {
const {documentation} = expectQuickInfo({ const {documentation} = expectQuickInfo({
templateOverride: `<t¦est-comp></test-comp>`, templateOverride: `<t¦est-comp></test-comp>`,
expectedSpanText: '<test-comp></test-comp>', expectedSpanText: '<test-comp></test-comp>',
// TODO(atscott): Find a way to include the module expectedDisplayString: '(component) AppModule.TestComponent'
// expectedDisplayParts: '(component) AppModule.TestComponent'
expectedDisplayString: '(component) TestComponent'
}); });
expect(toText(documentation)).toBe('This Component provides the `test-comp` selector.'); expect(toText(documentation)).toBe('This Component provides the `test-comp` selector.');
}); });

View File

@ -86,7 +86,7 @@ interface DirectiveClassLike {
* For example, * For example,
* v---------- `decoratorId` * v---------- `decoratorId`
* @NgModule({ < * @NgModule({ <
* declarations: [], < classDecl * declarations: [], < classDecln-al
* }) < * }) <
* class AppModule {} < * class AppModule {} <
* ^----- `classId` * ^----- `classId`