Skip to content

Commit

Permalink
feat(language-service): Add module name to directive quick info (#39121)
Browse files Browse the repository at this point in the history
This commit adds the module name as the `containerName` to the quick info
for directives.

PR Close #39121
  • Loading branch information
atscott committed Oct 8, 2020
1 parent 01ec0f0 commit 4604fe9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
9 changes: 7 additions & 2 deletions packages/language-service/ivy/quick_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 2 additions & 6 deletions packages/language-service/ivy/test/quick_info_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,15 @@ describe('quick info', () => {
expectQuickInfo({
templateOverride: `<div string-model¦></div>`,
expectedSpanText: 'string-model',
// TODO(atscott): Find a way to include the module
// expectedDisplayParts: '(directive) AppModule.StringModel'
expectedDisplayString: '(directive) StringModel'
expectedDisplayString: '(directive) AppModule.StringModel'
});
});

it('should work for components', () => {
const {documentation} = expectQuickInfo({
templateOverride: `<t¦est-comp></test-comp>`,
expectedSpanText: '<test-comp></test-comp>',
// 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.');
});
Expand Down
2 changes: 1 addition & 1 deletion packages/language-service/src/ts_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ interface DirectiveClassLike {
* For example,
* v---------- `decoratorId`
* @NgModule({ <
* declarations: [], < classDecl
* declarations: [], < classDecln-al
* }) <
* class AppModule {} <
* ^----- `classId`
Expand Down

0 comments on commit 4604fe9

Please sign in to comment.