23
23
////class F extends B {
24
24
//// public /*classThatHasWrittenPublicKeyword*/
25
25
//// }
26
+ ////class F2 extends B {
27
+ //// private /*classThatHasWrittenPrivateKeyword*/
28
+ //// }
26
29
////class G extends B {
27
30
//// static /*classElementContainingStatic*/
28
31
//// }
32
+ ////class G2 extends B {
33
+ //// private static /*classElementContainingPrivateStatic*/
34
+ //// }
29
35
////class H extends B {
30
36
//// prop/*classThatStartedWritingIdentifier*/
31
37
//// }
38
+ //////Class for location verification
32
39
////class I extends B {
33
40
//// prop0: number
34
41
//// /*propDeclarationWithoutSemicolon*/
68
75
////class L extends B {
69
76
//// public identi/*classThatStartedWritingIdentifierAfterModifier*/
70
77
//// }
71
- ////class L extends B {
78
+ ////class L2 extends B {
79
+ //// private identi/*classThatStartedWritingIdentifierAfterPrivateModifier*/
80
+ //// }
81
+ ////class M extends B {
72
82
//// static identi/*classThatStartedWritingIdentifierAfterStaticModifier*/
73
83
//// }
84
+ ////class M extends B {
85
+ //// private static identi/*classThatStartedWritingIdentifierAfterPrivateStaticModifier*/
86
+ //// }
74
87
75
88
const allowedKeywordCount = verify . allowedClassElementKeywords . length ;
89
+ type CompletionInfo = [ string , string ] ;
90
+ type CompletionInfoVerifier = { validMembers : CompletionInfo [ ] , invalidMembers : CompletionInfo [ ] } ;
91
+
92
+ function verifyClassElementLocations ( { validMembers, invalidMembers } : CompletionInfoVerifier , classElementCompletionLocations : string [ ] ) {
93
+ for ( const marker of classElementCompletionLocations ) {
94
+ goTo . marker ( marker ) ;
95
+ verifyCompletionInfo ( validMembers , verify ) ;
96
+ verifyCompletionInfo ( invalidMembers , verify . not ) ;
97
+ verify . completionListContainsClassElementKeywords ( ) ;
98
+ verify . completionListCount ( allowedKeywordCount + validMembers . length ) ;
99
+ }
100
+ }
101
+
102
+ function verifyCompletionInfo ( memberInfo : CompletionInfo [ ] , verify : FourSlashInterface . verifyNegatable ) {
103
+ for ( const [ symbol , text ] of memberInfo ) {
104
+ verify . completionListContains ( symbol , text , /*documentation*/ undefined , "method" ) ;
105
+ }
106
+ }
107
+
108
+ const allMembersOfBase : CompletionInfo [ ] = [
109
+ [ "getValue" , "(method) B.getValue(): number" ] ,
110
+ [ "protectedMethod" , "(method) B.protectedMethod(): void" ] ,
111
+ [ "privateMethod" , "(method) B.privateMethod(): void" ] ,
112
+ [ "staticMethod" , "(method) B.staticMethod(): void" ]
113
+ ] ;
114
+ function filterCompletionInfo ( fn : ( a : CompletionInfo ) => boolean ) : CompletionInfoVerifier {
115
+ const validMembers : CompletionInfo [ ] = [ ] ;
116
+ const invalidMembers : CompletionInfo [ ] = [ ] ;
117
+ for ( const member of allMembersOfBase ) {
118
+ if ( fn ( member ) ) {
119
+ validMembers . push ( member ) ;
120
+ }
121
+ else {
122
+ invalidMembers . push ( member ) ;
123
+ }
124
+ }
125
+ return { validMembers, invalidMembers } ;
126
+ }
127
+
128
+
129
+ const instanceMemberInfo = filterCompletionInfo ( ( [ a ] : CompletionInfo ) => a === "getValue" || a === "protectedMethod" ) ;
130
+ const staticMemberInfo = filterCompletionInfo ( ( [ a ] : CompletionInfo ) => a === "staticMethod" ) ;
131
+
132
+ // Not a class element declaration location
76
133
const nonClassElementMarkers = [
77
134
"InsideMethod"
78
135
] ;
79
136
for ( const marker of nonClassElementMarkers ) {
80
137
goTo . marker ( marker ) ;
81
- verify . not . completionListContains ( "getValue" ) ;
138
+ verifyCompletionInfo ( allMembersOfBase , verify . not ) ;
82
139
verify . not . completionListIsEmpty ( ) ;
83
140
}
84
141
85
- // Only keywords allowed at this position since they dont extend the class
142
+ // Only keywords allowed at this position since they dont extend the class or are private
86
143
const onlyClassElementKeywordLocations = [
87
144
"abstractClass" ,
88
- "classThatDoesNotExtendAnotherClass"
145
+ "classThatDoesNotExtendAnotherClass" ,
146
+ "classThatHasWrittenPrivateKeyword" ,
147
+ "classElementContainingPrivateStatic" ,
148
+ "classThatStartedWritingIdentifierAfterPrivateModifier" ,
149
+ "classThatStartedWritingIdentifierAfterPrivateStaticModifier"
89
150
] ;
90
- for ( const marker of onlyClassElementKeywordLocations ) {
91
- goTo . marker ( marker ) ;
92
- verify . completionListContainsClassElementKeywords ( ) ;
93
- verify . completionListCount ( allowedKeywordCount ) ;
94
- }
151
+ verifyClassElementLocations ( { validMembers : [ ] , invalidMembers : allMembersOfBase } , onlyClassElementKeywordLocations ) ;
95
152
96
- // Base members and class member keywords allowed
97
- const classElementCompletionLocations = [
153
+ // Instance base members and class member keywords allowed
154
+ const classInstanceElementLocations = [
98
155
"classThatIsEmptyAndExtendingAnotherClass" ,
99
156
"classThatHasAlreadyImplementedAnotherClassMethod" ,
100
157
"classThatHasAlreadyImplementedAnotherClassMethodAfterMethod" ,
101
158
"classThatHasWrittenPublicKeyword" ,
102
- "classElementContainingStatic" ,
103
159
"classThatStartedWritingIdentifier" ,
104
160
"propDeclarationWithoutSemicolon" ,
105
161
"propDeclarationWithSemicolon" ,
@@ -115,25 +171,12 @@ const classElementCompletionLocations = [
115
171
"classThatStartedWritingIdentifierOfGetAccessor" ,
116
172
"classThatStartedWritingIdentifierOfSetAccessor" ,
117
173
"classThatStartedWritingIdentifierAfterModifier" ,
118
- "classThatStartedWritingIdentifierAfterStaticModifier"
119
174
] ;
175
+ verifyClassElementLocations ( instanceMemberInfo , classInstanceElementLocations ) ;
120
176
121
- const validMembersOfBase = [
122
- [ "getValue" , "(method) B.getValue(): number" ] ,
123
- [ "protectedMethod" , "(method) B.protectedMethod(): void" ]
124
- ] ;
125
- const invalidMembersOfBase = [
126
- [ "privateMethod" , "(method) B.privateMethod(): void" ] ,
127
- [ "staticMethod" , "(method) B.staticMethod(): void" ]
177
+ // Static Base members and class member keywords allowed
178
+ const staticClassLocations = [
179
+ "classElementContainingStatic" ,
180
+ "classThatStartedWritingIdentifierAfterStaticModifier"
128
181
] ;
129
- for ( const marker of classElementCompletionLocations ) {
130
- goTo . marker ( marker ) ;
131
- for ( const [ validMemberOfBaseSymbol , validMemberOfBaseText ] of validMembersOfBase ) {
132
- verify . completionListContains ( validMemberOfBaseSymbol , validMemberOfBaseText , /*documentation*/ undefined , "method" ) ;
133
- }
134
- for ( const [ invalidMemberOfBaseSymbol , invalidMemberOfBaseText ] of invalidMembersOfBase ) {
135
- verify . not . completionListContains ( invalidMemberOfBaseSymbol , invalidMemberOfBaseText , /*documentation*/ undefined , "method" ) ;
136
- }
137
- verify . completionListContainsClassElementKeywords ( ) ;
138
- verify . completionListCount ( allowedKeywordCount + validMembersOfBase . length ) ;
139
- }
182
+ verifyClassElementLocations ( staticMemberInfo , staticClassLocations ) ;
0 commit comments