1
+ /// <reference path='fourslash.ts'/>
2
+
3
+ ////class /*1*/c</*2*/T> {
4
+ //// /*3*/constructor(/*4*/a: /*5*/T) {
5
+ //// }
6
+ //// /*6*/method</*7*/U>(/*8*/a: /*9*/U, /*10*/b: /*11*/T) {
7
+ //// return /*12*/a;
8
+ //// }
9
+ //// }
10
+ ////var /*13*/cInstance = new /*14*/c("Hello");
11
+ ////var /*15*/cVal = /*16*/c;
12
+ /////*17*/cInstance./*18*/method("hello", "cello");
13
+ ////class /*19*/c2</*20*/T extends /*21*/c<string>> {
14
+ //// /*22*/constructor(/*23*/a: /*24*/T) {
15
+ //// }
16
+ //// /*25*/method</*26*/U extends /*27*/c<string>>(/*28*/a: /*29*/U, /*30*/b: /*31*/T) {
17
+ //// return /*32*/a;
18
+ //// }
19
+ //// }
20
+ ////var /*33*/cInstance1 = new /*34*/c2(/*35*/cInstance);
21
+ ////var /*36*/cVal2 = /*37*/c2;
22
+ /////*38*/cInstance1./*39*/method(/*40*/cInstance, /*41*/cInstance);
23
+
24
+ var marker = 0 ;
25
+ var markerName : string ;
26
+
27
+ function goToMarker ( ) {
28
+ marker ++ ;
29
+ markerName = marker . toString ( ) ;
30
+ goTo . marker ( markerName ) ;
31
+ }
32
+
33
+ function getTypeParameterDisplay ( instanceType : ts . SymbolDisplayPart [ ] ,
34
+ name : string , optionalExtends ?: ts . SymbolDisplayPart [ ] ) {
35
+ return instanceType ||
36
+ function ( ) {
37
+ var typeParameterDisplay = [ { text : name , kind : "typeParameterName" } ] ;
38
+ if ( optionalExtends ) {
39
+ typeParameterDisplay . push ( { text : " " , kind : "space" } , { text : "extends" , kind : "keyword" } ,
40
+ { text : " " , kind : "space" } ) ;
41
+ typeParameterDisplay = typeParameterDisplay . concat ( optionalExtends ) ;
42
+ }
43
+ return typeParameterDisplay
44
+ } ( ) ;
45
+ }
46
+
47
+ function getClassDisplay ( name : string , optionalInstanceType ?: ts . SymbolDisplayPart [ ] ,
48
+ optionalExtends ?: ts . SymbolDisplayPart [ ] ) {
49
+ var classDisplay = [ { text : name , kind : "className" } , { text : "<" , kind : "punctuation" } ] ;
50
+ classDisplay = classDisplay . concat ( getTypeParameterDisplay ( optionalInstanceType , "T" , optionalExtends ) ) ;
51
+ classDisplay . push ( { text : ">" , kind : "punctuation" } ) ;
52
+ return classDisplay ;
53
+ }
54
+
55
+ function verifyClassDisplay ( name : string , optionalExtends ?: ts . SymbolDisplayPart [ ] ) {
56
+ goToMarker ( ) ;
57
+
58
+ verify . verifyQuickInfoDisplayParts ( "class" , "" , { start : test . markerByName ( markerName ) . position , length : name . length } ,
59
+ [ { text : "class" , kind : "keyword" } , { text : " " , kind : "space" } ] . concat (
60
+ getClassDisplay ( name , undefined , optionalExtends ) ) , [ ] ) ;
61
+ }
62
+
63
+ function verifyTypeParameter ( name : string , inDisplay : ts . SymbolDisplayPart [ ] ) {
64
+ goToMarker ( ) ;
65
+
66
+ var typeParameterDisplay = [ { text : "(" , kind : "punctuation" } , { text : "type parameter" , kind : "text" } , { text : ")" , kind : "punctuation" } ,
67
+ { text : " " , kind : "space" } , { text : name , kind : "typeParameterName" } ,
68
+ { text : " " , kind : "space" } , { text : "in" , kind : "keyword" } , { text : " " , kind : "space" } ] ;
69
+ typeParameterDisplay = typeParameterDisplay . concat ( inDisplay ) ;
70
+
71
+ verify . verifyQuickInfoDisplayParts ( "type parameter" , "" , { start : test . markerByName ( markerName ) . position , length : name . length } ,
72
+ typeParameterDisplay , [ ] ) ;
73
+ }
74
+
75
+ function verifyConstructor ( name : string , optionalInstanceType ?: ts . SymbolDisplayPart [ ] ,
76
+ optionalExtends ?: ts . SymbolDisplayPart [ ] ) {
77
+ goToMarker ( ) ;
78
+ var constructorDisplay = [ { text : "constructor" , kind : "keyword" } ,
79
+ { text : " " , kind : "space" } ] ;
80
+ constructorDisplay = constructorDisplay . concat ( getClassDisplay ( name , optionalInstanceType , optionalExtends ) ) ;
81
+
82
+ constructorDisplay . push ( { text : "(" , kind : "punctuation" } , { text : "a" , kind : "parameterName" } ,
83
+ { text : ":" , kind : "punctuation" } , { text : " " , kind : "space" } ) ;
84
+
85
+ constructorDisplay = constructorDisplay . concat (
86
+ getTypeParameterDisplay ( optionalInstanceType , "T" ) ) ;
87
+
88
+ constructorDisplay . push ( { text : ")" , kind : "punctuation" } ,
89
+ { text : ":" , kind : "punctuation" } , { text : " " , kind : "space" } ) ;
90
+
91
+ constructorDisplay = constructorDisplay . concat ( getClassDisplay ( name , optionalInstanceType ) ) ;
92
+
93
+ verify . verifyQuickInfoDisplayParts ( "constructor" , "" , { start : test . markerByName ( markerName ) . position , length : optionalInstanceType ? name . length : "constructor" . length } ,
94
+ constructorDisplay , [ ] ) ;
95
+ }
96
+
97
+ function verifyParameter ( name : string , type : string , optionalExtends ?: ts . SymbolDisplayPart [ ] ) {
98
+ goToMarker ( ) ;
99
+ var parameterDisplay = [ { text : "(" , kind : "punctuation" } , { text : "parameter" , kind : "text" } , { text : ")" , kind : "punctuation" } ,
100
+ { text : " " , kind : "space" } , { text : name , kind : "parameterName" } , { text : ":" , kind : "punctuation" } ,
101
+ { text : " " , kind : "space" } , { text : type , kind : "typeParameterName" } ] ;
102
+ if ( optionalExtends ) {
103
+ parameterDisplay . push ( { text : " " , kind : "space" } , { text : "extends" , kind : "keyword" } ,
104
+ { text : " " , kind : "space" } ) ;
105
+ parameterDisplay = parameterDisplay . concat ( optionalExtends ) ;
106
+ }
107
+ verify . verifyQuickInfoDisplayParts ( "parameter" , "" , { start : test . markerByName ( markerName ) . position , length : name . length } ,
108
+ parameterDisplay , [ ] ) ;
109
+ }
110
+
111
+ function getMethodDisplay ( name : string , className : string ,
112
+ optionalInstanceType ?: ts . SymbolDisplayPart [ ] , optionalExtends ?: ts . SymbolDisplayPart [ ] ) {
113
+ var functionDisplay = getClassDisplay ( className , optionalInstanceType , optionalExtends ) ;
114
+
115
+ functionDisplay . push ( { text : "." , kind : "punctuation" } , { text : name , kind : "methodName" } ,
116
+ { text : "<" , kind : "punctuation" } ) ;
117
+
118
+ functionDisplay = functionDisplay . concat (
119
+ getTypeParameterDisplay ( optionalInstanceType , "U" , optionalExtends ) ) ;
120
+
121
+ functionDisplay . push ( { text : ">" , kind : "punctuation" } , { text : "(" , kind : "punctuation" } ,
122
+ { text : "a" , kind : "parameterName" } , { text : ":" , kind : "punctuation" } ,
123
+ { text : " " , kind : "space" } ) ;
124
+ functionDisplay = functionDisplay . concat (
125
+ getTypeParameterDisplay ( optionalInstanceType , "U" ) ) ;
126
+ functionDisplay . push ( { text : "," , kind : "punctuation" } ,
127
+ { text : " " , kind : "space" } , { text : "b" , kind : "parameterName" } ,
128
+ { text : ":" , kind : "punctuation" } , { text : " " , kind : "space" } ) ;
129
+ functionDisplay = functionDisplay . concat (
130
+ getTypeParameterDisplay ( optionalInstanceType , "T" ) ) ;
131
+
132
+ functionDisplay . push ( { text : ")" , kind : "punctuation" } ,
133
+ { text : ":" , kind : "punctuation" } , { text : " " , kind : "space" } ) ;
134
+
135
+ functionDisplay = functionDisplay . concat (
136
+ getTypeParameterDisplay ( optionalInstanceType , "U" ) ) ;
137
+
138
+ return functionDisplay ;
139
+ }
140
+
141
+ function verifyMethodDisplay ( name : string , className : string ,
142
+ optionalInstanceType ?: ts . SymbolDisplayPart [ ] , optionalExtends ?: ts . SymbolDisplayPart [ ] ) {
143
+ goToMarker ( ) ;
144
+ var functionDisplay = [ { text : "(" , kind : "punctuation" } , { text : "method" , kind : "text" } ,
145
+ { text : ")" , kind : "punctuation" } , { text : " " , kind : "space" } ] . concat (
146
+ getMethodDisplay ( name , className , optionalInstanceType , optionalExtends ) ) ;
147
+
148
+ verify . verifyQuickInfoDisplayParts ( "method" , "" ,
149
+ { start : test . markerByName ( markerName ) . position , length : name . length } ,
150
+ functionDisplay , [ ] ) ;
151
+ }
152
+
153
+ function verifyClassInstance ( name : string , typeDisplay : ts . SymbolDisplayPart [ ] ) {
154
+ goToMarker ( ) ;
155
+ verify . verifyQuickInfoDisplayParts ( "var" , "" , { start : test . markerByName ( markerName ) . position , length : name . length } ,
156
+ [ { text : "var" , kind : "keyword" } ,
157
+ { text : " " , kind : "space" } , { text : name , kind : "localName" } , { text : ":" , kind : "punctuation" } ,
158
+ { text : " " , kind : "space" } ] . concat ( typeDisplay ) ,
159
+ [ ] ) ;
160
+ }
161
+
162
+ function verifyVarTypeOf ( name : string , typeOfSymbol : ts . SymbolDisplayPart ) {
163
+ goToMarker ( ) ;
164
+ verify . verifyQuickInfoDisplayParts ( "var" , "" , { start : test . markerByName ( markerName ) . position , length : name . length } ,
165
+ [ { text : "var" , kind : "keyword" } ,
166
+ { text : " " , kind : "space" } , { text : name , kind : "localName" } , { text : ":" , kind : "punctuation" } ,
167
+ { text : " " , kind : "space" } , { text : "typeof" , kind : "keyword" } ,
168
+ { text : " " , kind : "space" } ] . concat ( typeOfSymbol ) ,
169
+ [ ] ) ;
170
+ }
171
+
172
+ var stringTypeDisplay = [ { text : "string" , kind : "keyword" } ] ;
173
+ var extendsTypeDisplay = getClassDisplay ( "c" , stringTypeDisplay ) ;
174
+
175
+ // Declaration
176
+ verifyClassDisplay ( "c" ) ;
177
+ verifyTypeParameter ( "T" , getClassDisplay ( "c" ) ) ;
178
+
179
+ // Constructor declaration
180
+ verifyConstructor ( "c" ) ;
181
+ verifyParameter ( "a" , "T" ) ;
182
+ verifyTypeParameter ( "T" , getClassDisplay ( "c" ) ) ;
183
+
184
+ // Method declaration
185
+ verifyMethodDisplay ( "method" , "c" ) ;
186
+ verifyTypeParameter ( "U" , getMethodDisplay ( "method" , "c" ) ) ;
187
+ verifyParameter ( "a" , "U" ) ;
188
+ verifyTypeParameter ( "U" , getMethodDisplay ( "method" , "c" ) ) ;
189
+ verifyParameter ( "b" , "T" ) ;
190
+ verifyTypeParameter ( "T" , getClassDisplay ( "c" ) ) ;
191
+ verifyParameter ( "a" , "U" ) ;
192
+
193
+ // Instance creation
194
+ verifyClassInstance ( "cInstance" , getClassDisplay ( "c" , stringTypeDisplay ) ) ;
195
+ verifyConstructor ( "c" , stringTypeDisplay ) ;
196
+
197
+ // typeof assignment
198
+ verifyVarTypeOf ( "cVal" , { text : "c" , kind : "className" } ) ;
199
+ verifyClassDisplay ( "c" ) ;
200
+
201
+ // Method call
202
+ verifyClassInstance ( "cInstance" , getClassDisplay ( "c" , stringTypeDisplay ) ) ;
203
+ verifyMethodDisplay ( "method" , "c" , stringTypeDisplay ) ;
204
+
205
+ // With constraint
206
+ // Declaration
207
+ verifyClassDisplay ( "c2" , getClassDisplay ( "c" , stringTypeDisplay ) ) ;
208
+ verifyTypeParameter ( "T" , getClassDisplay ( "c2" , /*instanceType*/ undefined , extendsTypeDisplay ) ) ;
209
+ verifyClassDisplay ( "c" ) ;
210
+
211
+ // Constructor declaration
212
+ verifyConstructor ( "c2" , /*instanceType*/ undefined , extendsTypeDisplay ) ;
213
+ verifyParameter ( "a" , "T" , extendsTypeDisplay ) ;
214
+ verifyTypeParameter ( "T" , getClassDisplay ( "c2" , /*instanceType*/ undefined , extendsTypeDisplay ) ) ;
215
+
216
+ // Method declaration
217
+ verifyMethodDisplay ( "method" , "c2" , /*instance*/ undefined , extendsTypeDisplay ) ;
218
+ verifyTypeParameter ( "U" , getMethodDisplay ( "method" , "c2" , /*instance*/ undefined , extendsTypeDisplay ) ) ;
219
+ verifyClassDisplay ( "c" ) ;
220
+ verifyParameter ( "a" , "U" , extendsTypeDisplay ) ;
221
+ verifyTypeParameter ( "U" , getMethodDisplay ( "method" , "c2" , /*instance*/ undefined , extendsTypeDisplay ) ) ;
222
+ verifyParameter ( "b" , "T" , extendsTypeDisplay ) ;
223
+ verifyTypeParameter ( "T" , getClassDisplay ( "c2" , /*instanceType*/ undefined , extendsTypeDisplay ) ) ;
224
+ verifyParameter ( "a" , "U" , extendsTypeDisplay ) ;
225
+
226
+ // Instance creation
227
+ verifyClassInstance ( "cInstance1" , getClassDisplay ( "c2" , extendsTypeDisplay ) ) ;
228
+ verifyConstructor ( "c2" , extendsTypeDisplay ) ;
229
+ verifyClassInstance ( "cInstance" , getClassDisplay ( "c" , stringTypeDisplay ) ) ;
230
+
231
+ // typeof assignment
232
+ verifyVarTypeOf ( "cVal2" , { text : "c2" , kind : "className" } ) ;
233
+ verifyClassDisplay ( "c2" , getClassDisplay ( "c" , stringTypeDisplay ) ) ;
234
+
235
+ // Method call
236
+ verifyClassInstance ( "cInstance1" , getClassDisplay ( "c2" , extendsTypeDisplay ) ) ;
237
+ verifyMethodDisplay ( "method" , "c2" , extendsTypeDisplay ) ;
238
+ verifyClassInstance ( "cInstance" , getClassDisplay ( "c" , stringTypeDisplay ) ) ;
239
+ verifyClassInstance ( "cInstance" , getClassDisplay ( "c" , stringTypeDisplay ) ) ;
0 commit comments