@@ -1317,16 +1317,46 @@ module ts {
1317
1317
return displayPart ( "\n" , SymbolDisplayPartKind . lineBreak ) ;
1318
1318
}
1319
1319
1320
+ function isFirstDeclarationOfSymbolParameter ( symbol : Symbol ) {
1321
+ return symbol . declarations && symbol . declarations . length > 0 && symbol . declarations [ 0 ] . kind === SyntaxKind . Parameter ;
1322
+ }
1323
+
1324
+ function isLocalVariableOrFunction ( symbol : Symbol ) {
1325
+ if ( symbol . parent ) {
1326
+ return false ; // This is exported symbol
1327
+ }
1328
+
1329
+ return ts . forEach ( symbol . declarations , declaration => {
1330
+ // Function expressions are local
1331
+ if ( declaration . kind === SyntaxKind . FunctionExpression ) {
1332
+ return true ;
1333
+ }
1334
+
1335
+ if ( declaration . kind !== SyntaxKind . VariableDeclaration && declaration . kind !== SyntaxKind . FunctionDeclaration ) {
1336
+ return ;
1337
+ }
1338
+
1339
+ // If the parent is not sourceFile or module element it is local variable
1340
+ for ( var parent = declaration . parent ; parent . kind !== SyntaxKind . FunctionBlock ; parent = parent . parent ) {
1341
+ // Reached source file or module block
1342
+ if ( parent . kind === SyntaxKind . SourceFile || parent . kind === SyntaxKind . ModuleBlock ) {
1343
+ return ;
1344
+ }
1345
+ }
1346
+
1347
+ // parent is in function block
1348
+ return true ;
1349
+ } ) ;
1350
+ }
1351
+
1320
1352
export function symbolPart ( text : string , symbol : Symbol ) {
1321
1353
return displayPart ( text , displayPartKind ( symbol ) , symbol ) ;
1322
1354
1323
1355
function displayPartKind ( symbol : Symbol ) : SymbolDisplayPartKind {
1324
1356
var flags = symbol . flags ;
1325
1357
1326
1358
if ( flags & SymbolFlags . Variable ) {
1327
- return symbol . declarations && symbol . declarations . length > 0 && symbol . declarations [ 0 ] . kind === SyntaxKind . Parameter
1328
- ? SymbolDisplayPartKind . parameterName
1329
- : SymbolDisplayPartKind . localName ;
1359
+ return isFirstDeclarationOfSymbolParameter ( symbol ) ? SymbolDisplayPartKind . parameterName : SymbolDisplayPartKind . localName ;
1330
1360
}
1331
1361
else if ( flags & SymbolFlags . Property ) { return SymbolDisplayPartKind . propertyName ; }
1332
1362
else if ( flags & SymbolFlags . EnumMember ) { return SymbolDisplayPartKind . enumMemberName ; }
@@ -2534,27 +2564,35 @@ module ts {
2534
2564
if ( flags & SymbolFlags . Class ) return ScriptElementKind . classElement ;
2535
2565
if ( flags & SymbolFlags . Interface ) return ScriptElementKind . interfaceElement ;
2536
2566
if ( flags & SymbolFlags . Enum ) return ScriptElementKind . enumElement ;
2567
+ var result = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar ( symbol , flags ) ;
2568
+ if ( result === ScriptElementKind . unknown ) {
2569
+ if ( flags & SymbolFlags . IndexSignature ) return ScriptElementKind . indexSignatureElement ;
2570
+ if ( flags & SymbolFlags . ConstructSignature ) return ScriptElementKind . constructSignatureElement ;
2571
+ if ( flags & SymbolFlags . CallSignature ) return ScriptElementKind . callSignatureElement ;
2572
+ if ( flags & SymbolFlags . TypeParameter ) return ScriptElementKind . typeParameterElement ;
2573
+ if ( flags & SymbolFlags . EnumMember ) return ScriptElementKind . variableElement ;
2574
+ }
2575
+
2576
+ return result ;
2577
+ }
2578
+
2579
+ function getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar ( symbol : Symbol , flags : SymbolFlags ) {
2537
2580
if ( flags & SymbolFlags . Variable ) {
2538
- if ( ts . forEach ( symbol . declarations , declaration => declaration . kind === SyntaxKind . Parameter ) ) {
2581
+ if ( isFirstDeclarationOfSymbolParameter ( symbol ) ) {
2539
2582
return ScriptElementKind . parameterElement ;
2540
2583
}
2541
- return ScriptElementKind . variableElement ;
2584
+ return isLocalVariableOrFunction ( symbol ) ? ScriptElementKind . localVariableElement : ScriptElementKind . variableElement ;
2542
2585
}
2543
- if ( flags & SymbolFlags . Function ) return ScriptElementKind . functionElement ;
2586
+ if ( flags & SymbolFlags . Function ) return isLocalVariableOrFunction ( symbol ) ? ScriptElementKind . localFunctionElement : ScriptElementKind . functionElement ;
2544
2587
if ( flags & SymbolFlags . GetAccessor ) return ScriptElementKind . memberGetAccessorElement ;
2545
2588
if ( flags & SymbolFlags . SetAccessor ) return ScriptElementKind . memberSetAccessorElement ;
2546
2589
if ( flags & SymbolFlags . Method ) return ScriptElementKind . memberFunctionElement ;
2547
2590
if ( flags & SymbolFlags . Property ) return ScriptElementKind . memberVariableElement ;
2548
- if ( flags & SymbolFlags . IndexSignature ) return ScriptElementKind . indexSignatureElement ;
2549
- if ( flags & SymbolFlags . ConstructSignature ) return ScriptElementKind . constructSignatureElement ;
2550
- if ( flags & SymbolFlags . CallSignature ) return ScriptElementKind . callSignatureElement ;
2551
2591
if ( flags & SymbolFlags . Constructor ) return ScriptElementKind . constructorImplementationElement ;
2552
- if ( flags & SymbolFlags . TypeParameter ) return ScriptElementKind . typeParameterElement ;
2553
- if ( flags & SymbolFlags . EnumMember ) return ScriptElementKind . variableElement ;
2554
2592
2555
2593
return ScriptElementKind . unknown ;
2556
2594
}
2557
-
2595
+
2558
2596
function getTypeKind ( type : Type ) : string {
2559
2597
var flags = type . getFlags ( ) ;
2560
2598
@@ -2613,7 +2651,7 @@ module ts {
2613
2651
2614
2652
function getSymbolDisplayPartsofSymbol ( symbol : Symbol , sourceFile : SourceFile , enclosingDeclaration : Node , typeResolver : TypeChecker ) : SymbolDisplayPart [ ] {
2615
2653
var displayParts : SymbolDisplayPart [ ] = [ ] ;
2616
- var symbolFlags = typeResolver . getTargetSymbol ( symbol ) . flags ;
2654
+ var symbolFlags = typeResolver . getRootSymbol ( symbol ) . flags ;
2617
2655
if ( symbolFlags & SymbolFlags . Class ) {
2618
2656
displayParts . push ( keywordPart ( SyntaxKind . ClassKeyword ) ) ;
2619
2657
displayParts . push ( spacePart ( ) ) ;
@@ -2647,36 +2685,16 @@ module ts {
2647
2685
}
2648
2686
else {
2649
2687
//public static string FormatSymbolName(string name, string fullSymbolName, string kind, out bool useTypeName)
2688
+ var symbolKind = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar ( symbol , symbolFlags ) ;
2650
2689
var text : string ;
2651
- if ( symbolFlags & SymbolFlags . Property ) {
2652
- text = "property" ;
2653
- }
2654
- else if ( symbolFlags & SymbolFlags . EnumMember ) {
2690
+ if ( symbolKind === ScriptElementKind . unknown ) {
2691
+ if ( symbolFlags & SymbolFlags . EnumMember ) {
2655
2692
text = "enum member" ;
2656
2693
}
2657
- else if ( symbolFlags & SymbolFlags . Function ) {
2658
- text = "function" ;
2659
- }
2660
- else if ( symbolFlags & SymbolFlags . Variable ) {
2661
- if ( ts . forEach ( symbol . declarations , declaration => declaration . kind === SyntaxKind . Parameter ) ) {
2662
- text = "parameter" ;
2663
- }
2664
- else {
2665
- text = "var" ;
2666
- }
2667
- }
2668
- else if ( symbolFlags & SymbolFlags . Method ) {
2669
- text = "method" ;
2670
- }
2671
- else if ( symbolFlags & SymbolFlags . Constructor ) {
2672
- text = "constructor" ;
2673
- }
2674
- else if ( symbolFlags & SymbolFlags . GetAccessor ) {
2675
- text = "getter" ;
2676
- }
2677
- else if ( symbolFlags & SymbolFlags . SetAccessor ) {
2678
- text = "setter" ;
2679
- }
2694
+ }
2695
+ else {
2696
+ text = symbolKind ;
2697
+ }
2680
2698
2681
2699
if ( text || symbolFlags & SymbolFlags . Signature ) {
2682
2700
addNewLineIfDisplayPartsExist ( ) ;
0 commit comments