microsoft / vscode-python

Python extension for Visual Studio Code
https://aka.ms/pvsc-marketplace
MIT License
4.34k stars 1.19k forks source link

Unexpectedly overlapping import suggestions in multi-root workspace using Jedi #21447

Open PeterJCLaw opened 1 year ago

PeterJCLaw commented 1 year ago

Type: Bug

Behaviour

Expected vs. Actual

In a multi-root workspace, where different interpreters are configured for different projects, I would expect that the import suggestions for each project are distinct. Instead they overlap, including suggestions from other projects for packages which aren't actually installed in the current one.

Steps to reproduce:

$ tree -L 2
.
├── proj-1
│   └── main.py
├── proj-2
│   └── main.py
├── repo.code-workspace
├── venv-1
│   └── ...
└── venv-2
    └── ...

$ cat repo.code-workspace 
{
    "folders": [
        {
            "path": "proj-1"
        },
        {
            "path": "proj-2"
        }
    ]
}

Install packages unlikely to already be present within the extension's vendoring:

$ venv-1/bin/pip install tuck
$ venv-2/bin/pip install layer-loader

Under Pylance each of these will only be offered as import suggestions in the respective environments, however using JediLSP both are offered in both. Using JediLSP, some packages (e.g: setuptools) are listed in duplicate.

Is the Python extension perhaps somehow calling Jedi for both environments regardless of the file that the user is looking at?

Diagnostic data

Output for Python in the Output panel

``` 2023-06-18 11:34:01.196 [info] Telemetry level is off 2023-06-18 11:34:01.196 [info] Experiments are disabled, only manually opted experiments are active. 2023-06-18 11:34:01.196 [info] Experiment 'pythonDeprecatePythonPath' is inactive 2023-06-18 11:34:01.196 [info] Test server listening. 2023-06-18 11:34:01.196 [info] Python interpreter path: /tmp/repo/venv-1/bin/python 2023-06-18 11:34:01.681 [info] Starting Jedi language server for proj-2. 2023-06-18 11:34:02.422 [info] Extension search path: /home/peter/.vscode/extensions 2023-06-18 11:34:02.439 [info] > /tmp/repo/venv-2/bin/python ~/.vscode/extensions/ms-python.python-2023.10.1/pythonFiles/linter.py -m mypy --show-column-numbers /tmp/repo/proj-2/main.py 2023-06-18 11:34:02.439 [info] cwd: /tmp/repo/proj-2 2023-06-18 11:34:02.446 [info] > /tmp/repo/venv-2/bin/python ~/.vscode/extensions/ms-python.python-2023.10.1/pythonFiles/linter.py -m flake8 /tmp/repo/proj-2/main.py 2023-06-18 11:34:02.446 [info] cwd: /tmp/repo/proj-2 2023-06-18 11:34:02.489 [info] > /tmp/repo/venv-2/bin/python -c "import mypy" 2023-06-18 11:34:02.499 [info] > /tmp/repo/venv-2/bin/python -c "import flake8" 2023-06-18 11:34:02.516 [info] > /tmp/repo/venv-2/bin/python -c "import mypy" 2023-06-18 11:34:02.530 [info] > /tmp/repo/venv-2/bin/python -c "import flake8" 2023-06-18 11:34:02.532 [info] Linter 'mypy' is not installed. Please install it or select another linter". Error: Module 'mypy' not installed. 2023-06-18 11:34:02.532 [warning] Linter 'mypy' is not installed. Please install it or select another linter". [n [Error]: Module 'mypy' not installed. at s.execForLinter (/home/peter/.vscode/extensions/ms-python.python-2023.10.1/out/client/extension.js:2:237440) at process.processTicksAndRejections (node:internal/process/task_queues:96:5) at async a.run (/home/peter/.vscode/extensions/ms-python.python-2023.10.1/out/client/extension.js:2:535853) at async a.runLinter (/home/peter/.vscode/extensions/ms-python.python-2023.10.1/out/client/extension.js:2:551278)] 2023-06-18 11:34:02.545 [info] Linter 'flake8' is not installed. Please install it or select another linter". Error: Module 'flake8' not installed. 2023-06-18 11:34:02.545 [warning] Linter 'flake8' is not installed. Please install it or select another linter". [n [Error]: Module 'flake8' not installed. at s.execForLinter (/home/peter/.vscode/extensions/ms-python.python-2023.10.1/out/client/extension.js:2:237440) at async c.run (/home/peter/.vscode/extensions/ms-python.python-2023.10.1/out/client/extension.js:2:535853) at async c.runLinter (/home/peter/.vscode/extensions/ms-python.python-2023.10.1/out/client/extension.js:2:539796)] 2023-06-18 11:34:08.829 [info] Extension search path: /home/peter/.vscode/extensions 2023-06-18 11:34:08.884 [info] > /tmp/repo/venv-1/bin/python ~/.vscode/extensions/ms-python.python-2023.10.1/pythonFiles/linter.py -m mypy --show-column-numbers /tmp/repo/proj-1/main.py 2023-06-18 11:34:08.884 [info] cwd: /tmp/repo/proj-1 2023-06-18 11:34:08.895 [info] > /tmp/repo/venv-1/bin/python ~/.vscode/extensions/ms-python.python-2023.10.1/pythonFiles/linter.py -m flake8 /tmp/repo/proj-1/main.py 2023-06-18 11:34:08.895 [info] cwd: /tmp/repo/proj-1 2023-06-18 11:34:08.943 [info] > /tmp/repo/venv-1/bin/python -c "import mypy" 2023-06-18 11:34:09.007 [info] ##########Linting Output - flake8########## 2023-06-18 11:34:09.007 [info] 1,1,F,F401:'tuck' imported but unused 1,1,F,F401:'layer_loader' imported but unused 1,12,E,E401:multiple imports on one line 2023-06-18 11:34:09.117 [info] > /tmp/repo/venv-1/bin/python -c "import mypy" 2023-06-18 11:34:09.131 [info] Linter 'mypy' is not installed. Please install it or select another linter". Error: Module 'mypy' not installed. 2023-06-18 11:34:09.131 [warning] Linter 'mypy' is not installed. Please install it or select another linter". [n [Error]: Module 'mypy' not installed. at s.execForLinter (/home/peter/.vscode/extensions/ms-python.python-2023.10.1/out/client/extension.js:2:237440) at async a.run (/home/peter/.vscode/extensions/ms-python.python-2023.10.1/out/client/extension.js:2:535853) at async a.runLinter (/home/peter/.vscode/extensions/ms-python.python-2023.10.1/out/client/extension.js:2:551278)] 2023-06-18 11:34:09.264 [info] Starting Jedi language server for proj-1. 2023-06-18 11:34:10.638 [info] Extension search path: /home/peter/.vscode/extensions 2023-06-18 11:34:10.656 [info] > /tmp/repo/venv-1/bin/python ~/.vscode/extensions/ms-python.python-2023.10.1/pythonFiles/linter.py -m mypy --show-column-numbers /tmp/repo/proj-1/main.py 2023-06-18 11:34:10.656 [info] cwd: /tmp/repo/proj-1 2023-06-18 11:34:10.670 [info] > /tmp/repo/venv-1/bin/python ~/.vscode/extensions/ms-python.python-2023.10.1/pythonFiles/linter.py -m flake8 /tmp/repo/proj-1/main.py 2023-06-18 11:34:10.670 [info] cwd: /tmp/repo/proj-1 2023-06-18 11:34:10.716 [info] > /tmp/repo/venv-1/bin/python -c "import mypy" 2023-06-18 11:34:10.742 [info] > /tmp/repo/venv-1/bin/python -c "import mypy" 2023-06-18 11:34:10.754 [info] Linter 'mypy' is not installed. Please install it or select another linter". Error: Module 'mypy' not installed. 2023-06-18 11:34:10.754 [warning] Linter 'mypy' is not installed. Please install it or select another linter". [n [Error]: Module 'mypy' not installed. at s.execForLinter (/home/peter/.vscode/extensions/ms-python.python-2023.10.1/out/client/extension.js:2:237440) at process.processTicksAndRejections (node:internal/process/task_queues:96:5) at async a.run (/home/peter/.vscode/extensions/ms-python.python-2023.10.1/out/client/extension.js:2:535853) at async a.runLinter (/home/peter/.vscode/extensions/ms-python.python-2023.10.1/out/client/extension.js:2:551278)] 2023-06-18 11:34:10.801 [info] ##########Linting Output - flake8########## 2023-06-18 11:34:10.801 [info] 1,1,F,F401:'tuck' imported but unused 1,1,F,F401:'layer_loader' imported but unused 1,12,E,E401:multiple imports on one line 2023-06-18 11:34:13.682 [info] Python interpreter path: /tmp/repo/venv-2/bin/python 2023-06-18 11:34:13.691 [info] Extension search path: /home/peter/.vscode/extensions 2023-06-18 11:34:13.711 [info] > /tmp/repo/venv-2/bin/python ~/.vscode/extensions/ms-python.python-2023.10.1/pythonFiles/linter.py -m mypy --show-column-numbers /tmp/repo/proj-2/main.py 2023-06-18 11:34:13.711 [info] cwd: /tmp/repo/proj-2 2023-06-18 11:34:13.726 [info] > /tmp/repo/venv-2/bin/python ~/.vscode/extensions/ms-python.python-2023.10.1/pythonFiles/linter.py -m flake8 /tmp/repo/proj-2/main.py 2023-06-18 11:34:13.726 [info] cwd: /tmp/repo/proj-2 2023-06-18 11:34:13.770 [info] > /tmp/repo/venv-2/bin/python -c "import mypy" 2023-06-18 11:34:13.789 [info] > /tmp/repo/venv-2/bin/python -c "import flake8" 2023-06-18 11:34:13.828 [info] > /tmp/repo/venv-2/bin/python -c "import mypy" 2023-06-18 11:34:13.840 [info] > /tmp/repo/venv-2/bin/python -c "import flake8" 2023-06-18 11:34:13.842 [info] Linter 'mypy' is not installed. Please install it or select another linter". Error: Module 'mypy' not installed. 2023-06-18 11:34:13.842 [warning] Linter 'mypy' is not installed. Please install it or select another linter". [n [Error]: Module 'mypy' not installed. at s.execForLinter (/home/peter/.vscode/extensions/ms-python.python-2023.10.1/out/client/extension.js:2:237440) at async a.run (/home/peter/.vscode/extensions/ms-python.python-2023.10.1/out/client/extension.js:2:535853) at async a.runLinter (/home/peter/.vscode/extensions/ms-python.python-2023.10.1/out/client/extension.js:2:551278)] 2023-06-18 11:34:13.855 [info] Linter 'flake8' is not installed. Please install it or select another linter". Error: Module 'flake8' not installed. 2023-06-18 11:34:13.855 [warning] Linter 'flake8' is not installed. Please install it or select another linter". [n [Error]: Module 'flake8' not installed. at s.execForLinter (/home/peter/.vscode/extensions/ms-python.python-2023.10.1/out/client/extension.js:2:237440) at async c.run (/home/peter/.vscode/extensions/ms-python.python-2023.10.1/out/client/extension.js:2:535853) at async c.runLinter (/home/peter/.vscode/extensions/ms-python.python-2023.10.1/out/client/extension.js:2:539796)] 2023-06-18 11:34:27.458 [info] Python interpreter path: /tmp/repo/venv-1/bin/python ```

User Settings

``` Multiroot scenario, following user settings may not apply: languageServer: "Jedi" linting • flake8Enabled: true • mypyArgs: "" • mypyEnabled: true experiments • optOutFrom: ["pythonDeprecatePythonPath"] ```

Extension version: 2023.10.1 VS Code version: Code 1.79.2 (695af097c7bd098fbf017ce3ac85e09bbc5dda06, 2023-06-14T08:59:55.818Z) OS version: Linux x64 5.15.0-75-generic snap Modes:

karthiknadig commented 1 year ago

We launch separate instances of Jedi for each workspace. Looks like these are not getting scoped properly to each workspace.