@@ -2378,7 +2378,7 @@ module ts {
2378
2378
return undefined ;
2379
2379
}
2380
2380
2381
- function createCompletionEntry ( symbol : Symbol , typeChecker : TypeChecker ) : CompletionEntry {
2381
+ function createCompletionEntry ( symbol : Symbol , typeChecker : TypeChecker , location : Node ) : CompletionEntry {
2382
2382
// Try to get a valid display name for this symbol, if we could not find one, then ignore it.
2383
2383
// We would like to only show things that can be added after a dot, so for instance numeric properties can
2384
2384
// not be accessed with a dot (a.1 <- invalid)
@@ -2393,7 +2393,7 @@ module ts {
2393
2393
// We COULD also just do what 'getSymbolModifiers' does, which is to use the first declaration.
2394
2394
return {
2395
2395
name : displayName ,
2396
- kind : getSymbolKind ( symbol , typeChecker ) ,
2396
+ kind : getSymbolKind ( symbol , typeChecker , location ) ,
2397
2397
kindModifiers : getSymbolModifiers ( symbol )
2398
2398
} ;
2399
2399
}
@@ -2464,6 +2464,7 @@ module ts {
2464
2464
} ;
2465
2465
host . log ( "getCompletionsAtPosition: Syntactic work: " + ( new Date ( ) . getTime ( ) - syntacticStart ) ) ;
2466
2466
2467
+ var location = getTouchingPropertyName ( sourceFile , position ) ;
2467
2468
// Populate the completion list
2468
2469
var semanticStart = new Date ( ) . getTime ( ) ;
2469
2470
if ( isRightOfDot ) {
@@ -2545,7 +2546,7 @@ module ts {
2545
2546
function getCompletionEntriesFromSymbols ( symbols : Symbol [ ] , session : CompletionSession ) : void {
2546
2547
var start = new Date ( ) . getTime ( ) ;
2547
2548
forEach ( symbols , symbol => {
2548
- var entry = createCompletionEntry ( symbol , session . typeChecker ) ;
2549
+ var entry = createCompletionEntry ( symbol , session . typeChecker , location ) ;
2549
2550
if ( entry && ! lookUp ( session . symbols , entry . name ) ) {
2550
2551
session . entries . push ( entry ) ;
2551
2552
session . symbols [ entry . name ] = symbol ;
@@ -2757,14 +2758,13 @@ module ts {
2757
2758
2758
2759
var symbol = lookUp ( activeCompletionSession . symbols , entryName ) ;
2759
2760
if ( symbol ) {
2760
- var type = session . typeChecker . getTypeOfSymbol ( symbol ) ;
2761
- Debug . assert ( type !== undefined , "Could not find type for symbol" ) ;
2762
- var completionEntry = createCompletionEntry ( symbol , session . typeChecker ) ;
2761
+ var location = getTouchingPropertyName ( sourceFile , position ) ;
2762
+ var completionEntry = createCompletionEntry ( symbol , session . typeChecker , location ) ;
2763
2763
// TODO(drosen): Right now we just permit *all* semantic meanings when calling 'getSymbolKind'
2764
2764
// which is permissible given that it is backwards compatible; but really we should consider
2765
2765
// passing the meaning for the node so that we don't report that a suggestion for a value is an interface.
2766
2766
// We COULD also just do what 'getSymbolModifiers' does, which is to use the first declaration.
2767
- var location = getTouchingPropertyName ( sourceFile , position ) ;
2767
+ Debug . assert ( session . typeChecker . getNarrowedTypeOfSymbol ( symbol , location ) !== undefined , "Could not find type for symbol" ) ;
2768
2768
var displayPartsDocumentationsAndSymbolKind = getSymbolDisplayPartsDocumentationAndSymbolKind ( symbol , getSourceFile ( filename ) , location , session . typeChecker , location , SemanticMeaning . All ) ;
2769
2769
return {
2770
2770
name : entryName ,
@@ -2809,7 +2809,7 @@ module ts {
2809
2809
}
2810
2810
2811
2811
// TODO(drosen): use contextual SemanticMeaning.
2812
- function getSymbolKind ( symbol : Symbol , typeResolver : TypeChecker ) : string {
2812
+ function getSymbolKind ( symbol : Symbol , typeResolver : TypeChecker , location ?: Node ) : string {
2813
2813
var flags = symbol . getFlags ( ) ;
2814
2814
2815
2815
if ( flags & SymbolFlags . Class ) return ScriptElementKind . classElement ;
@@ -2818,7 +2818,7 @@ module ts {
2818
2818
if ( flags & SymbolFlags . Interface ) return ScriptElementKind . interfaceElement ;
2819
2819
if ( flags & SymbolFlags . TypeParameter ) return ScriptElementKind . typeParameterElement ;
2820
2820
2821
- var result = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar ( symbol , flags , typeResolver ) ;
2821
+ var result = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar ( symbol , flags , typeResolver , location ) ;
2822
2822
if ( result === ScriptElementKind . unknown ) {
2823
2823
if ( flags & SymbolFlags . TypeParameter ) return ScriptElementKind . typeParameterElement ;
2824
2824
if ( flags & SymbolFlags . EnumMember ) return ScriptElementKind . variableElement ;
@@ -2828,7 +2828,7 @@ module ts {
2828
2828
return result ;
2829
2829
}
2830
2830
2831
- function getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar ( symbol : Symbol , flags : SymbolFlags , typeResolver : TypeChecker ) {
2831
+ function getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar ( symbol : Symbol , flags : SymbolFlags , typeResolver : TypeChecker , location : Node ) {
2832
2832
if ( typeResolver . isUndefinedSymbol ( symbol ) ) {
2833
2833
return ScriptElementKind . variableElement ;
2834
2834
}
@@ -2852,15 +2852,24 @@ module ts {
2852
2852
2853
2853
if ( flags & SymbolFlags . Property ) {
2854
2854
if ( flags & SymbolFlags . UnionProperty ) {
2855
- return forEach ( typeInfoResolver . getRootSymbols ( symbol ) , rootSymbol => {
2855
+ // If union property is result of union of non method (property/accessors), it is labeled as property
2856
+ var unionPropertyKind = forEach ( typeInfoResolver . getRootSymbols ( symbol ) , rootSymbol => {
2856
2857
var rootSymbolFlags = rootSymbol . getFlags ( ) ;
2857
- if ( rootSymbolFlags & SymbolFlags . Property ) {
2858
+ if ( rootSymbolFlags & ( SymbolFlags . Property | SymbolFlags . GetAccessor | SymbolFlags . SetAccessor ) ) {
2858
2859
return ScriptElementKind . memberVariableElement ;
2859
2860
}
2860
- if ( rootSymbolFlags & SymbolFlags . GetAccessor ) return ScriptElementKind . memberVariableElement ;
2861
- if ( rootSymbolFlags & SymbolFlags . SetAccessor ) return ScriptElementKind . memberVariableElement ;
2862
- Debug . assert ( ( rootSymbolFlags & SymbolFlags . Method ) !== undefined ) ;
2863
- } ) || ScriptElementKind . memberFunctionElement ;
2861
+ Debug . assert ( ! ! ( rootSymbolFlags & SymbolFlags . Method ) ) ;
2862
+ } ) ;
2863
+ if ( ! unionPropertyKind ) {
2864
+ // If this was union of all methods,
2865
+ //make sure it has call signatures before we can label it as method
2866
+ var typeOfUnionProperty = typeInfoResolver . getNarrowedTypeOfSymbol ( symbol , location ) ;
2867
+ if ( typeOfUnionProperty . getCallSignatures ( ) . length ) {
2868
+ return ScriptElementKind . memberFunctionElement ;
2869
+ }
2870
+ return ScriptElementKind . memberVariableElement ;
2871
+ }
2872
+ return unionPropertyKind ;
2864
2873
}
2865
2874
return ScriptElementKind . memberVariableElement ;
2866
2875
}
@@ -2918,7 +2927,7 @@ module ts {
2918
2927
var displayParts : SymbolDisplayPart [ ] = [ ] ;
2919
2928
var documentation : SymbolDisplayPart [ ] ;
2920
2929
var symbolFlags = symbol . flags ;
2921
- var symbolKind = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar ( symbol , symbolFlags , typeResolver ) ;
2930
+ var symbolKind = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar ( symbol , symbolFlags , typeResolver , location ) ;
2922
2931
var hasAddedSymbolInfo : boolean ;
2923
2932
// Class at constructor site need to be shown as constructor apart from property,method, vars
2924
2933
if ( symbolKind !== ScriptElementKind . unknown || symbolFlags & SymbolFlags . Class || symbolFlags & SymbolFlags . Import ) {
@@ -2927,7 +2936,7 @@ module ts {
2927
2936
symbolKind = ScriptElementKind . memberVariableElement ;
2928
2937
}
2929
2938
2930
- var type = typeResolver . getTypeOfSymbol ( symbol ) ;
2939
+ var type = typeResolver . getNarrowedTypeOfSymbol ( symbol , location ) ;
2931
2940
if ( type ) {
2932
2941
if ( location . parent && location . parent . kind === SyntaxKind . PropertyAccess ) {
2933
2942
var right = ( < PropertyAccess > location . parent ) . right ;
@@ -3173,7 +3182,7 @@ module ts {
3173
3182
}
3174
3183
}
3175
3184
else {
3176
- symbolKind = getSymbolKind ( symbol , typeResolver ) ;
3185
+ symbolKind = getSymbolKind ( symbol , typeResolver , location ) ;
3177
3186
}
3178
3187
}
3179
3188
0 commit comments