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

VSCode gets stuck on sorting imports if source.organizeImports is enabled and isort is installed #17828

Closed
BLucky-gh opened this issue Oct 21, 2021 · 6 comments
Assignees
Labels
area-formatting bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster investigating We are looking into the cause of the issue

Comments

@BLucky-gh
Copy link

Environment data

  • VS Code version: 1.61.2
  • Extension version (available under the Extensions sidebar): v2021.10.1365161279
  • OS and version: Windows 10 21H1 with VSCode server running on WSL Debian
  • Python version (& distribution if applicable, e.g. Anaconda): 3.9.2
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): poetry
  • Relevant/affected Python packages and their versions: isort
  • Relevant/affected Python-related VS Code extensions and their versions: Python
  • Value of the python.languageServer setting: Pylance

[NOTE: If you suspect that your issue is related to the Microsoft Python Language Server (python.languageServer: 'Microsoft'), please download our new language server Pylance from the VS Code marketplace to see if that fixes your issue]

Expected behaviour

VSCode sorts my imports automatically on save

Actual behaviour

When saving a python file with

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

in settings.json I get a notification with an indefinite loading bar saying Saving [filename]: Applying code action "Sort Imports"., which seemingly never finishes.
Looking at Output>Python I see that it tries to call isort - --diff, and when I try to run it myself in a terminal it also hangs forever. Running isort . --diff in the project root however finishes instantly and works as intended

Steps to reproduce:

[NOTE: Self-contained, minimal reproducing code samples are extremely helpful and will expedite addressing your issue]

  1. Install isort
  2. Add
"[python]": {
    "editor.codeActionsOnSave": {
      "source.organizeImports": true
    }
  }

to your settings.json
3. Save a random python file

Logs

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

isort - --diff
cwd: ~/git/vairus_matrix_search/vairus_matrix_search

I clicked "cancel" on the sorting task here
image

~/.cache/pypoetry/virtualenvs/vairus-matrix-search-n0kaFjyj-py3.9/bin/python -m flake8 --max-line-length=88 --format=%(row)d,%(col)d,%(code).1s,%(code)s:%(text)s ~/git/vairus_matrix_search/vairus_matrix_search/main.py
cwd: ~/git/vairus_matrix_search
##########Linting Output - flake8##########
3,1,I,I100:Import statements are in the wrong order. 'import json' should be before 'from getpass import getpass'
3,1,I,I202:Additional newline in a group of imports. 'import json' is identified as Stdlib and 'from getpass import getpass' is identified as Stdlib.
5,1,I,I202:Additional newline in a group of imports. 'from os import path' is identified as Stdlib and 'import json' is identified as Stdlib.
12,1,F,F401:'websockets' imported but unused
36,5,F,F841:local variable 'resp' is assigned to but never used

@BLucky-gh BLucky-gh added bug Issue identified by VS Code Team member as probable bug triage-needed Needs assignment to the proper sub-team labels Oct 21, 2021
@karthiknadig karthiknadig added area-formatting triage and removed triage-needed Needs assignment to the proper sub-team labels Oct 21, 2021
@karrtikr
Copy link

karrtikr commented Oct 21, 2021

Thanks for the bug report! We investigate issues in order based on priority and severity, which includes the impact it has on your ability to use the extension to do productive work, and the number of people affected. If other users come forward and leave a comment demonstrating they are seeing/reproducing the problem then we will raise this issue's priority.

Thanks for your understanding and patience!

@karrtikr karrtikr added investigating We are looking into the cause of the issue and removed triage labels Oct 21, 2021
@karrtikr
Copy link

It seems to work fine for me. Can you provide the following info:

Install isort

  • Extension ships with isort, so you do not need to install it. What did you use to install it, and do you have "python.sortImports.path" set to your installed isort?
  • What's the isort version you're using?
  • A minimal file content which reproduces this?

@karrtikr karrtikr added the info-needed Issue requires more information from poster label Oct 21, 2021
@karrtikr
Copy link

Your issue could be a potential dup of #7042 based on your answers.

@BLucky-gh
Copy link
Author

BLucky-gh commented Oct 22, 2021

  • Extension ships with isort, so you do not need to install it. What did you use to install it, and do you have "python.sortImports.path" set to your installed isort?

Didn't know the extension ships with isort, I just used poetry add --dev isort which installs it from PyPi, and then set python.sortImports.path to isort

  • What's the isort version you're using?

Will tell in an hour, but I assume latest version compatible with python 3.9

  • A minimal file content which reproduces this?

Will give in an hour, the issue is on my work pc and my workday starts in an hour

Your issue could be a potential dup of #7042 based on your answers.

Looks like it is, I did set the path to isort and it is within a virtual env

@BLucky-gh
Copy link
Author

  • What's the isort version you're using?
                 _                 _
                (_) ___  ___  _ __| |_
                | |/ _/ / _ \/ '__  _/
                | |\__ \/\_\/| |  | |_
                |_|\___/\___/\_/   \_/

      isort your imports, so you don't have to.

                    VERSION 5.9.3
  • A minimal file content which reproduces this?
from getpass import getpass

import json

from os import path

import requests
from requests.structures import CaseInsensitiveDict

import rsa

import websockets

@karrtikr
Copy link

Yep, closing as dup of #7042. Please try some of the workarounds mentioned there like #7042 (comment).

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-formatting bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster investigating We are looking into the cause of the issue
Projects
None yet
Development

No branches or pull requests

3 participants