@@ -307,7 +307,14 @@ export class CompletionsProviderImpl implements CompletionsProvider<CompletionEn
307
307
for ( const action of actions ) {
308
308
for ( const change of action . changes ) {
309
309
edit . push (
310
- ...this . codeActionChangesToTextEdit ( document , fragment , change , isImport )
310
+ ...this . codeActionChangesToTextEdit (
311
+ document ,
312
+ fragment ,
313
+ change ,
314
+ isImport ,
315
+ isInTag ( comp . position , document . scriptInfo ) ||
316
+ isInTag ( comp . position , document . moduleScriptInfo )
317
+ )
311
318
) ;
312
319
}
313
320
}
@@ -342,20 +349,28 @@ export class CompletionsProviderImpl implements CompletionsProvider<CompletionEn
342
349
doc : Document ,
343
350
fragment : SvelteSnapshotFragment ,
344
351
changes : ts . FileTextChanges ,
345
- isImport : boolean
352
+ isImport : boolean ,
353
+ actionTriggeredInScript : boolean
346
354
) : TextEdit [ ] {
347
355
return changes . textChanges . map ( ( change ) =>
348
- this . codeActionChangeToTextEdit ( doc , fragment , change , isImport )
356
+ this . codeActionChangeToTextEdit (
357
+ doc ,
358
+ fragment ,
359
+ change ,
360
+ isImport ,
361
+ actionTriggeredInScript
362
+ )
349
363
) ;
350
364
}
351
365
352
366
codeActionChangeToTextEdit (
353
367
doc : Document ,
354
368
fragment : SvelteSnapshotFragment ,
355
369
change : ts . TextChange ,
356
- isImport : boolean
370
+ isImport : boolean ,
371
+ actionTriggeredInScript : boolean
357
372
) : TextEdit {
358
- change . newText = this . changeSvelteComponentImport ( change . newText ) ;
373
+ change . newText = this . changeComponentImport ( change . newText , actionTriggeredInScript ) ;
359
374
360
375
const scriptTagInfo = fragment . scriptInfo ;
361
376
if ( ! scriptTagInfo ) {
@@ -427,10 +442,11 @@ export class CompletionsProviderImpl implements CompletionsProvider<CompletionEn
427
442
return name . replace ( / ( \w + ) _ _ S v e l t e C o m p o n e n t _ / , '$1' ) ;
428
443
}
429
444
430
- private changeSvelteComponentImport ( importText : string ) {
445
+ private changeComponentImport ( importText : string , actionTriggeredInScript : boolean ) {
431
446
const changedName = this . changeSvelteComponentName ( importText ) ;
432
- if ( importText !== changedName ) {
433
- // For some reason, TS sometimes adds the `type` modifier. Remove it.
447
+ if ( importText !== changedName || ! actionTriggeredInScript ) {
448
+ // For some reason, TS sometimes adds the `type` modifier. Remove it
449
+ // in case of Svelte component imports or if import triggered from markup.
434
450
return changedName . replace ( ' type ' , ' ' ) ;
435
451
}
436
452
0 commit comments