@@ -2259,9 +2259,13 @@ module ts {
2259
2259
return undefined ;
2260
2260
}
2261
2261
2262
+ // TODO(drosen): Right now we just permit *all* semantic meanings when calling 'getSymbolKind'
2263
+ // which is permissible given that it is backwards compatible; but really we should consider
2264
+ // passing the meaning for the node so that we don't report that a suggestion for a value is an interface.
2265
+ // We COULD also just do what 'getSymbolModifiers' does, which is to use the first declaration.
2262
2266
return {
2263
2267
name : displayName ,
2264
- kind : getSymbolKind ( symbol ) ,
2268
+ kind : getSymbolKind ( symbol , SemanticMeaning . All ) ,
2265
2269
kindModifiers : getSymbolModifiers ( symbol )
2266
2270
} ;
2267
2271
}
@@ -2613,7 +2617,7 @@ module ts {
2613
2617
// which is permissible given that it is backwards compatible; but really we should consider
2614
2618
// passing the meaning for the node so that we don't report that a suggestion for a value is an interface.
2615
2619
// We COULD also just do what 'getSymbolModifiers' does, which is to use the first declaration.
2616
- var displayPartsDocumentationsAndSymbolKind = getSymbolDisplayPartsDocumentationAndSymbolKind ( symbol , getSourceFile ( filename ) , session . location , session . typeChecker , session . location ) ;
2620
+ var displayPartsDocumentationsAndSymbolKind = getSymbolDisplayPartsDocumentationAndSymbolKind ( symbol , getSourceFile ( filename ) , session . location , session . typeChecker , session . location , SemanticMeaning . All ) ;
2617
2621
return {
2618
2622
name : entryName ,
2619
2623
kind : displayPartsDocumentationsAndSymbolKind . symbolKind ,
@@ -2656,15 +2660,19 @@ module ts {
2656
2660
}
2657
2661
}
2658
2662
2659
- // TODO(drosen): use contextual SemanticMeaning.
2660
- function getSymbolKind ( symbol : Symbol ) : string {
2663
+ function getSymbolKind ( symbol : Symbol , meaningAtLocation : SemanticMeaning ) : string {
2661
2664
var flags = typeInfoResolver . getRootSymbols ( symbol ) [ 0 ] . getFlags ( ) ;
2662
2665
2663
2666
if ( flags & SymbolFlags . Class ) return ScriptElementKind . classElement ;
2664
2667
if ( flags & SymbolFlags . Enum ) return ScriptElementKind . enumElement ;
2665
- if ( flags & SymbolFlags . Interface ) return ScriptElementKind . interfaceElement ;
2666
- if ( flags & SymbolFlags . TypeParameter ) return ScriptElementKind . typeParameterElement ;
2667
-
2668
+
2669
+ // The following should only apply if encountered at a type position,
2670
+ // and need to have precedence over other meanings if this is the case.
2671
+ if ( meaningAtLocation & SemanticMeaning . Type ) {
2672
+ if ( flags & SymbolFlags . Interface ) return ScriptElementKind . interfaceElement ;
2673
+ if ( flags & SymbolFlags . TypeParameter ) return ScriptElementKind . typeParameterElement ;
2674
+ }
2675
+
2668
2676
var result = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar ( symbol , flags ) ;
2669
2677
if ( result === ScriptElementKind . unknown ) {
2670
2678
if ( flags & SymbolFlags . TypeParameter ) return ScriptElementKind . typeParameterElement ;
@@ -2737,15 +2745,13 @@ module ts {
2737
2745
: ScriptElementKindModifier . none ;
2738
2746
}
2739
2747
2740
- // TODO(drosen): use contextual SemanticMeaning.
2741
- function getSymbolDisplayPartsDocumentationAndSymbolKind ( symbol : Symbol ,
2742
- sourceFile : SourceFile ,
2743
- enclosingDeclaration : Node ,
2744
- typeResolver : TypeChecker ,
2745
- location : Node ) {
2748
+ function getSymbolDisplayPartsDocumentationAndSymbolKind ( symbol : Symbol , sourceFile : SourceFile , enclosingDeclaration : Node ,
2749
+ typeResolver : TypeChecker , location : Node ,
2750
+ // TODO(drosen): Currently completion entry details passes the SemanticMeaning.All instead of using semanticMeaning of location
2751
+ semanticMeaning = getMeaningFromLocation ( location ) ) {
2746
2752
var displayParts : SymbolDisplayPart [ ] = [ ] ;
2747
2753
var documentation : SymbolDisplayPart [ ] ;
2748
- var symbolFlags = typeResolver . getRootSymbol ( symbol ) . flags ;
2754
+ var symbolFlags = typeResolver . getRootSymbols ( symbol ) [ 0 ] . flags ;
2749
2755
var symbolKind = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar ( symbol , symbolFlags ) ;
2750
2756
var hasAddedSymbolInfo : boolean ;
2751
2757
// Class at constructor site need to be shown as constructor apart from property,method, vars
@@ -2847,14 +2853,13 @@ module ts {
2847
2853
}
2848
2854
}
2849
2855
}
2850
-
2851
2856
if ( symbolFlags & SymbolFlags . Class && ! hasAddedSymbolInfo ) {
2852
2857
displayParts . push ( keywordPart ( SyntaxKind . ClassKeyword ) ) ;
2853
2858
displayParts . push ( spacePart ( ) ) ;
2854
2859
displayParts . push . apply ( displayParts , symbolToDisplayParts ( typeResolver , symbol , sourceFile , /*meaning*/ undefined , SymbolFormatFlags . WriteTypeParametersOrArguments ) ) ;
2855
2860
writeTypeParametersOfSymbol ( symbol , sourceFile ) ;
2856
2861
}
2857
- if ( symbolFlags & SymbolFlags . Interface ) {
2862
+ if ( ( symbolFlags & SymbolFlags . Interface ) && ( semanticMeaning & SemanticMeaning . Type ) ) {
2858
2863
addNewLineIfDisplayPartsExist ( ) ;
2859
2864
displayParts . push ( keywordPart ( SyntaxKind . InterfaceKeyword ) ) ;
2860
2865
displayParts . push ( spacePart ( ) ) ;
@@ -2873,7 +2878,7 @@ module ts {
2873
2878
displayParts . push ( spacePart ( ) ) ;
2874
2879
displayParts . push . apply ( displayParts , symbolToDisplayParts ( typeResolver , symbol , sourceFile ) ) ;
2875
2880
}
2876
- if ( symbolFlags & SymbolFlags . TypeParameter ) {
2881
+ if ( ( symbolFlags & SymbolFlags . TypeParameter ) && ( semanticMeaning & SemanticMeaning . Type ) ) {
2877
2882
addNewLineIfDisplayPartsExist ( ) ;
2878
2883
displayParts . push ( punctuationPart ( SyntaxKind . OpenParenToken ) ) ;
2879
2884
displayParts . push ( textPart ( "type parameter" ) ) ;
@@ -2953,7 +2958,7 @@ module ts {
2953
2958
}
2954
2959
}
2955
2960
else {
2956
- symbolKind = getSymbolKind ( symbol ) ;
2961
+ symbolKind = getSymbolKind ( symbol , semanticMeaning ) ;
2957
2962
}
2958
2963
}
2959
2964
@@ -3015,7 +3020,6 @@ module ts {
3015
3020
3016
3021
var symbol = typeInfoResolver . getSymbolInfo ( node ) ;
3017
3022
if ( ! symbol ) {
3018
-
3019
3023
// Try getting just type at this position and show
3020
3024
switch ( node . kind ) {
3021
3025
case SyntaxKind . Identifier :
@@ -3107,25 +3111,6 @@ module ts {
3107
3111
return false ;
3108
3112
}
3109
3113
3110
- function getDefinitionFromSymbol ( symbol : Symbol , location : Node , result : DefinitionInfo [ ] ) : void {
3111
- var declarations = symbol . getDeclarations ( ) ;
3112
- if ( declarations ) {
3113
- var symbolName = typeInfoResolver . symbolToString ( symbol ) ; // Do not get scoped name, just the name of the symbol
3114
- var symbolKind = getSymbolKind ( symbol ) ;
3115
- var containerSymbol = symbol . parent ;
3116
- var containerName = containerSymbol ? typeInfoResolver . symbolToString ( containerSymbol , location ) : "" ;
3117
- var containerKind = containerSymbol ? getSymbolKind ( symbol ) : "" ;
3118
-
3119
- if ( ! tryAddConstructSignature ( symbol , location , symbolKind , symbolName , containerName , result ) &&
3120
- ! tryAddCallSignature ( symbol , location , symbolKind , symbolName , containerName , result ) ) {
3121
- // Just add all the declarations.
3122
- forEach ( declarations , declaration => {
3123
- result . push ( getDefinitionInfo ( declaration , symbolKind , symbolName , containerName ) ) ;
3124
- } ) ;
3125
- }
3126
- }
3127
- }
3128
-
3129
3114
synchronizeHostData ( ) ;
3130
3115
3131
3116
filename = TypeScript . switchToForwardSlashes ( filename ) ;
@@ -3173,7 +3158,7 @@ module ts {
3173
3158
3174
3159
var declarations = symbol . getDeclarations ( ) ;
3175
3160
var symbolName = typeInfoResolver . symbolToString ( symbol ) ; // Do not get scoped name, just the name of the symbol
3176
- var symbolKind = getSymbolKind ( symbol ) ;
3161
+ var symbolKind = getSymbolKind ( symbol , getMeaningFromLocation ( node ) ) ;
3177
3162
var containerSymbol = symbol . parent ;
3178
3163
var containerName = containerSymbol ? typeInfoResolver . symbolToString ( containerSymbol , node ) : "" ;
3179
3164
@@ -4703,7 +4688,6 @@ module ts {
4703
4688
function classifySymbol ( symbol : Symbol , meaningAtPosition : SemanticMeaning ) {
4704
4689
var flags = symbol . getFlags ( ) ;
4705
4690
4706
- // TODO(drosen): use meaningAtPosition.
4707
4691
if ( flags & SymbolFlags . Class ) {
4708
4692
return ClassificationTypeNames . className ;
4709
4693
}
@@ -4721,8 +4705,6 @@ module ts {
4721
4705
else if ( flags & SymbolFlags . Module ) {
4722
4706
return ClassificationTypeNames . moduleName ;
4723
4707
}
4724
-
4725
- return undefined ;
4726
4708
}
4727
4709
4728
4710
function processNode ( node : Node ) {
@@ -5192,7 +5174,7 @@ module ts {
5192
5174
5193
5175
// Only allow a symbol to be renamed if it actually has at least one declaration.
5194
5176
if ( symbol && symbol . getDeclarations ( ) && symbol . getDeclarations ( ) . length > 0 ) {
5195
- var kind = getSymbolKind ( symbol ) ;
5177
+ var kind = getSymbolKind ( symbol , getMeaningFromLocation ( node ) ) ;
5196
5178
if ( kind ) {
5197
5179
return getRenameInfo ( symbol . name , typeInfoResolver . getFullyQualifiedName ( symbol ) , kind ,
5198
5180
getSymbolModifiers ( symbol ) ,
0 commit comments