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

Add option to set organizeImports provider #90221

Closed
Spenhouet opened this issue Feb 7, 2020 · 7 comments
Closed

Add option to set organizeImports provider #90221

Spenhouet opened this issue Feb 7, 2020 · 7 comments
Assignees
Labels
api editor-code-actions Editor inplace actions (Ctrl + .) under-discussion Issue is under discussion for relevance, priority, approach wont-fix

Comments

@Spenhouet
Copy link

Spenhouet commented Feb 7, 2020

Currently source.organizeImports activates all extensions that provide this functionality.
This leads to problems like this: #90220

I wish that similar to python.formatting.provider we could also set a python.organizeImports.provider.

This would control which extension is supposed to run the organizeImports action (and which one not).

@mjbvz
Copy link
Collaborator

mjbvz commented Feb 7, 2020

Extensions can already provide for more scoped code actions kinds, such as source.organizeImports.python to support this

We could consider allowing codeActionsOnSave to specify which extension to use for a given on save action, the way editor.defaultFormatter woks

@mjbvz mjbvz added api editor-code-actions Editor inplace actions (Ctrl + .) under-discussion Issue is under discussion for relevance, priority, approach labels Feb 7, 2020
@Spenhouet
Copy link
Author

Sounds good. That would do the job.

@copdips
Copy link

copdips commented May 1, 2020

@mjbvz
vscode 1.44 introduced code actions order, what is the correct settings if I want to use this new feature ? The given setting example doesn't work, if I don't use your tip on source.organizeImports.python. The new feature even changed the type of the setting, editor.codeActionsOnSave was a dict before, and now it's an array.

"editor.codeActionsOnSave": [
    "source.organizeImports",
    "source.fixAll"
]

I gave the initial import order like:

import sys
import os

after save, vscode changed it to (it deleted import):

import os
import os

@mjbvz
Copy link
Collaborator

mjbvz commented May 2, 2020

@copdips My example was theoretical, I'm not sure it has been implemented by python

@copdips
Copy link

copdips commented May 2, 2020

@mjbvz your example source.organizeImports.python fixed the issue. And as vscode 1.44 introduced the sorted code actions, I would like to know if we can do something with it.

@etienne-monier
Copy link

Hi, this topic is quite old.

I've got the same problem with imports like

from mypackage import (
    function1,
    function2,
    function3,
    function4,
    function5,
    function6,
    function7,
    function8,
    function9,
)

with the configuration

    "python.formatting.provider": "black",
    "python.formatting.blackArgs": [
        "--line-length",
        "80"
    ],
    "editor.formatOnPaste": false,
    "editor.formatOnSave": true,
    "editor.formatOnSaveMode": "file",
    // Options for isort
    "python.sortImports.args": [
        "--settings-path=${workspaceFolder}/pyproject.toml",
    ],
    "[python]": {
        "editor.codeActionsOnSave": {
            "source.organizeImports.python": true,
        },
        "editor.rulers": [
            72,
            79
        ]
    },

When I save it, the import list get into line format, then comes back to column. I tried to use the source.organizeImports.python: true instead of "source.organizeImports.python": true,, but this did not work.

Help!

@mjbvz
Copy link
Collaborator

mjbvz commented Oct 7, 2021

Closing due to lack of additional feedback since it was opened. Adding additional scopes to code actions can help unblock the users who running into this in advanced cases

@mjbvz mjbvz closed this as completed Oct 7, 2021
@mjbvz mjbvz added the wont-fix label Oct 7, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Nov 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api editor-code-actions Editor inplace actions (Ctrl + .) under-discussion Issue is under discussion for relevance, priority, approach wont-fix
Projects
None yet
Development

No branches or pull requests

5 participants