language-tools icon indicating copy to clipboard operation
language-tools copied to clipboard

F2/Renaming a .ts file to a .svelte.ts does not update imports in VS Code

Open newsve opened this issue 7 months ago • 5 comments

Describe the bug

Updating myImport.ts to myImport.svelte.ts, should update all imports of myImport.ts in other files (either by prompting or automatically depending on your VS Code settings).

Reproduction

Rename any .ts file to a .svelte.ts file and watch how imports get ignored.

If you uninstall the VS Code Svelte plugin you get at least the imports of your renamed file in the .ts files but not in the .svelte files updated.

Expected behaviour

Updating all imports.

System Info

VS Code 1.98.2 on Ubuntu

Plugins installed: (TS-plugin is enabled)

Image

Which package is the issue about?

Svelte for VS Code extension

Additional Information, eg. Screenshots

No response

newsve avatar Apr 08 '25 10:04 newsve

The update-import functions are split between the TypeScript and Svelte extensions to avoid duplicate edits. When there is a duplicated edit between TypeScript and the Svelte extension, it might cause a race condition and break the code. I think what happens in your case is that you haven't opened any Svelte files, so the Svelte extension hasn't started yet. That is why it is missing part of the functionality. Can you check if it works after you opened a svelte files?

jasonlyu123 avatar Apr 09 '25 01:04 jasonlyu123

Interesting idea, so I've just tried:

Image

  • Closed all open files in VS Code
  • Closed VS Code
  • Restarted VS Code
  • Opened a .svelte file
  • Opened a .svelte.ts file
  • Clicked on a .ts file in the explorer pane
  • Pressed F2
  • Changed name to .svelte.ts

Still the same, just that .ts file got renamed (I checked the git tab), no prompt no nothing.

FWIW, tried the same in Cursor with the same outcome.

If you have more ideas let me know, happy to try more!

Edit: BTW, this has worked flawlessly on March 19, where a renaming affected 9 files. I would have reported it then already if it hadn't worked then.

newsve avatar Apr 09 '25 05:04 newsve

There is a separate config svelte.plugin.svelte.rename.enable for the Svelte extension part. Can you check if it's enabled? If it's, can you check if this happens to specific files or all the files?

jasonlyu123 avatar Apr 09 '25 05:04 jasonlyu123

It's enabled:

Image

If it's, can you check if this happens to specific files or all the files?

Now, it is getting weird, I redid the entire process above but change another .ts file's (let's call it b.ts) name to .svelte.ts in the same folder.

This time, while VS Code didn't prompt, at least it opened all affected files and changed their imports properly and left the file unsaved/dirty.

Now, I did the same for the og file (let's call it a.ts) and it worked there too.

Since, I couldn't believe my eyes, I tried close VS Code, redid everything and got the same result, I got unsaved files with all affected imports.

Now, I tried this a third time but again with the og file a.ts first and it worked too.

Totally confused...

newsve avatar Apr 09 '25 08:04 newsve

Update: It is definitely not about if a .svelte or .svelte.ts file is open, it feels rather erratically.

I just had open 14 files, all kind of files, many .svelte and many .svelte.ts.

I renamed one .ts file to a .svelte.ts file which affects imports in three more files. Nothing had happened.

newsve avatar Apr 11 '25 10:04 newsve