@@ -12,7 +12,7 @@ import {URI} from 'vscode-uri';
12
12
import { ProjectLanguageService , ProjectLanguageServiceParams } from '../../common/notifications' ;
13
13
import { NgccProgress , NgccProgressToken , NgccProgressType } from '../../common/progress' ;
14
14
15
- import { APP_COMPONENT , createConnection , FOO_TEMPLATE , initializeServer , openTextDocument } from './test_utils' ;
15
+ import { APP_COMPONENT , createConnection , FOO_COMPONENT , FOO_TEMPLATE , initializeServer , openTextDocument } from './test_utils' ;
16
16
17
17
describe ( 'Angular Ivy language server' , ( ) => {
18
18
jasmine . DEFAULT_TIMEOUT_INTERVAL = 10000 ; /* 10 seconds */
@@ -117,6 +117,148 @@ describe('Angular Ivy language server', () => {
117
117
value : 'declare (property) NgIf<boolean>.ngIf: boolean' ,
118
118
} ) ;
119
119
} ) ;
120
+
121
+ describe ( 'renaming' , ( ) => {
122
+ describe ( 'from template files' , ( ) => {
123
+ beforeEach ( async ( ) => {
124
+ openTextDocument ( client , FOO_TEMPLATE ) ;
125
+ const languageServiceEnabled = await waitForNgcc ( client ) ;
126
+ expect ( languageServiceEnabled ) . toBeTrue ( ) ;
127
+ } ) ;
128
+
129
+ it ( 'should handle prepare rename request for property read' , async ( ) => {
130
+ const response = await client . sendRequest ( lsp . PrepareRenameRequest . type , {
131
+ textDocument : {
132
+ uri : `file://${ FOO_TEMPLATE } ` ,
133
+ } ,
134
+ position : { line : 0 , character : 3 } ,
135
+ } ) as { range : lsp . Range , placeholder : string } ;
136
+ expect ( response . range ) . toEqual ( {
137
+ start : { line : 0 , character : 2 } ,
138
+ end : { line : 0 , character : 7 } ,
139
+ } ) ;
140
+ expect ( response . placeholder ) . toEqual ( 'title' ) ;
141
+ } ) ;
142
+
143
+ const expectedRenameInComponent = {
144
+ range : {
145
+ start : { line : 6 , character : 2 } ,
146
+ end : { line : 6 , character : 7 } ,
147
+ } ,
148
+ newText : 'subtitle' ,
149
+ } ;
150
+ const expectedRenameInTemplate = {
151
+ range : {
152
+ start : { line : 0 , character : 2 } ,
153
+ end : { line : 0 , character : 7 } ,
154
+ } ,
155
+ newText : 'subtitle' ,
156
+ } ;
157
+
158
+ it ( 'should handle rename request for property read' , async ( ) => {
159
+ const response = await client . sendRequest ( lsp . RenameRequest . type , {
160
+ textDocument : {
161
+ uri : `file://${ FOO_TEMPLATE } ` ,
162
+ } ,
163
+ position : { line : 0 , character : 3 } ,
164
+ newName : 'subtitle'
165
+ } ) ;
166
+ expect ( response ) . not . toBeNull ( ) ;
167
+ expect ( response ?. changes ?. [ FOO_TEMPLATE ] . length ) . toBe ( 1 ) ;
168
+ expect ( response ?. changes ?. [ FOO_TEMPLATE ] ) . toContain ( expectedRenameInTemplate ) ;
169
+ expect ( response ?. changes ?. [ FOO_COMPONENT ] . length ) . toBe ( 1 ) ;
170
+ expect ( response ?. changes ?. [ FOO_COMPONENT ] ) . toContain ( expectedRenameInComponent ) ;
171
+ } ) ;
172
+ } ) ;
173
+
174
+ describe ( 'from typescript files' , ( ) => {
175
+ beforeEach ( async ( ) => {
176
+ openTextDocument ( client , APP_COMPONENT ) ;
177
+ const languageServiceEnabled = await waitForNgcc ( client ) ;
178
+ expect ( languageServiceEnabled ) . toBeTrue ( ) ;
179
+ } ) ;
180
+
181
+ it ( 'should not be enabled, see https://github.com/microsoft/vscode/issues/115354' ,
182
+ async ( ) => {
183
+ const prepareRenameResponse = await client . sendRequest ( lsp . PrepareRenameRequest . type , {
184
+ textDocument : {
185
+ uri : `file://${ APP_COMPONENT } ` ,
186
+ } ,
187
+ position : { line : 4 , character : 25 } ,
188
+ } ) as { range : lsp . Range , placeholder : string } ;
189
+ expect ( prepareRenameResponse ) . toBeNull ( ) ;
190
+ const renameResponse = await client . sendRequest ( lsp . RenameRequest . type , {
191
+ textDocument : {
192
+ uri : `file://${ APP_COMPONENT } ` ,
193
+ } ,
194
+ position : { line : 4 , character : 25 } ,
195
+ newName : 'surname'
196
+ } ) ;
197
+ expect ( renameResponse ) . toBeNull ( ) ;
198
+ } ) ;
199
+
200
+ xdescribe ( 'Blocked by https://github.com/microsoft/vscode/issues/115354' , ( ) => {
201
+ it ( 'should handle prepare rename request for property read' , async ( ) => {
202
+ const response = await client . sendRequest ( lsp . PrepareRenameRequest . type , {
203
+ textDocument : {
204
+ uri : `file://${ APP_COMPONENT } ` ,
205
+ } ,
206
+ position : { line : 4 , character : 25 } ,
207
+ } ) as { range : lsp . Range , placeholder : string } ;
208
+ expect ( response . range ) . toEqual ( {
209
+ start : { line : 4 , character : 25 } ,
210
+ end : { line : 4 , character : 29 } ,
211
+ } ) ;
212
+ expect ( response . placeholder ) . toEqual ( 'name' ) ;
213
+ } ) ;
214
+
215
+ describe ( 'property rename' , ( ) => {
216
+ const expectedRenameInComponent = {
217
+ range : {
218
+ start : { line : 7 , character : 2 } ,
219
+ end : { line : 7 , character : 6 } ,
220
+ } ,
221
+ newText : 'surname' ,
222
+ } ;
223
+ const expectedRenameInTemplate = {
224
+ range : {
225
+ start : { line : 4 , character : 25 } ,
226
+ end : { line : 4 , character : 29 } ,
227
+ } ,
228
+ newText : 'surname' ,
229
+ } ;
230
+
231
+ it ( 'should handle rename request for property read in a template' , async ( ) => {
232
+ const response = await client . sendRequest ( lsp . RenameRequest . type , {
233
+ textDocument : {
234
+ uri : `file://${ APP_COMPONENT } ` ,
235
+ } ,
236
+ position : { line : 4 , character : 25 } ,
237
+ newName : 'surname'
238
+ } ) ;
239
+ expect ( response ) . not . toBeNull ( ) ;
240
+ expect ( response ?. changes ?. [ APP_COMPONENT ] . length ) . toBe ( 2 ) ;
241
+ expect ( response ?. changes ?. [ APP_COMPONENT ] ) . toContain ( expectedRenameInComponent ) ;
242
+ expect ( response ?. changes ?. [ APP_COMPONENT ] ) . toContain ( expectedRenameInTemplate ) ;
243
+ } ) ;
244
+
245
+ it ( 'should handle rename request for property in the component' , async ( ) => {
246
+ const response = await client . sendRequest ( lsp . RenameRequest . type , {
247
+ textDocument : {
248
+ uri : `file://${ APP_COMPONENT } ` ,
249
+ } ,
250
+ position : { line : 7 , character : 4 } ,
251
+ newName : 'surname'
252
+ } ) ;
253
+ expect ( response ) . not . toBeNull ( ) ;
254
+ expect ( response ?. changes ?. [ APP_COMPONENT ] . length ) . toBe ( 2 ) ;
255
+ expect ( response ?. changes ?. [ APP_COMPONENT ] ) . toContain ( expectedRenameInComponent ) ;
256
+ expect ( response ?. changes ?. [ APP_COMPONENT ] ) . toContain ( expectedRenameInTemplate ) ;
257
+ } ) ;
258
+ } ) ;
259
+ } ) ;
260
+ } ) ;
261
+ } ) ;
120
262
} ) ;
121
263
122
264
function onNgccProgress ( client : MessageConnection ) : Promise < string > {
0 commit comments