Skip to content

Commit d5e91e0

Browse files
atscottmmalerba
authored andcommitted
fix(language-service): Forward the tags for quick info from the type definition (#59524)
Prior to this commit, the tags from the type definition were dropped. Tags may include, but are not limited to, deprecation information from the jsdoc. PR Close #59524
1 parent 739cada commit d5e91e0

File tree

2 files changed

+40
-13
lines changed

2 files changed

+40
-13
lines changed

packages/language-service/src/quick_info.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -145,38 +145,41 @@ export class QuickInfoBuilder {
145145
}
146146

147147
private getQuickInfoForVariableSymbol(symbol: VariableSymbol): ts.QuickInfo {
148-
const documentation = this.getDocumentationFromTypeDefAtLocation(symbol.initializerLocation);
148+
const info = this.getQuickInfoFromTypeDefAtLocation(symbol.initializerLocation);
149149
return createQuickInfo(
150150
symbol.declaration.name,
151151
DisplayInfoKind.VARIABLE,
152152
getTextSpanOfNode(this.node),
153153
undefined /* containerName */,
154154
this.typeChecker.typeToString(symbol.tsType),
155-
documentation,
155+
info?.documentation,
156+
info?.tags,
156157
);
157158
}
158159

159160
private getQuickInfoForLetDeclarationSymbol(symbol: LetDeclarationSymbol): ts.QuickInfo {
160-
const documentation = this.getDocumentationFromTypeDefAtLocation(symbol.initializerLocation);
161+
const info = this.getQuickInfoFromTypeDefAtLocation(symbol.initializerLocation);
161162
return createQuickInfo(
162163
symbol.declaration.name,
163164
DisplayInfoKind.LET,
164165
getTextSpanOfNode(this.node),
165166
undefined /* containerName */,
166167
this.typeChecker.typeToString(symbol.tsType),
167-
documentation,
168+
info?.documentation,
169+
info?.tags,
168170
);
169171
}
170172

171173
private getQuickInfoForReferenceSymbol(symbol: ReferenceSymbol): ts.QuickInfo {
172-
const documentation = this.getDocumentationFromTypeDefAtLocation(symbol.targetLocation);
174+
const info = this.getQuickInfoFromTypeDefAtLocation(symbol.targetLocation);
173175
return createQuickInfo(
174176
symbol.declaration.name,
175177
DisplayInfoKind.REFERENCE,
176178
getTextSpanOfNode(this.node),
177179
undefined /* containerName */,
178180
this.typeChecker.typeToString(symbol.tsType),
179-
documentation,
181+
info?.documentation,
182+
info?.tags,
180183
);
181184
}
182185

@@ -217,7 +220,7 @@ export class QuickInfoBuilder {
217220
node: TmplAstNode | AST = this.node,
218221
): ts.QuickInfo {
219222
const kind = dir.isComponent ? DisplayInfoKind.COMPONENT : DisplayInfoKind.DIRECTIVE;
220-
const documentation = this.getDocumentationFromTypeDefAtLocation(dir.tcbLocation);
223+
const info = this.getQuickInfoFromTypeDefAtLocation(dir.tcbLocation);
221224
let containerName: string | undefined;
222225
if (ts.isClassDeclaration(dir.tsSymbol.valueDeclaration) && dir.ngModule !== null) {
223226
containerName = dir.ngModule.name.getText();
@@ -229,22 +232,20 @@ export class QuickInfoBuilder {
229232
getTextSpanOfNode(this.node),
230233
containerName,
231234
undefined,
232-
documentation,
235+
info?.documentation,
236+
info?.tags,
233237
);
234238
}
235239

236-
private getDocumentationFromTypeDefAtLocation(
237-
tcbLocation: TcbLocation,
238-
): ts.SymbolDisplayPart[] | undefined {
240+
private getQuickInfoFromTypeDefAtLocation(tcbLocation: TcbLocation): ts.QuickInfo | undefined {
239241
const typeDefs = this.tsLS.getTypeDefinitionAtPosition(
240242
tcbLocation.tcbPath,
241243
tcbLocation.positionInFile,
242244
);
243245
if (typeDefs === undefined || typeDefs.length === 0) {
244246
return undefined;
245247
}
246-
return this.tsLS.getQuickInfoAtPosition(typeDefs[0].fileName, typeDefs[0].textSpan.start)
247-
?.documentation;
248+
return this.tsLS.getQuickInfoAtPosition(typeDefs[0].fileName, typeDefs[0].textSpan.start);
248249
}
249250

250251
private getQuickInfoAtTcbLocation(location: TcbLocation): ts.QuickInfo | undefined {

packages/language-service/test/quick_info_spec.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,25 @@ function quickInfoSkeleton(): {[fileName: string]: string} {
105105
@Input() config?: {color?: string};
106106
}
107107
108+
/**
109+
* Don't use me
110+
*
111+
* @deprecated use the new thing
112+
*/
113+
@Directive({
114+
selector: '[deprecated]',
115+
standalone: false,
116+
})
117+
export class DeprecatedDirective {}
118+
108119
@NgModule({
109120
declarations: [
110121
AppCmp,
111122
CompoundCustomButtonDirective,
112123
StringModel,
113124
TestComponent,
114125
SignalModel,
126+
DeprecatedDirective
115127
],
116128
imports: [
117129
CommonModule,
@@ -216,6 +228,20 @@ describe('quick info', () => {
216228
expectedDisplayString: '(variable) hero: Hero',
217229
});
218230
});
231+
232+
it('should get tags', () => {
233+
const templateOverride = '<div depr¦ecated></div>';
234+
const text = templateOverride.replace('¦', '');
235+
const template = project.openFile('app.html');
236+
template.contents = text;
237+
env.expectNoSourceDiagnostics();
238+
239+
template.moveCursorToText(templateOverride);
240+
const quickInfo = template.getQuickInfoAtPosition();
241+
const tags = quickInfo!.tags!;
242+
expect(tags[0].name).toBe('deprecated');
243+
expect(toText(tags[0].text)).toBe('use the new thing');
244+
});
219245
});
220246

221247
describe('bindings', () => {

0 commit comments

Comments
 (0)