@@ -1563,43 +1563,34 @@ namespace ts.Completions {
1563
1563
completionKind = CompletionKind . MemberLike ;
1564
1564
// Declaring new property/method/accessor
1565
1565
isNewIdentifierLocation = true ;
1566
- // Has keywords for class elements
1567
1566
keywordFilters = isClassLike ( decl ) ? KeywordCompletionFilters . ClassElementKeywords : KeywordCompletionFilters . InterfaceElementKeywords ;
1568
1567
1569
1568
// If you're in an interface you don't want to repeat things from super-interface. So just stop here.
1570
1569
if ( ! isClassLike ( decl ) ) return GlobalsSearch . Success ;
1571
1570
1572
- const baseTypeNode = getClassExtendsHeritageClauseElement ( decl ) ;
1573
- const implementsTypeNodes = getClassImplementsHeritageClauseElements ( decl ) ;
1574
- if ( ! baseTypeNode && ! implementsTypeNodes ) return GlobalsSearch . Success ;
1575
-
1576
1571
const classElement = contextToken . parent ;
1577
- const classElementModifierFlags = ( isClassElement ( classElement ) ? getModifierFlags ( classElement ) : ModifierFlags . None )
1578
- // If this context token is not something we are editing now, consider if this would lead to be modifier
1579
- | ( ! isCurrentlyEditingNode ( contextToken ) ? modifierToFlag ( keywordForNode ( contextToken ) ) : ModifierFlags . None ) ;
1580
-
1581
- // No member list for private methods
1582
- if ( classElementModifierFlags & ModifierFlags . Private ) return GlobalsSearch . Success ;
1583
-
1584
- let baseClassTypeToGetPropertiesFrom : Type | undefined ;
1585
- if ( baseTypeNode ) {
1586
- baseClassTypeToGetPropertiesFrom = typeChecker . getTypeAtLocation ( baseTypeNode ) ;
1587
- if ( classElementModifierFlags & ModifierFlags . Static ) {
1588
- // Use static class to get property symbols from
1589
- baseClassTypeToGetPropertiesFrom = typeChecker . getTypeOfSymbolAtLocation ( baseClassTypeToGetPropertiesFrom . symbol , decl ) ;
1572
+ let classElementModifierFlags = isClassElement ( classElement ) && getModifierFlags ( classElement ) ;
1573
+ // If this is context token is not something we are editing now, consider if this would lead to be modifier
1574
+ if ( contextToken . kind === SyntaxKind . Identifier && ! isCurrentlyEditingNode ( contextToken ) ) {
1575
+ switch ( contextToken . getText ( ) ) {
1576
+ case "private" :
1577
+ classElementModifierFlags = classElementModifierFlags | ModifierFlags . Private ;
1578
+ break ;
1579
+ case "static" :
1580
+ classElementModifierFlags = classElementModifierFlags | ModifierFlags . Static ;
1581
+ break ;
1590
1582
}
1591
1583
}
1592
1584
1593
- const implementedInterfaceTypePropertySymbols = ! implementsTypeNodes || ( classElementModifierFlags & ModifierFlags . Static )
1594
- ? emptyArray
1595
- : flatMap ( implementsTypeNodes , typeNode => typeChecker . getPropertiesOfType ( typeChecker . getTypeAtLocation ( typeNode ) ) ) ;
1596
-
1597
- // List of property symbols of base type that are not private and already implemented
1598
- symbols = filterClassMembersList (
1599
- baseClassTypeToGetPropertiesFrom ? typeChecker . getPropertiesOfType ( baseClassTypeToGetPropertiesFrom ) : emptyArray ,
1600
- implementedInterfaceTypePropertySymbols ,
1601
- decl . members ,
1602
- classElementModifierFlags ) ;
1585
+ // No member list for private methods
1586
+ if ( ! ( classElementModifierFlags & ModifierFlags . Private ) ) {
1587
+ // List of property symbols of base type that are not private and already implemented
1588
+ const baseSymbols = flatMap ( getAllSuperTypeNodes ( decl ) , baseTypeNode => {
1589
+ const type = typeChecker . getTypeAtLocation ( baseTypeNode ) ;
1590
+ return typeChecker . getPropertiesOfType ( classElementModifierFlags & ModifierFlags . Static ? typeChecker . getTypeOfSymbolAtLocation ( type . symbol , decl ) : type ) ;
1591
+ } ) ;
1592
+ symbols = filterClassMembersList ( baseSymbols , decl . members , classElementModifierFlags ) ;
1593
+ }
1603
1594
1604
1595
return GlobalsSearch . Success ;
1605
1596
}
@@ -1967,12 +1958,8 @@ namespace ts.Completions {
1967
1958
*
1968
1959
* @returns Symbols to be suggested in an class element depending on existing memebers and symbol flags
1969
1960
*/
1970
- function filterClassMembersList (
1971
- baseSymbols : ReadonlyArray < Symbol > ,
1972
- implementingTypeSymbols : ReadonlyArray < Symbol > ,
1973
- existingMembers : ReadonlyArray < ClassElement > ,
1974
- currentClassElementModifierFlags : ModifierFlags ) : Symbol [ ] {
1975
- const existingMemberNames = createUnderscoreEscapedMap < boolean > ( ) ;
1961
+ function filterClassMembersList ( baseSymbols : ReadonlyArray < Symbol > , existingMembers : ReadonlyArray < ClassElement > , currentClassElementModifierFlags : ModifierFlags ) : Symbol [ ] {
1962
+ const existingMemberNames = createUnderscoreEscapedMap < true > ( ) ;
1976
1963
for ( const m of existingMembers ) {
1977
1964
// Ignore omitted expressions for missing members
1978
1965
if ( m . kind !== SyntaxKind . PropertyDeclaration &&
@@ -1993,10 +1980,7 @@ namespace ts.Completions {
1993
1980
}
1994
1981
1995
1982
// do not filter it out if the static presence doesnt match
1996
- const mIsStatic = hasModifier ( m , ModifierFlags . Static ) ;
1997
- const currentElementIsStatic = ! ! ( currentClassElementModifierFlags & ModifierFlags . Static ) ;
1998
- if ( ( mIsStatic && ! currentElementIsStatic ) ||
1999
- ( ! mIsStatic && currentElementIsStatic ) ) {
1983
+ if ( hasModifier ( m , ModifierFlags . Static ) !== ! ! ( currentClassElementModifierFlags & ModifierFlags . Static ) ) {
2000
1984
continue ;
2001
1985
}
2002
1986
@@ -2006,24 +1990,10 @@ namespace ts.Completions {
2006
1990
}
2007
1991
}
2008
1992
2009
- const result : Symbol [ ] = [ ] ;
2010
- addPropertySymbols ( baseSymbols , ModifierFlags . Private ) ;
2011
- addPropertySymbols ( implementingTypeSymbols , ModifierFlags . NonPublicAccessibilityModifier ) ;
2012
- return result ;
2013
-
2014
- function addPropertySymbols ( properties : ReadonlyArray < Symbol > , inValidModifierFlags : ModifierFlags ) {
2015
- for ( const property of properties ) {
2016
- if ( isValidProperty ( property , inValidModifierFlags ) ) {
2017
- result . push ( property ) ;
2018
- }
2019
- }
2020
- }
2021
-
2022
- function isValidProperty ( propertySymbol : Symbol , inValidModifierFlags : ModifierFlags ) {
2023
- return ! existingMemberNames . get ( propertySymbol . escapedName ) &&
2024
- propertySymbol . getDeclarations ( ) &&
2025
- ! ( getDeclarationModifierFlagsFromSymbol ( propertySymbol ) & inValidModifierFlags ) ;
2026
- }
1993
+ return baseSymbols . filter ( propertySymbol =>
1994
+ ! existingMemberNames . has ( propertySymbol . escapedName ) &&
1995
+ ! ! propertySymbol . declarations &&
1996
+ ! ( getDeclarationModifierFlagsFromSymbol ( propertySymbol ) & ModifierFlags . Private ) ) ;
2027
1997
}
2028
1998
2029
1999
/**
0 commit comments