-
Notifications
You must be signed in to change notification settings - Fork 29k
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
Organize imports and formatters are conflicting due to a race condition #83586
Comments
I know this issue is closed but it is the closest I found to an issue I have with isort. I was struggling to get it to work with the setup.cfg files in my project directory. Looking at your description of this issue it is possible that it is actually using setup.cfg but the race condition is messing up my imports. In your journey with VSCode + isort did you find that it checked for and respected any setup.cfg file? If not (or you are unsure) then at least I can open a new issue to be investigated. |
@baolsen sorry I don't think I understand what you mean, this issue is open, not closed. |
@baolsen – I don't think the race issue is related to VS Code not reading isort settings from setup.cfg. At least for me, I can consistently get import sorting to work as expected if I specify the settings file in my VS Code settings:
Why the above doesn't happen automatically is unclear to me, but that is for a different Issue. |
@pydolan's suggestion did seem to make the behavior consistently correct for me. I recommend using the
As an aside, I also had to add |
I really hope that this gets addressed soon. It keeps us from being able to sort imports on save. This race condition leads to deleted or duplicated code. That feels quite significant to me for this issue to be fixed. Code actions should run before the code formatter. |
Here's what I see debugging this setup for JS/TS:
From this, it seems to me that VS Code calls things in the correct order and does correctly await the result of organize imports @luabud Can you please share a link to the python extension's implementation of organize imports? |
I actually can't repro the race condition anymore, it's consistently organizing the imports first and then triggering the formatter. And it seems that if we wanted to change the order, we could do it in the extension side, so I'm closing this issue. FWIW the code for sorting imports is here: https://github.com/microsoft/vscode-python/blob/master/src/client/providers/importSortProvider.ts |
I can very much still reproduce this. I just used the
and opened a random python file. Directly on the first one it dances and deletes lines of code.
I extracted these lines of code into an empty python file ans pressed STRG + S multiple times (nothing else): |
@Spenhouet Oh that's weird! I can't repro this behaviour with the sample code you proved. I tried it with black, autopep8 and yapf. I opened an issue on the Python extension repo so we can investigate it (microsoft/vscode-python#10923), as it may not be due to a race condition. It'd help immensely if you could fill up our bug report template there providing your environment information, the formatter you're using as well as the contents of the Python channel in the Output: |
same issue here, the worst thing is that it even deletes some imports |
@copdips do you see the import deletion behaviour consistently? I wasn't able to reproduce it. |
Yes, as per the GIF in #83586 (comment), it deletes imports. |
@luabud I can reproduce this again with the following import:
Maybe you could try if you can also reproduce it with that import. |
microsoft/vscode-python#6933
This is not an extension issue though.
Steps to Reproduce:
Does this issue occur when all extensions are disabled?: No
The problem is that there's a race condition since there are two formatters being used when saving changes to a file. The results vary based on which formatter completes first. I.e. if black formats first, then you see one result, then isort formats the imports and changes the imports and you see another set of changes.
As you keep hitting save both trip on one another.
The Python extension wants to organize formatters and isort to be ran consistently, but we don't have control over that as VS Code is doing the excutions.
The text was updated successfully, but these errors were encountered: