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

Cannot sort imports when both settings editor.formatOnSave and source.organizeImports are being used #5748

Closed
DavidArchibald opened this issue May 24, 2019 · 4 comments
Labels
area-formatting area-intellisense LSP-related functionality: auto-complete, docstrings, navigation, refactoring, etc. bug Issue identified by VS Code Team member as probable bug needs PR Ready to be worked on

Comments

@DavidArchibald
Copy link

DavidArchibald commented May 24, 2019

Issue Type: Bug

The issue described in the title is reproduced with these settings:

"[python]": {
    "editor.formatOnSave": true,
    "editor.codeActionsOnSave": {
        "source.organizeImports": true
    },
}

Only one or the other will work at a time which is odd because Go has basically the exact same thing in the default settings and it works fine. I have reproduced this with different formatters(autopep8 and black), using source.fixAll, and all sorts of other Python settings. This occurs in both the stable and insiders version of VSCode. It may be that editor.codeActionsOnSave just overrides editor.formatOnSave but as Go implements this just fine, I'm filing it as an issue with the Python extension. I apologize if I misunderstand the intent of the settings and it is working as intended.

Extension version: 2019.4.12954
VS Code version: Code 1.34.0 (a622c65b2c713c890fcf4fbf07cf34049d5fe758, 2019-05-15T21:59:37.030Z)
OS version: Windows_NT x64 10.0.17763

System Info
Item Value
CPUs Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz (8 x 1992)
GPU Status 2d_canvas: enabled
checker_imaging: disabled_off
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
native_gpu_memory_buffers: disabled_software
rasterization: enabled
surface_synchronization: enabled_on
video_decode: enabled
webgl: enabled
webgl2: enabled
Load (avg) undefined
Memory (System) 15.87GB (4.18GB free)
Process Argv
Screen Reader no
VM 0%
@ghost ghost added the triage-needed Needs assignment to the proper sub-team label May 24, 2019
@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label May 28, 2019
@karrtikr
Copy link

karrtikr commented May 31, 2019

Thanks for reporting the issue. This is the behavior I see,

import sys
import os

print   ('hello'    )

Press CTRL + S to save the file

import os
import sys

print   ('hello'    )

Only imports are sorted, but the file is NOT saved. Try saving the file again (maybe a few more times), until ideal code is reached.

import os
import sys

print('hello')

Settings editor.codeActionsOnSave and editor.formatOnSave works fine when used separately.
Looks like some overlap between the settings occurs.

@karrtikr karrtikr added area-formatting feature-refactoring bug Issue identified by VS Code Team member as probable bug and removed triage labels May 31, 2019
@karrtikr karrtikr removed their assignment May 31, 2019
@brettcannon brettcannon added the regression Bug didn't exist in a previous release label Jun 4, 2019
@luabud luabud added reason-preexisting and removed regression Bug didn't exist in a previous release labels Aug 13, 2019
@pengchaoandy
Copy link

I think we can add "editor.formatOnSave" as a entry under "editor.codeActionsOnSave"

@brettcannon brettcannon added area-intellisense LSP-related functionality: auto-complete, docstrings, navigation, refactoring, etc. and removed feature-refactoring labels Apr 9, 2020
@karrtikr karrtikr changed the title Cannot sort imports and format on save Cannot sort imports when both settings editor.formatOnSave and source.organizeImports are being used Aug 3, 2020
@karrtikr
Copy link

karrtikr commented Aug 3, 2020

Helpful comment: microsoft/vscode#83586 (comment)

@github-actions github-actions bot removed the needs PR label Aug 9, 2022
@karrtikr karrtikr added the needs PR Ready to be worked on label Aug 9, 2022
@karthiknadig
Copy link
Member

This is now supported via the isort extension.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-formatting area-intellisense LSP-related functionality: auto-complete, docstrings, navigation, refactoring, etc. bug Issue identified by VS Code Team member as probable bug needs PR Ready to be worked on
Projects
None yet
Development

No branches or pull requests

7 participants