@@ -1681,9 +1681,17 @@ module ts {
16811681 }
16821682
16831683 /// Completion
1684- function getValidCompletionEntryDisplayName ( displayName : string , target : ScriptTarget ) : string {
1684+ function getValidCompletionEntryDisplayName ( symbol : Symbol , target : ScriptTarget ) : string {
1685+ var displayName = symbol . getName ( ) ;
16851686 if ( displayName && displayName . length > 0 ) {
16861687 var firstCharCode = displayName . charCodeAt ( 0 ) ;
1688+ // First check of the displayName is not external module; if it is an external module, it is not valid entry
1689+ if ( ( symbol . flags & SymbolFlags . Namespace ) && ( firstCharCode === CharacterCodes . singleQuote || firstCharCode === CharacterCodes . doubleQuote ) ) {
1690+ // If the symbol is external module, don't show it in the completion list
1691+ // (i.e declare module "http" { var x; } | // <= request completion here, "http" should not be there)
1692+ return undefined ;
1693+ }
1694+
16871695 if ( displayName && displayName . length >= 2 && firstCharCode === displayName . charCodeAt ( displayName . length - 1 ) &&
16881696 ( firstCharCode === CharacterCodes . singleQuote || firstCharCode === CharacterCodes . doubleQuote ) ) {
16891697 // If the user entered name for the symbol was quoted, removing the quotes is not enough, as the name could be an
@@ -1696,6 +1704,7 @@ module ts {
16961704 isValid = isIdentifierPart ( displayName . charCodeAt ( i ) , target ) ;
16971705 }
16981706
1707+
16991708 if ( isValid ) {
17001709 return displayName ;
17011710 }
@@ -1708,14 +1717,7 @@ module ts {
17081717 // Try to get a valid display name for this symbol, if we could not find one, then ignore it.
17091718 // We would like to only show things that can be added after a dot, so for instance numeric properties can
17101719 // not be accessed with a dot (a.1 <- invalid)
1711- var firstCharCode = symbol . name . charCodeAt ( 0 ) ;
1712- if ( ( symbol . flags & SymbolFlags . Namespace ) && ( firstCharCode === CharacterCodes . singleQuote || firstCharCode === CharacterCodes . doubleQuote ) ) {
1713- // If the symbol is external module, don't show it in the completion list
1714- // (i.e declare module "http" { var x; } | // <= request completion here, "http" should not be there)
1715- return undefined ;
1716- }
1717-
1718- var displayName = getValidCompletionEntryDisplayName ( symbol . getName ( ) , program . getCompilerOptions ( ) . target ) ;
1720+ var displayName = getValidCompletionEntryDisplayName ( symbol , program . getCompilerOptions ( ) . target ) ;
17191721 if ( ! displayName ) {
17201722 return undefined ;
17211723 }
0 commit comments