@@ -2259,9 +2259,13 @@ module ts {
22592259 return undefined ;
22602260 }
22612261
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.
22622266 return {
22632267 name : displayName ,
2264- kind : getSymbolKind ( symbol ) ,
2268+ kind : getSymbolKind ( symbol , SemanticMeaning . All ) ,
22652269 kindModifiers : getSymbolModifiers ( symbol )
22662270 } ;
22672271 }
@@ -2613,7 +2617,7 @@ module ts {
26132617 // which is permissible given that it is backwards compatible; but really we should consider
26142618 // passing the meaning for the node so that we don't report that a suggestion for a value is an interface.
26152619 // 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 ) ;
26172621 return {
26182622 name : entryName ,
26192623 kind : displayPartsDocumentationsAndSymbolKind . symbolKind ,
@@ -2656,15 +2660,19 @@ module ts {
26562660 }
26572661 }
26582662
2659- // TODO(drosen): use contextual SemanticMeaning.
2660- function getSymbolKind ( symbol : Symbol ) : string {
2663+ function getSymbolKind ( symbol : Symbol , meaningAtLocation : SemanticMeaning ) : string {
26612664 var flags = typeInfoResolver . getRootSymbols ( symbol ) [ 0 ] . getFlags ( ) ;
26622665
26632666 if ( flags & SymbolFlags . Class ) return ScriptElementKind . classElement ;
26642667 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+
26682676 var result = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar ( symbol , flags ) ;
26692677 if ( result === ScriptElementKind . unknown ) {
26702678 if ( flags & SymbolFlags . TypeParameter ) return ScriptElementKind . typeParameterElement ;
@@ -2737,15 +2745,13 @@ module ts {
27372745 : ScriptElementKindModifier . none ;
27382746 }
27392747
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 ) ) {
27462752 var displayParts : SymbolDisplayPart [ ] = [ ] ;
27472753 var documentation : SymbolDisplayPart [ ] ;
2748- var symbolFlags = typeResolver . getRootSymbol ( symbol ) . flags ;
2754+ var symbolFlags = typeResolver . getRootSymbols ( symbol ) [ 0 ] . flags ;
27492755 var symbolKind = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar ( symbol , symbolFlags ) ;
27502756 var hasAddedSymbolInfo : boolean ;
27512757 // Class at constructor site need to be shown as constructor apart from property,method, vars
@@ -2847,14 +2853,13 @@ module ts {
28472853 }
28482854 }
28492855 }
2850-
28512856 if ( symbolFlags & SymbolFlags . Class && ! hasAddedSymbolInfo ) {
28522857 displayParts . push ( keywordPart ( SyntaxKind . ClassKeyword ) ) ;
28532858 displayParts . push ( spacePart ( ) ) ;
28542859 displayParts . push . apply ( displayParts , symbolToDisplayParts ( typeResolver , symbol , sourceFile , /*meaning*/ undefined , SymbolFormatFlags . WriteTypeParametersOrArguments ) ) ;
28552860 writeTypeParametersOfSymbol ( symbol , sourceFile ) ;
28562861 }
2857- if ( symbolFlags & SymbolFlags . Interface ) {
2862+ if ( ( symbolFlags & SymbolFlags . Interface ) && ( semanticMeaning & SemanticMeaning . Type ) ) {
28582863 addNewLineIfDisplayPartsExist ( ) ;
28592864 displayParts . push ( keywordPart ( SyntaxKind . InterfaceKeyword ) ) ;
28602865 displayParts . push ( spacePart ( ) ) ;
@@ -2873,7 +2878,7 @@ module ts {
28732878 displayParts . push ( spacePart ( ) ) ;
28742879 displayParts . push . apply ( displayParts , symbolToDisplayParts ( typeResolver , symbol , sourceFile ) ) ;
28752880 }
2876- if ( symbolFlags & SymbolFlags . TypeParameter ) {
2881+ if ( ( symbolFlags & SymbolFlags . TypeParameter ) && ( semanticMeaning & SemanticMeaning . Type ) ) {
28772882 addNewLineIfDisplayPartsExist ( ) ;
28782883 displayParts . push ( punctuationPart ( SyntaxKind . OpenParenToken ) ) ;
28792884 displayParts . push ( textPart ( "type parameter" ) ) ;
@@ -2953,7 +2958,7 @@ module ts {
29532958 }
29542959 }
29552960 else {
2956- symbolKind = getSymbolKind ( symbol ) ;
2961+ symbolKind = getSymbolKind ( symbol , semanticMeaning ) ;
29572962 }
29582963 }
29592964
@@ -3015,7 +3020,6 @@ module ts {
30153020
30163021 var symbol = typeInfoResolver . getSymbolInfo ( node ) ;
30173022 if ( ! symbol ) {
3018-
30193023 // Try getting just type at this position and show
30203024 switch ( node . kind ) {
30213025 case SyntaxKind . Identifier :
@@ -3107,25 +3111,6 @@ module ts {
31073111 return false ;
31083112 }
31093113
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-
31293114 synchronizeHostData ( ) ;
31303115
31313116 filename = TypeScript . switchToForwardSlashes ( filename ) ;
@@ -3173,7 +3158,7 @@ module ts {
31733158
31743159 var declarations = symbol . getDeclarations ( ) ;
31753160 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 ) ) ;
31773162 var containerSymbol = symbol . parent ;
31783163 var containerName = containerSymbol ? typeInfoResolver . symbolToString ( containerSymbol , node ) : "" ;
31793164
@@ -4703,7 +4688,6 @@ module ts {
47034688 function classifySymbol ( symbol : Symbol , meaningAtPosition : SemanticMeaning ) {
47044689 var flags = symbol . getFlags ( ) ;
47054690
4706- // TODO(drosen): use meaningAtPosition.
47074691 if ( flags & SymbolFlags . Class ) {
47084692 return ClassificationTypeNames . className ;
47094693 }
@@ -4721,8 +4705,6 @@ module ts {
47214705 else if ( flags & SymbolFlags . Module ) {
47224706 return ClassificationTypeNames . moduleName ;
47234707 }
4724-
4725- return undefined ;
47264708 }
47274709
47284710 function processNode ( node : Node ) {
@@ -5192,7 +5174,7 @@ module ts {
51925174
51935175 // Only allow a symbol to be renamed if it actually has at least one declaration.
51945176 if ( symbol && symbol . getDeclarations ( ) && symbol . getDeclarations ( ) . length > 0 ) {
5195- var kind = getSymbolKind ( symbol ) ;
5177+ var kind = getSymbolKind ( symbol , getMeaningFromLocation ( node ) ) ;
51965178 if ( kind ) {
51975179 return getRenameInfo ( symbol . name , typeInfoResolver . getFullyQualifiedName ( symbol ) , kind ,
51985180 getSymbolModifiers ( symbol ) ,
0 commit comments