@@ -105,7 +105,7 @@ namespace ts.SymbolDisplay {
105
105
106
106
// TODO(drosen): Currently completion entry details passes the SemanticMeaning.All instead of using semanticMeaning of location
107
107
export function getSymbolDisplayPartsDocumentationAndSymbolKind ( typeChecker : TypeChecker , symbol : Symbol , sourceFile : SourceFile , enclosingDeclaration : Node ,
108
- location : Node , semanticMeaning = getMeaningFromLocation ( location ) ) : SymbolDisplayPartsDocumentationAndSymbolKind {
108
+ location : Node , semanticMeaning = getMeaningFromLocation ( location ) , alias ?: Symbol ) : SymbolDisplayPartsDocumentationAndSymbolKind {
109
109
110
110
const displayParts : SymbolDisplayPart [ ] = [ ] ;
111
111
let documentation : SymbolDisplayPart [ ] ;
@@ -115,6 +115,7 @@ namespace ts.SymbolDisplay {
115
115
let hasAddedSymbolInfo : boolean ;
116
116
const isThisExpression = location . kind === SyntaxKind . ThisKeyword && isExpression ( location ) ;
117
117
let type : Type ;
118
+ let documentationFromAlias : SymbolDisplayPart [ ] ;
118
119
119
120
// Class at constructor site need to be shown as constructor apart from property,method, vars
120
121
if ( symbolKind !== ScriptElementKind . unknown || symbolFlags & SymbolFlags . Class || symbolFlags & SymbolFlags . Alias ) {
@@ -243,6 +244,7 @@ namespace ts.SymbolDisplay {
243
244
}
244
245
}
245
246
if ( symbolFlags & SymbolFlags . Class && ! hasAddedSymbolInfo && ! isThisExpression ) {
247
+ addAliasPrefixIfNecessary ( ) ;
246
248
if ( getDeclarationOfKind ( symbol , SyntaxKind . ClassExpression ) ) {
247
249
// Special case for class expressions because we would like to indicate that
248
250
// the class name is local to the class body (similar to function expression)
@@ -258,14 +260,14 @@ namespace ts.SymbolDisplay {
258
260
writeTypeParametersOfSymbol ( symbol , sourceFile ) ;
259
261
}
260
262
if ( ( symbolFlags & SymbolFlags . Interface ) && ( semanticMeaning & SemanticMeaning . Type ) ) {
261
- addNewLineIfDisplayPartsExist ( ) ;
263
+ prefixNextMeaning ( ) ;
262
264
displayParts . push ( keywordPart ( SyntaxKind . InterfaceKeyword ) ) ;
263
265
displayParts . push ( spacePart ( ) ) ;
264
266
addFullSymbolName ( symbol ) ;
265
267
writeTypeParametersOfSymbol ( symbol , sourceFile ) ;
266
268
}
267
269
if ( symbolFlags & SymbolFlags . TypeAlias ) {
268
- addNewLineIfDisplayPartsExist ( ) ;
270
+ prefixNextMeaning ( ) ;
269
271
displayParts . push ( keywordPart ( SyntaxKind . TypeKeyword ) ) ;
270
272
displayParts . push ( spacePart ( ) ) ;
271
273
addFullSymbolName ( symbol ) ;
@@ -276,7 +278,7 @@ namespace ts.SymbolDisplay {
276
278
addRange ( displayParts , typeToDisplayParts ( typeChecker , typeChecker . getDeclaredTypeOfSymbol ( symbol ) , enclosingDeclaration , TypeFormatFlags . InTypeAlias ) ) ;
277
279
}
278
280
if ( symbolFlags & SymbolFlags . Enum ) {
279
- addNewLineIfDisplayPartsExist ( ) ;
281
+ prefixNextMeaning ( ) ;
280
282
if ( forEach ( symbol . declarations , isConstEnumDeclaration ) ) {
281
283
displayParts . push ( keywordPart ( SyntaxKind . ConstKeyword ) ) ;
282
284
displayParts . push ( spacePart ( ) ) ;
@@ -286,15 +288,15 @@ namespace ts.SymbolDisplay {
286
288
addFullSymbolName ( symbol ) ;
287
289
}
288
290
if ( symbolFlags & SymbolFlags . Module ) {
289
- addNewLineIfDisplayPartsExist ( ) ;
291
+ prefixNextMeaning ( ) ;
290
292
const declaration = getDeclarationOfKind < ModuleDeclaration > ( symbol , SyntaxKind . ModuleDeclaration ) ;
291
293
const isNamespace = declaration && declaration . name && declaration . name . kind === SyntaxKind . Identifier ;
292
294
displayParts . push ( keywordPart ( isNamespace ? SyntaxKind . NamespaceKeyword : SyntaxKind . ModuleKeyword ) ) ;
293
295
displayParts . push ( spacePart ( ) ) ;
294
296
addFullSymbolName ( symbol ) ;
295
297
}
296
298
if ( ( symbolFlags & SymbolFlags . TypeParameter ) && ( semanticMeaning & SemanticMeaning . Type ) ) {
297
- addNewLineIfDisplayPartsExist ( ) ;
299
+ prefixNextMeaning ( ) ;
298
300
displayParts . push ( punctuationPart ( SyntaxKind . OpenParenToken ) ) ;
299
301
displayParts . push ( textPart ( "type parameter" ) ) ;
300
302
displayParts . push ( punctuationPart ( SyntaxKind . CloseParenToken ) ) ;
@@ -354,7 +356,32 @@ namespace ts.SymbolDisplay {
354
356
}
355
357
}
356
358
if ( symbolFlags & SymbolFlags . Alias ) {
357
- addNewLineIfDisplayPartsExist ( ) ;
359
+ prefixNextMeaning ( ) ;
360
+ if ( ! hasAddedSymbolInfo ) {
361
+ const resolvedSymbol = typeChecker . getAliasedSymbol ( symbol ) ;
362
+ if ( resolvedSymbol !== symbol && resolvedSymbol . declarations && resolvedSymbol . declarations . length > 0 ) {
363
+ const resolvedNode = resolvedSymbol . declarations [ 0 ] ;
364
+ const declarationName = ts . getNameOfDeclaration ( resolvedNode ) ;
365
+ if ( declarationName ) {
366
+ const isExternalModuleDeclaration =
367
+ ts . isModuleWithStringLiteralName ( resolvedNode ) &&
368
+ ts . hasModifier ( resolvedNode , ModifierFlags . Ambient ) ;
369
+ const shouldUseAliasName = symbol . name !== "default" && ! isExternalModuleDeclaration ;
370
+ const resolvedInfo = getSymbolDisplayPartsDocumentationAndSymbolKind (
371
+ typeChecker ,
372
+ resolvedSymbol ,
373
+ ts . getSourceFileOfNode ( resolvedNode ) ,
374
+ resolvedNode ,
375
+ declarationName ,
376
+ semanticMeaning ,
377
+ shouldUseAliasName ? symbol : resolvedSymbol ) ;
378
+ displayParts . push ( ...resolvedInfo . displayParts ) ;
379
+ displayParts . push ( lineBreakPart ( ) ) ;
380
+ documentationFromAlias = resolvedInfo . documentation ;
381
+ }
382
+ }
383
+ }
384
+
358
385
switch ( symbol . declarations [ 0 ] . kind ) {
359
386
case SyntaxKind . NamespaceExportDeclaration :
360
387
displayParts . push ( keywordPart ( SyntaxKind . ExportKeyword ) ) ;
@@ -400,7 +427,7 @@ namespace ts.SymbolDisplay {
400
427
if ( symbolKind !== ScriptElementKind . unknown ) {
401
428
if ( type ) {
402
429
if ( isThisExpression ) {
403
- addNewLineIfDisplayPartsExist ( ) ;
430
+ prefixNextMeaning ( ) ;
404
431
displayParts . push ( keywordPart ( SyntaxKind . ThisKeyword ) ) ;
405
432
}
406
433
else {
@@ -472,12 +499,24 @@ namespace ts.SymbolDisplay {
472
499
}
473
500
}
474
501
502
+ if ( documentation . length === 0 && documentationFromAlias ) {
503
+ documentation = documentationFromAlias ;
504
+ }
505
+
475
506
return { displayParts, documentation, symbolKind, tags } ;
476
507
477
- function addNewLineIfDisplayPartsExist ( ) {
508
+ function prefixNextMeaning ( ) {
478
509
if ( displayParts . length ) {
479
510
displayParts . push ( lineBreakPart ( ) ) ;
480
511
}
512
+ addAliasPrefixIfNecessary ( ) ;
513
+ }
514
+
515
+ function addAliasPrefixIfNecessary ( ) {
516
+ if ( alias ) {
517
+ pushTypePart ( ScriptElementKind . alias ) ;
518
+ displayParts . push ( spacePart ( ) ) ;
519
+ }
481
520
}
482
521
483
522
function addInPrefix ( ) {
@@ -486,14 +525,17 @@ namespace ts.SymbolDisplay {
486
525
displayParts . push ( spacePart ( ) ) ;
487
526
}
488
527
489
- function addFullSymbolName ( symbol : Symbol , enclosingDeclaration ?: Node ) {
490
- const fullSymbolDisplayParts = symbolToDisplayParts ( typeChecker , symbol , enclosingDeclaration || sourceFile , /*meaning*/ undefined ,
528
+ function addFullSymbolName ( symbolToDisplay : Symbol , enclosingDeclaration ?: Node ) {
529
+ if ( alias && symbolToDisplay === symbol ) {
530
+ symbolToDisplay = alias ;
531
+ }
532
+ const fullSymbolDisplayParts = symbolToDisplayParts ( typeChecker , symbolToDisplay , enclosingDeclaration || sourceFile , /*meaning*/ undefined ,
491
533
SymbolFormatFlags . WriteTypeParametersOrArguments | SymbolFormatFlags . UseOnlyExternalAliasing ) ;
492
534
addRange ( displayParts , fullSymbolDisplayParts ) ;
493
535
}
494
536
495
537
function addPrefixForAnyFunctionOrVar ( symbol : Symbol , symbolKind : string ) {
496
- addNewLineIfDisplayPartsExist ( ) ;
538
+ prefixNextMeaning ( ) ;
497
539
if ( symbolKind ) {
498
540
pushTypePart ( symbolKind ) ;
499
541
if ( symbol && ! some ( symbol . declarations , d => isArrowFunction ( d ) || ( isFunctionExpression ( d ) || isClassExpression ( d ) ) && ! d . name ) ) {
0 commit comments