Skip to content

Commit 4604fe9

Browse files
committed
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
1 parent 01ec0f0 commit 4604fe9

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

packages/language-service/ivy/quick_info.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,14 @@ export class QuickInfoBuilder {
143143
ts.QuickInfo {
144144
const kind = dir.isComponent ? QuickInfoKind.COMPONENT : QuickInfoKind.DIRECTIVE;
145145
const documentation = this.getDocumentationFromTypeDefAtLocation(dir.shimLocation);
146+
let containerName: string|undefined;
147+
if (ts.isClassDeclaration(dir.tsSymbol.valueDeclaration) && dir.ngModule !== null) {
148+
containerName = dir.ngModule.name.getText();
149+
}
150+
146151
return createQuickInfo(
147-
this.typeChecker.typeToString(dir.tsType), kind, getTextSpanOfNode(node),
148-
undefined /* containerName */, undefined, documentation);
152+
this.typeChecker.typeToString(dir.tsType), kind, getTextSpanOfNode(node), containerName,
153+
undefined, documentation);
149154
}
150155

151156
private getDocumentationFromTypeDefAtLocation(shimLocation: ShimLocation):

packages/language-service/ivy/test/quick_info_spec.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,15 @@ describe('quick info', () => {
4747
expectQuickInfo({
4848
templateOverride: `<div string-model¦></div>`,
4949
expectedSpanText: 'string-model',
50-
// TODO(atscott): Find a way to include the module
51-
// expectedDisplayParts: '(directive) AppModule.StringModel'
52-
expectedDisplayString: '(directive) StringModel'
50+
expectedDisplayString: '(directive) AppModule.StringModel'
5351
});
5452
});
5553

5654
it('should work for components', () => {
5755
const {documentation} = expectQuickInfo({
5856
templateOverride: `<t¦est-comp></test-comp>`,
5957
expectedSpanText: '<test-comp></test-comp>',
60-
// TODO(atscott): Find a way to include the module
61-
// expectedDisplayParts: '(component) AppModule.TestComponent'
62-
expectedDisplayString: '(component) TestComponent'
58+
expectedDisplayString: '(component) AppModule.TestComponent'
6359
});
6460
expect(toText(documentation)).toBe('This Component provides the `test-comp` selector.');
6561
});

packages/language-service/src/ts_utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ interface DirectiveClassLike {
8686
* For example,
8787
* v---------- `decoratorId`
8888
* @NgModule({ <
89-
* declarations: [], < classDecl
89+
* declarations: [], < classDecln-al
9090
* }) <
9191
* class AppModule {} <
9292
* ^----- `classId`

0 commit comments

Comments
 (0)