@@ -1288,6 +1288,117 @@ describe('tsserver plugin', () => {
1288
1288
} ) ;
1289
1289
} ) ;
1290
1290
1291
+ describe ( 'renaming files' , ( ) => {
1292
+ test ( 'moving a transformed file updates its imports' , async ( ) => {
1293
+ await project . open ( {
1294
+ 'dir/greeting.ts' : stripIndent `
1295
+ import Component, { hbs } from '@glimmerx/component';
1296
+
1297
+ export interface GreetingArgs {
1298
+ message: string;
1299
+ }
1300
+
1301
+ export default class Greeting extends Component<GreetingArgs> {
1302
+ static template = hbs\`{{@message}}, World!\`;
1303
+ }
1304
+ ` ,
1305
+ 'dir/index.ts' : stripIndent `
1306
+ import Component, { hbs } from '@glimmerx/component';
1307
+ import Greeting from './greeting';
1308
+
1309
+ export class Application extends Component {
1310
+ static template = hbs\`
1311
+ <Greeting @message="Hello" />
1312
+ \`;
1313
+ }
1314
+ ` ,
1315
+ } ) ;
1316
+
1317
+ let greetingMoveResult = await server . request ( CommandTypes . GetEditsForFileRename , {
1318
+ oldFilePath : project . filePath ( 'dir/greeting.ts' ) ,
1319
+ newFilePath : project . filePath ( 'other/greeting.ts' ) ,
1320
+ } ) ;
1321
+
1322
+ expect ( greetingMoveResult ) . toMatchObject ( [
1323
+ {
1324
+ fileName : project . filePath ( 'dir/index.ts' ) ,
1325
+ textChanges : [
1326
+ {
1327
+ start : { line : 2 , offset : 23 } ,
1328
+ end : { line : 2 , offset : 33 } ,
1329
+ newText : '../other/greeting' ,
1330
+ } ,
1331
+ ] ,
1332
+ } ,
1333
+ ] ) ;
1334
+
1335
+ let indexMoveResult = await server . request ( CommandTypes . GetEditsForFileRename , {
1336
+ oldFilePath : project . filePath ( 'dir/index.ts' ) ,
1337
+ newFilePath : project . filePath ( 'other/index.ts' ) ,
1338
+ } ) ;
1339
+
1340
+ expect ( indexMoveResult ) . toMatchObject ( [
1341
+ {
1342
+ fileName : project . filePath ( 'dir/index.ts' ) ,
1343
+ textChanges : [
1344
+ {
1345
+ start : { line : 2 , offset : 23 } ,
1346
+ end : { line : 2 , offset : 33 } ,
1347
+ newText : '../dir/greeting' ,
1348
+ } ,
1349
+ ] ,
1350
+ } ,
1351
+ ] ) ;
1352
+ } ) ;
1353
+
1354
+ test ( 'moving an untransformed file updates its imports' , async ( ) => {
1355
+ await project . open ( {
1356
+ 'dir/foo.ts' : stripIndent `
1357
+ export const message = 'hello';
1358
+ ` ,
1359
+ 'dir/index.ts' : stripIndent `
1360
+ export { message } from './foo';
1361
+ ` ,
1362
+ } ) ;
1363
+
1364
+ let greetingMoveResult = await server . request ( CommandTypes . GetEditsForFileRename , {
1365
+ oldFilePath : project . filePath ( 'dir/foo.ts' ) ,
1366
+ newFilePath : project . filePath ( 'other/foo.ts' ) ,
1367
+ } ) ;
1368
+
1369
+ expect ( greetingMoveResult ) . toMatchObject ( [
1370
+ {
1371
+ fileName : project . filePath ( 'dir/index.ts' ) ,
1372
+ textChanges : [
1373
+ {
1374
+ start : { line : 1 , offset : 26 } ,
1375
+ end : { line : 1 , offset : 31 } ,
1376
+ newText : '../other/foo' ,
1377
+ } ,
1378
+ ] ,
1379
+ } ,
1380
+ ] ) ;
1381
+
1382
+ let indexMoveResult = await server . request ( CommandTypes . GetEditsForFileRename , {
1383
+ oldFilePath : project . filePath ( 'dir/index.ts' ) ,
1384
+ newFilePath : project . filePath ( 'other/index.ts' ) ,
1385
+ } ) ;
1386
+
1387
+ expect ( indexMoveResult ) . toMatchObject ( [
1388
+ {
1389
+ fileName : project . filePath ( 'dir/index.ts' ) ,
1390
+ textChanges : [
1391
+ {
1392
+ start : { line : 1 , offset : 26 } ,
1393
+ end : { line : 1 , offset : 31 } ,
1394
+ newText : '../dir/foo' ,
1395
+ } ,
1396
+ ] ,
1397
+ } ,
1398
+ ] ) ;
1399
+ } ) ;
1400
+ } ) ;
1401
+
1291
1402
describe ( 'error recovery' , ( ) => {
1292
1403
test ( 'introducing and fixing a template error with editor changes' , async ( ) => {
1293
1404
await project . open ( {
0 commit comments