You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
many many thanks for this extension, it's really great.
I use format on save and been pretty happy about it.
But I also wanted to do Isort on save, could it be possible to add both of the tools or smth ?
Thanks a lot
Copied from original issue: DonJayamanne/pythonVSCode#1140
Brett Cannon (@brettcannon) I'd like to submit a PR to add this feature but I'm not yet familiar with the codebase. Do you have any pointers to get me started?
I know there's a lot together there, but if you think it's a possible way so I can improve it and make a PR.
This proposed code works, I ran a test locally and it made both of the formatting correctly.
2 - Another option would be to transform the "python.formatting.provider" configuration into an array and it execute all the formats in sequence. ["autopep8", "isort"]. The problem here would be the mandatory change in who already uses the setting as a string.
Ricardo Baltazar Chaves (@ricardochaves) Import sorting is basically the only thing that people would potentially want to stack with other formatters, so I don't think making the support generic makes sense.
Ricardo Baltazar Chaves (@ricardochaves)
Please make use of the PythonImportSortProvider class to invoke isort in /Users/donjayamanne/.vscode-insiders/extensions/pythonVSCode/src/client/providers/importSortProvider.ts
Ricardo Baltazar Chaves (@ricardochaves)
Please could you look at utilizing the corresponding VS Code API (Code Actions) see here Please look at code.visualstudio.com/updates/v1_23#_run-code-actions-on-save
I'd like to ensure sorting of imports within the python extension is implemented the way it is implemented in other languages (see above link).
Activity
DonJayamanne commentedon Nov 14, 2017
Unfortunately, not at this stage. Will look into this later as a feature request.
DonJayamanne commentedon Nov 14, 2017
From eMerzh (@eMerzh) on August 5, 2017 12:22
Thanks a lot :)
i'll follow the updates ;)
DonJayamanne commentedon Nov 14, 2017
From Damian Pukaluk (@threaz) on August 23, 2017 19:24
Is there any other way to run your
sort importscommand on save? I mean using some kind of hook etc.brettcannon commentedon Jan 30, 2018
We might consider adding this is someone submitted a PR that added a flag to also do import sorts as part of document formatting.
4 remaining items
n6g7 commentedon Jun 2, 2018
Brett Cannon (@brettcannon) I'd like to submit a PR to add this feature but I'm not yet familiar with the codebase. Do you have any pointers to get me started?
ricardochaves commentedon Jun 3, 2018
What would be the best way to implement this in your opinion?
1 - One option would be to take one step further in the promise of provideDocumentFormattingEdits:
I know there's a lot together there, but if you think it's a possible way so I can improve it and make a PR.
This proposed code works, I ran a test locally and it made both of the formatting correctly.
2 - Another option would be to transform the "python.formatting.provider" configuration into an array and it execute all the formats in sequence. ["autopep8", "isort"]. The problem here would be the mandatory change in who already uses the setting as a string.
brettcannon commentedon Jun 4, 2018
Ricardo Baltazar Chaves (@ricardochaves) Import sorting is basically the only thing that people would potentially want to stack with other formatters, so I don't think making the support generic makes sense.
ricardochaves commentedon Jun 7, 2018
Perfect Brett Cannon (@brettcannon), and what do you think of this solution?
New method in
BaseFormatter:In the format chain, after it applies the defined formatter, we call the new method:
settings.sortImports.sortOnSave.isortafter formatting.DonJayamanne commentedon Jun 8, 2018
Ricardo Baltazar Chaves (@ricardochaves)
Please make use of the
PythonImportSortProviderclass to invokeisortin /Users/donjayamanne/.vscode-insiders/extensions/pythonVSCode/src/client/providers/importSortProvider.tsDonJayamanne commentedon Jun 8, 2018
I think we need to take a closer look at this.
Ideally sorting of imports during save should be done via the VS Code API.
Please look at https://code.visualstudio.com/updates/v1_23#_run-code-actions-on-save
ricardochaves commentedon Jun 8, 2018
Hi Don Jayamanne (@DonJayamanne) ,
What do you think of this solution?
On sortImports.ts (/Users/ricardochaves/Desktop/projetos/vscode-python/src/client/sortImports.ts):
An extremely simple code. Using the
onWillSaveTextDocumentevent and also thePythonImportSortProvider.DonJayamanne commentedon Jun 9, 2018
Ricardo Baltazar Chaves (@ricardochaves)
Please could you look at utilizing the corresponding VS Code API (Code Actions) see here Please look at code.visualstudio.com/updates/v1_23#_run-code-actions-on-save
I'd like to ensure sorting of imports within the python extension is implemented the way it is implemented in other languages (see above link).
Add isort CodeAction (sort imports on save) (#1926)