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

Bug: Sort on Save garbles current file when refactoring #65

Open
flutterrausch opened this issue Jan 20, 2024 · 5 comments
Open

Bug: Sort on Save garbles current file when refactoring #65

flutterrausch opened this issue Jan 20, 2024 · 5 comments

Comments

@flutterrausch
Copy link

flutterrausch commented Jan 20, 2024

1st: love the ext, love the sort on save feature.

But I had to switch it off - too annoying too often. If I e.g. rename a function, I get a block of imports (most probably the last sorted ones) on top of current file - often leads to a lot of confusing project errors. I can Cmd-Z it away, but it totally breaks my flow.

Here is what I think happens: The refactor does an auto-save itself. Somehow import-sorter is hooked in and applies cached imports. It may only apply, if multiple files get changed thru the refactoring.

Please fix :)

@aziznal
Copy link
Owner

aziznal commented Feb 1, 2024

interesting issue. I've tried to recreate it on my side but wasn't able to. Could you share the exact scenario where you're seeing this behavior?

@flutterrausch
Copy link
Author

flutterrausch commented Feb 2, 2024

  • sort on save on, empty line between on
  • refactor/rename anything, that spans multiple files (current file must be saved, or sth)

Hope this helps

@malkomich
Copy link

It happens with sortOnSave feature enabled, everytime you refactor a file (renaming, moving to a different folder...)

I can show you an example of the unexpected changes automatically made in one of my files:

Captura de pantalla 2024-05-07 a las 1 05 54

It looks to be adding new "random"(it may follow some logic but I have no clue) imports, replacing the top lines of the file.

@DylanCross
Copy link

Came to report the same. Extension is awesome, but I figured I'd check if there's a fix before I give up on it.

I hit the issue mainly when refactoring. It's hard to tell exactly when since the imports change at the top of the file not where I'm at. But I think it's related to renaming functions or classes. It looks like it's copying sorted imports from different file.

@DylanCross
Copy link

Observation: It's definitely happening often when using the VSCode right click, Rename Symbol (F2). It also doesn't appear to be copying an existing set of imports from another file. I also always get a lot of imports.

Theory: When you rename an item that exists in multiple files, it renames and saves all those files. I believe the import statements from all of the files referenced are all sorted and added to just the current open file.

So if a given item that's renamed exists in 3, 4, or more files, a lot of imports get added to the existing file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants