Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Updating imports" happens unnecessarily #641

Open
joelmukuthu opened this issue Oct 29, 2020 · 7 comments
Open

"Updating imports" happens unnecessarily #641

joelmukuthu opened this issue Oct 29, 2020 · 7 comments
Labels
bug Something isn't working

Comments

@joelmukuthu
Copy link

Describe the bug
I work on a project containing different types of files (mostly *.ts, *.sql, *.svelte, *.json, *.yml, *.md). I observe the following two issues:

  1. Whenever I rename a file, even a .sql file for instance, the Svelte plugin tries to update imports in *.svelte files.
  2. A Node.js process is forked to update imports and that runs at 100% CPU (or more). I often have to kill the process, it doesn't stop on its own.

I have about 2000 files in the project and only 100 of them are *.svelte files.

To Reproduce

  1. Clone the template project https://github.com/sveltejs/template
  2. Open it in VSCode. Ensure you have the Svelte for VSCode plugin installed.
  3. Add a file in the src/ directory of any type, try with foo.yml.
  4. Rename the file (e.g. to bar.yml). Keep an eye on the info/status toolbar at the bottom of VS Code, you'll see "Updating imports" quickly show and then disappear.

Expected behavior

  1. That renaming a non-svelte (or ts or js) file should not trigger updating of imports in svelte files.
  2. That renaming a file that's not used anywhere does not trigger updating of imports (it's not imported yet)
  3. That imports are not automatically updated, rather, I'm asked if I'd like to update imports. This is the current behaviour in VSCode itself.
  4. Ideally, I get to configure which file types should trigger updating of imports in svelte files.

Screenshots
N/A

System (please complete the following information):

  • OS: Ubuntu Linux 20.04
  • IDE: VSCode v1.50.1
  • Plugin/Package: Svelte for VSCode v102.3.0

Additional context
N/A

@joelmukuthu joelmukuthu added the bug Something isn't working label Oct 29, 2020
@dummdidumm
Copy link
Member

Expected behavior

  1. That renaming a non-svelte (or ts or js) file should not trigger updating of imports in svelte files.

You could also import non-ts/js files into Svelte files I think.

  1. That renaming a file that's not used anywhere does not trigger updating of imports (it's not imported yet)

How to know if the file is not imported yet if you don't scan the other files? -> this is not possible unfortunately.

  1. That imports are not automatically updated, rather, I'm asked if I'd like to update imports. This is the current behaviour in VSCode itself.

That is a good idea!

  1. Ideally, I get to configure which file types should trigger updating of imports in svelte files.

Yes this would certainly help for point 1.

General note: To update the imports, we just forward the request to our TypeScript language service which then does all the work of finding out what needs to be changed. I'm curious to know whether or not the update times are equally long when you open up your project, open a TS file and NOT a Svelte file (so the Svelte extension is not triggered/started) and then do a file rename of a) a TS file b) a sql file.

@joelmukuthu
Copy link
Author

Following your instructions,

  1. when I rename a TS file that's imported somewhere, it takes about 2-3 seconds before I'm presented with the dialog on whether or not I want to update imports.
  2. when I rename a TS file that's not imported, a note in the status toolbar "Checking for update of TS/JS files" shows up and disappears after 2-3 seconds.
  3. when I rename a TS file, nothing happens (the note in the toolbar doesn't show).

Regarding my 4 expected outcomes, I agree that it'd be hard to know what files to trigger updates for. But if we combine all those points, we could have a user-configurable list of file types to look out for and then default it to something common. Also, on the issue of knowing whether the file is imported or not, if that feature is split up into a) check for imports and b) prompt the user for updates to imports, then hopefully there might a little less work to do in the first step.

@dummdidumm
Copy link
Member

In the meantime you can disable this completely by setting https://github.com/sveltejs/language-tools/tree/master/packages/svelte-vscode#sveltepluginsvelterenameenable to false.

@joelmukuthu
Copy link
Author

Great, thanks for the pointer @dummdidumm!

@dummdidumm
Copy link
Member

This will now only search for imports to update when .ts, .js, .svelte or .json file paths are changed. What's left to do is the "update imports?"-question.

dummdidumm pushed a commit to dummdidumm/language-tools that referenced this issue May 1, 2022
The TS plugin and the Svelte extension want to update the same locations after a file move/rename in some cases; prevent that
sveltejs#641
@henrikvilhelmberglund
Copy link

I saw this in Svelte 4, copying an existing .svelte file and renaming it from copy to another name caused a never ending "Updating Imports..." (needed to reload the editor to get rid of it)

@jasonlyu123
Copy link
Member

@henrikvilhelmberglund I create a new issue to track it #2065

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants