@@ -921,6 +921,9 @@ namespace ts.Completions {
921
921
case SyntaxKind . QualifiedName :
922
922
node = ( parent as QualifiedName ) . left ;
923
923
break ;
924
+ case SyntaxKind . ModuleDeclaration :
925
+ node = ( parent as ModuleDeclaration ) . name ;
926
+ break ;
924
927
case SyntaxKind . ImportType :
925
928
case SyntaxKind . MetaProperty :
926
929
node = parent ;
@@ -1062,6 +1065,8 @@ namespace ts.Completions {
1062
1065
const isRhsOfImportDeclaration = isInRightSideOfInternalImportEqualsDeclaration ( node ) ;
1063
1066
const allowTypeOrValue = isRhsOfImportDeclaration || ( ! isTypeLocation && isPossiblyTypeArgumentPosition ( contextToken , sourceFile , typeChecker ) ) ;
1064
1067
if ( isEntityName ( node ) || isImportType ) {
1068
+ const isNamespaceName = isModuleDeclaration ( node . parent ) ;
1069
+ if ( isNamespaceName ) isNewIdentifierLocation = true ;
1065
1070
let symbol = typeChecker . getSymbolAtLocation ( node ) ;
1066
1071
if ( symbol ) {
1067
1072
symbol = skipAlias ( symbol , typeChecker ) ;
@@ -1071,13 +1076,17 @@ namespace ts.Completions {
1071
1076
const exportedSymbols = Debug . assertEachDefined ( typeChecker . getExportsOfModule ( symbol ) , "getExportsOfModule() should all be defined" ) ;
1072
1077
const isValidValueAccess = ( symbol : Symbol ) => typeChecker . isValidPropertyAccess ( isImportType ? < ImportTypeNode > node : < PropertyAccessExpression > ( node . parent ) , symbol . name ) ;
1073
1078
const isValidTypeAccess = ( symbol : Symbol ) => symbolCanBeReferencedAtTypeLocation ( symbol ) ;
1074
- const isValidAccess = allowTypeOrValue ?
1075
- // Any kind is allowed when dotting off namespace in internal import equals declaration
1076
- ( symbol : Symbol ) => isValidTypeAccess ( symbol ) || isValidValueAccess ( symbol ) :
1077
- isTypeLocation ? isValidTypeAccess : isValidValueAccess ;
1078
- for ( const symbol of exportedSymbols ) {
1079
- if ( isValidAccess ( symbol ) ) {
1080
- symbols . push ( symbol ) ;
1079
+ const isValidAccess : ( symbol : Symbol ) => boolean =
1080
+ isNamespaceName
1081
+ // At `namespace N.M/**/`, if this is the only declaration of `M`, don't include `M` as a completion.
1082
+ ? symbol => ! ! ( symbol . flags & SymbolFlags . Namespace ) && ! symbol . declarations . every ( d => d . parent === node . parent )
1083
+ : allowTypeOrValue ?
1084
+ // Any kind is allowed when dotting off namespace in internal import equals declaration
1085
+ symbol => isValidTypeAccess ( symbol ) || isValidValueAccess ( symbol ) :
1086
+ isTypeLocation ? isValidTypeAccess : isValidValueAccess ;
1087
+ for ( const exportedSymbol of exportedSymbols ) {
1088
+ if ( isValidAccess ( exportedSymbol ) ) {
1089
+ symbols . push ( exportedSymbol ) ;
1081
1090
}
1082
1091
}
1083
1092
@@ -1461,7 +1470,8 @@ namespace ts.Completions {
1461
1470
function isNewIdentifierDefinitionLocation ( previousToken : Node | undefined ) : boolean {
1462
1471
if ( previousToken ) {
1463
1472
const containingNodeKind = previousToken . parent . kind ;
1464
- switch ( previousToken . kind ) {
1473
+ // Previous token may have been a keyword that was converted to an identifier.
1474
+ switch ( keywordForNode ( previousToken ) ) {
1465
1475
case SyntaxKind . CommaToken :
1466
1476
return containingNodeKind === SyntaxKind . CallExpression // func( a, |
1467
1477
|| containingNodeKind === SyntaxKind . Constructor // constructor( a, | /* public, protected, private keywords are allowed here, so show completion */
@@ -1507,14 +1517,6 @@ namespace ts.Completions {
1507
1517
case SyntaxKind . ProtectedKeyword :
1508
1518
return containingNodeKind === SyntaxKind . PropertyDeclaration ; // class A{ public |
1509
1519
}
1510
-
1511
- // Previous token may have been a keyword that was converted to an identifier.
1512
- switch ( keywordForNode ( previousToken ) ) {
1513
- case SyntaxKind . PublicKeyword :
1514
- case SyntaxKind . ProtectedKeyword :
1515
- case SyntaxKind . PrivateKeyword :
1516
- return true ;
1517
- }
1518
1520
}
1519
1521
1520
1522
return false ;
0 commit comments