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

How to get imports generated across project roots? #1587

Closed
ThiefMaster opened this issue Jul 22, 2021 · 7 comments
Closed

How to get imports generated across project roots? #1587

ThiefMaster opened this issue Jul 22, 2021 · 7 comments
Assignees

Comments

@ThiefMaster
Copy link

Environment data

  • Language Server version: 2021.7.5-pre.1
  • OS and version: linux x64
  • Python version: 3.9.6
  • python.analysis.indexing: undefined
  • python.analysis.typeCheckingMode: off

Expected behavior

If I write main_function in a/test_plugin_a/__init__.py and ask for autocompletion or import generation, I expect this function to be suggested with from main_project import main_function.

Actual behavior

It doesn't happen. However, Pylance clearly understands the import location, because if I manually add the import, "Go to definition" works fine. "Go to references" on the other hand does not find a reference to that function in the plugin root.

Logs

Python Language Server Log

[Info  - 2:47:23 PM] Pylance language server 2021.7.5-pre.1 (pyright 209f9621) starting
[Info  - 2:47:23 PM] Server root directory: /home/adrian/.vscode-server-insiders/extensions/ms-python.vscode-pylance-2021.7.5-pre.1/dist
[Info  - 2:47:23 PM] No configuration file found.
[Info  - 2:47:23 PM] No pyproject.toml file found.
[Info  - 2:47:23 PM] Setting pythonPath for service "mainproject": "/home/adrian/dev/vscode-python-roots-test/.venv/bin/python"
[Warn  - 2:47:23 PM] stubPath /home/adrian/dev/vscode-python-roots-test/mainproject/typings is not a valid directory.
[Info  - 2:47:23 PM] Assuming Python version 3.9
[Info  - 2:47:23 PM] Assuming Python platform Linux
Search paths for /home/adrian/dev/vscode-python-roots-test/mainproject
  /home/adrian/.vscode-server-insiders/extensions/ms-python.vscode-pylance-2021.7.5-pre.1/dist/typeshed-fallback/stdlib
  /home/adrian/dev/vscode-python-roots-test/mainproject
  /home/adrian/dev/vscode-python-roots-test/mainproject
  /home/adrian/dev/vscode-python-roots-test/mainproject/typings
  /home/adrian/.vscode-server-insiders/extensions/ms-python.vscode-pylance-2021.7.5-pre.1/dist/typeshed-fallback/stubs/...
  /home/adrian/.vscode-server-insiders/extensions/ms-python.vscode-pylance-2021.7.5-pre.1/dist/bundled/stubs
  /home/adrian/.pyenv/versions/3.9.6/lib/python3.9
  /home/adrian/.pyenv/versions/3.9.6/lib/python3.9/lib-dynload
  /home/adrian/dev/vscode-python-roots-test/.venv/lib/python3.9/site-packages
  /home/adrian/dev/vscode-python-roots-test/plugins/a
  /home/adrian/dev/vscode-python-roots-test/mainproject
[Warn  - 2:47:24 PM] Exception received when installing recursive file system watcher: TypeError [ERR_FEATURE_UNAVAILABLE_ON_PLATFORM]: The feature watch recursively is unavailable on the current platform, which is being used to run Node.js
[Warn  - 2:47:24 PM] Exception received when installing recursive file system watcher: TypeError [ERR_FEATURE_UNAVAILABLE_ON_PLATFORM]: The feature watch recursively is unavailable on the current platform, which is being used to run Node.js
[Warn  - 2:47:24 PM] Exception received when installing recursive file system watcher: TypeError [ERR_FEATURE_UNAVAILABLE_ON_PLATFORM]: The feature watch recursively is unavailable on the current platform, which is being used to run Node.js
[Info  - 2:47:24 PM] Searching for source files
[Info  - 2:47:24 PM] Found 2 source files
[Info  - 2:47:24 PM] Background analysis(1) root directory: /home/adrian/.vscode-server-insiders/extensions/ms-python.vscode-pylance-2021.7.5-pre.1/dist
[Info  - 2:47:24 PM] Background analysis(1) started
Background analysis message: setConfigOptions
Background analysis message: ensurePartialStubPackages
Background analysis message: setTrackedFiles
Background analysis message: markAllFilesDirty
[Info  - 2:47:24 PM] Background analysis(2) root directory: /home/adrian/.vscode-server-insiders/extensions/ms-python.vscode-pylance-2021.7.5-pre.1/dist
[Info  - 2:47:24 PM] Background analysis(2) started
[Info  - 2:47:24 PM] No configuration file found.
[Info  - 2:47:24 PM] No pyproject.toml file found.
[Info  - 2:47:24 PM] Setting pythonPath for service "plugins": "/home/adrian/dev/vscode-python-roots-test/.venv/bin/python"
[Warn  - 2:47:24 PM] stubPath /home/adrian/dev/vscode-python-roots-test/plugins/typings is not a valid directory.
[Info  - 2:47:24 PM] Assuming Python version 3.9
[Info  - 2:47:24 PM] Assuming Python platform Linux
Search paths for /home/adrian/dev/vscode-python-roots-test/plugins
  /home/adrian/.vscode-server-insiders/extensions/ms-python.vscode-pylance-2021.7.5-pre.1/dist/typeshed-fallback/stdlib
  /home/adrian/dev/vscode-python-roots-test/plugins
  /home/adrian/dev/vscode-python-roots-test/mainproject
  /home/adrian/dev/vscode-python-roots-test/plugins/typings
  /home/adrian/.vscode-server-insiders/extensions/ms-python.vscode-pylance-2021.7.5-pre.1/dist/typeshed-fallback/stubs/...
  /home/adrian/.vscode-server-insiders/extensions/ms-python.vscode-pylance-2021.7.5-pre.1/dist/bundled/stubs
  /home/adrian/.pyenv/versions/3.9.6/lib/python3.9
  /home/adrian/.pyenv/versions/3.9.6/lib/python3.9/lib-dynload
  /home/adrian/dev/vscode-python-roots-test/.venv/lib/python3.9/site-packages
  /home/adrian/dev/vscode-python-roots-test/plugins/a
  /home/adrian/dev/vscode-python-roots-test/mainproject
[Warn  - 2:47:24 PM] Exception received when installing recursive file system watcher: TypeError [ERR_FEATURE_UNAVAILABLE_ON_PLATFORM]: The feature watch recursively is unavailable on the current platform, which is being used to run Node.js
[Warn  - 2:47:24 PM] Exception received when installing recursive file system watcher: TypeError [ERR_FEATURE_UNAVAILABLE_ON_PLATFORM]: The feature watch recursively is unavailable on the current platform, which is being used to run Node.js
[Warn  - 2:47:24 PM] Exception received when installing recursive file system watcher: TypeError [ERR_FEATURE_UNAVAILABLE_ON_PLATFORM]: The feature watch recursively is unavailable on the current platform, which is being used to run Node.js
[Info  - 2:47:24 PM] Searching for source files
[Info  - 2:47:24 PM] Found 2 source files
Background analysis message: setConfigOptions
Background analysis message: ensurePartialStubPackages
Background analysis message: analyze
Background analysis message: setTrackedFiles
Background analysis message: markAllFilesDirty
Background analysis message: analyze
[BG(1)] parsing: /home/adrian/dev/vscode-python-roots-test/mainproject/setup.py [fs read 0ms] (18ms)
[BG(2)] parsing: /home/adrian/dev/vscode-python-roots-test/plugins/a/setup.py [fs read 1ms] (14ms)
[BG(1)] parsing: /home/adrian/.vscode-server-insiders/extensions/ms-python.vscode-pylance-2021.7.5-pre.1/dist/typeshed-fallback/stdlib/builtins.pyi [fs read 2ms] (83ms)
[BG(2)] parsing: /home/adrian/.vscode-server-insiders/extensions/ms-python.vscode-pylance-2021.7.5-pre.1/dist/typeshed-fallback/stdlib/builtins.pyi [fs read 2ms] (77ms)
[Info  - 2:47:24 PM] Indexer background runner(3) root directory: /home/adrian/.vscode-server-insiders/extensions/ms-python.vscode-pylance-2021.7.5-pre.1/dist
[Info  - 2:47:24 PM] Indexing(3) started
[BG(1)] binding: /home/adrian/.vscode-server-insiders/extensions/ms-python.vscode-pylance-2021.7.5-pre.1/dist/typeshed-fallback/stdlib/builtins.pyi (38ms)
[BG(1)] binding: /home/adrian/dev/vscode-python-roots-test/mainproject/setup.py (0ms)
[BG(1)] indexing: /home/adrian/dev/vscode-python-roots-test/mainproject/setup.py [found 0] (1ms)
Indexing Done: /home/adrian/dev/vscode-python-roots-test/mainproject/setup.py
[BG(1)] parsing: /home/adrian/dev/vscode-python-roots-test/mainproject/main_project/__init__.py [fs read 1ms] (2ms)
[BG(1)] binding: /home/adrian/dev/vscode-python-roots-test/mainproject/main_project/__init__.py (0ms)
[BG(1)] indexing: /home/adrian/dev/vscode-python-roots-test/mainproject/main_project/__init__.py [found 2] (0ms)
Indexing Done: /home/adrian/dev/vscode-python-roots-test/mainproject/main_project/__init__.py
[BG(2)] binding: /home/adrian/.vscode-server-insiders/extensions/ms-python.vscode-pylance-2021.7.5-pre.1/dist/typeshed-fallback/stdlib/builtins.pyi (37ms)
[BG(2)] binding: /home/adrian/dev/vscode-python-roots-test/plugins/a/setup.py (0ms)
[BG(2)] indexing: /home/adrian/dev/vscode-python-roots-test/plugins/a/setup.py [found 0] (1ms)
Indexing Done: /home/adrian/dev/vscode-python-roots-test/plugins/a/setup.py
[BG(2)] parsing: /home/adrian/dev/vscode-python-roots-test/plugins/a/test_plugin_a/__init__.py [fs read 1ms] (3ms)
[BG(2)] binding: /home/adrian/dev/vscode-python-roots-test/plugins/a/test_plugin_a/__init__.py (0ms)
[BG(2)] indexing: /home/adrian/dev/vscode-python-roots-test/plugins/a/test_plugin_a/__init__.py [found 0] (0ms)
Indexing Done: /home/adrian/dev/vscode-python-roots-test/plugins/a/test_plugin_a/__init__.py
[Info  - 2:47:24 PM] Indexer background runner(4) root directory: /home/adrian/.vscode-server-insiders/extensions/ms-python.vscode-pylance-2021.7.5-pre.1/dist
[Info  - 2:47:24 PM] Indexing(4) started
[IDX(3)] index libraries /home/adrian/dev/vscode-python-roots-test/mainproject ...
[IDX(3)]   read stdlib indices (77ms)
[IDX(4)] index libraries /home/adrian/dev/vscode-python-roots-test/plugins ...
[IDX(4)]   read stdlib indices (75ms)
[IDX(3)]   scan packages [found 15 modules over 1 exec env] (139ms)
[IDX(3)]   index execution environment /home/adrian/dev/vscode-python-roots-test/mainproject ...
[IDX(3)]     parsing: /home/adrian/.vscode-server-insiders/extensions/ms-python.vscode-pylance-2021.7.5-pre.1/dist/typeshed-fallback/stubs/setuptools/pkg_resources/__init__.pyi [fs read 1ms] (44ms)
[IDX(4)]   scan packages [found 16 modules over 1 exec env] (142ms)
[IDX(3)]     parsing: /home/adrian/.vscode-server-insiders/extensions/ms-python.vscode-pylance-2021.7.5-pre.1/dist/typeshed-fallback/stdlib/builtins.pyi [fs read 1ms] (45ms)
[IDX(3)]     binding: /home/adrian/.vscode-server-insiders/extensions/ms-python.vscode-pylance-2021.7.5-pre.1/dist/typeshed-fallback/stdlib/builtins.pyi (8ms)
[IDX(3)]     binding: /home/adrian/.vscode-server-insiders/extensions/ms-python.vscode-pylance-2021.7.5-pre.1/dist/typeshed-fallback/stubs/setuptools/pkg_resources/__init__.pyi (2ms)
[IDX(3)]     indexing: /home/adrian/.vscode-server-insiders/extensions/ms-python.vscode-pylance-2021.7.5-pre.1/dist/typeshed-fallback/stubs/setuptools/pkg_resources/__init__.pyi [found 70] (1ms)
[IDX(3)]     parsing: /home/adrian/.pyenv/versions/3.9.6/lib/python3.9/xml/__init__.py [fs read 1ms] (6ms)
[IDX(3)]     binding: /home/adrian/.pyenv/versions/3.9.6/lib/python3.9/xml/__init__.py (0ms)
[IDX(3)]     indexing: /home/adrian/.pyenv/versions/3.9.6/lib/python3.9/xml/__init__.py [found 0] (0ms)
[IDX(3)]     parsing: /home/adrian/dev/vscode-python-roots-test/.venv/lib/python3.9/site-packages/pip/__init__.py [fs read 0ms] (0ms)
[IDX(3)]     binding: /home/adrian/dev/vscode-python-roots-test/.venv/lib/python3.9/site-packages/pip/__init__.py (0ms)
[IDX(3)]     indexing: /home/adrian/dev/vscode-python-roots-test/.venv/lib/python3.9/site-packages/pip/__init__.py [found 2] (0ms)
[IDX(4)]   index execution environment /home/adrian/dev/vscode-python-roots-test/plugins ...
[IDX(4)]     parsing: /home/adrian/.vscode-server-insiders/extensions/ms-python.vscode-pylance-2021.7.5-pre.1/dist/typeshed-fallback/stubs/setuptools/pkg_resources/__init__.pyi [fs read 1ms] (47ms)
[IDX(3)]     parsing: /home/adrian/dev/vscode-python-roots-test/.venv/lib/python3.9/site-packages/setuptools/__init__.py [fs read 0ms] (11ms)
[IDX(3)]     binding: /home/adrian/dev/vscode-python-roots-test/.venv/lib/python3.9/site-packages/setuptools/__init__.py (1ms)
[IDX(3)]     indexing: /home/adrian/dev/vscode-python-roots-test/.venv/lib/python3.9/site-packages/setuptools/__init__.py ...
[IDX(3)]       parsing: /home/adrian/dev/vscode-python-roots-test/.venv/lib/python3.9/site-packages/setuptools/_deprecation_warning.py [fs read 0ms] (1ms)
[IDX(3)]       binding: /home/adrian/dev/vscode-python-roots-test/.venv/lib/python3.9/site-packages/setuptools/_deprecation_warning.py (0ms)
[IDX(3)]       parsing: /home/adrian/dev/vscode-python-roots-test/.venv/lib/python3.9/site-packages/setuptools/extension.py [fs read 0ms] (1ms)
[IDX(3)]       binding: /home/adrian/dev/vscode-python-roots-test/.venv/lib/python3.9/site-packages/setuptools/extension.py (0ms)
[IDX(3)]       parsing: /home/adrian/dev/vscode-python-roots-test/.venv/lib/python3.9/site-packages/setuptools/dist.py [fs read 0ms] (27ms)
[IDX(3)]       binding: /home/adrian/dev/vscode-python-roots-test/.venv/lib/python3.9/site-packages/setuptools/dist.py (1ms)
[IDX(3)]       parsing: /home/adrian/dev/vscode-python-roots-test/.venv/lib/python3.9/site-packages/setuptools/depends.py [fs read 0ms] (4ms)
[IDX(3)]       binding: /home/adrian/dev/vscode-python-roots-test/.venv/lib/python3.9/site-packages/setuptools/depends.py (0ms)
[IDX(3)]     indexing: /home/adrian/dev/vscode-python-roots-test/.venv/lib/python3.9/site-packages/setuptools/__init__.py [found 8] (34ms)
[IDX(3)]   index execution environment /home/adrian/dev/vscode-python-roots-test/mainproject [found 7937 in 408 files] (155ms)
[IDX(3)] index libraries /home/adrian/dev/vscode-python-roots-test/mainproject [found 7937 in 1 exec envs] (372ms)
[Info  - 2:47:24 PM] Indexer done(3). indexed 408 files
[IDX(4)]     parsing: /home/adrian/.vscode-server-insiders/extensions/ms-python.vscode-pylance-2021.7.5-pre.1/dist/typeshed-fallback/stdlib/builtins.pyi [fs read 1ms] (44ms)
[IDX(4)]     binding: /home/adrian/.vscode-server-insiders/extensions/ms-python.vscode-pylance-2021.7.5-pre.1/dist/typeshed-fallback/stdlib/builtins.pyi (9ms)
[IDX(4)]     binding: /home/adrian/.vscode-server-insiders/extensions/ms-python.vscode-pylance-2021.7.5-pre.1/dist/typeshed-fallback/stubs/setuptools/pkg_resources/__init__.pyi (1ms)
[IDX(4)]     indexing: /home/adrian/.vscode-server-insiders/extensions/ms-python.vscode-pylance-2021.7.5-pre.1/dist/typeshed-fallback/stubs/setuptools/pkg_resources/__init__.pyi [found 70] (1ms)
[IDX(4)]     parsing: /home/adrian/.pyenv/versions/3.9.6/lib/python3.9/xml/__init__.py [fs read 1ms] (5ms)
[IDX(4)]     binding: /home/adrian/.pyenv/versions/3.9.6/lib/python3.9/xml/__init__.py (0ms)
[IDX(4)]     indexing: /home/adrian/.pyenv/versions/3.9.6/lib/python3.9/xml/__init__.py [found 0] (0ms)
[IDX(4)]     parsing: /home/adrian/dev/vscode-python-roots-test/.venv/lib/python3.9/site-packages/pip/__init__.py [fs read 0ms] (1ms)
[IDX(4)]     binding: /home/adrian/dev/vscode-python-roots-test/.venv/lib/python3.9/site-packages/pip/__init__.py (0ms)
[IDX(4)]     indexing: /home/adrian/dev/vscode-python-roots-test/.venv/lib/python3.9/site-packages/pip/__init__.py [found 2] (0ms)
[IDX(4)]     parsing: /home/adrian/dev/vscode-python-roots-test/.venv/lib/python3.9/site-packages/setuptools/__init__.py [fs read 0ms] (10ms)
[IDX(4)]     binding: /home/adrian/dev/vscode-python-roots-test/.venv/lib/python3.9/site-packages/setuptools/__init__.py (1ms)
[IDX(4)]     indexing: /home/adrian/dev/vscode-python-roots-test/.venv/lib/python3.9/site-packages/setuptools/__init__.py ...
[IDX(4)]       parsing: /home/adrian/dev/vscode-python-roots-test/.venv/lib/python3.9/site-packages/setuptools/_deprecation_warning.py [fs read 0ms] (0ms)
[IDX(4)]       binding: /home/adrian/dev/vscode-python-roots-test/.venv/lib/python3.9/site-packages/setuptools/_deprecation_warning.py (1ms)
[IDX(4)]       parsing: /home/adrian/dev/vscode-python-roots-test/.venv/lib/python3.9/site-packages/setuptools/extension.py [fs read 0ms] (1ms)
[IDX(4)]       binding: /home/adrian/dev/vscode-python-roots-test/.venv/lib/python3.9/site-packages/setuptools/extension.py (0ms)
[IDX(4)]       parsing: /home/adrian/dev/vscode-python-roots-test/.venv/lib/python3.9/site-packages/setuptools/dist.py [fs read 0ms] (24ms)
[IDX(4)]       binding: /home/adrian/dev/vscode-python-roots-test/.venv/lib/python3.9/site-packages/setuptools/dist.py (0ms)
[IDX(4)]       parsing: /home/adrian/dev/vscode-python-roots-test/.venv/lib/python3.9/site-packages/setuptools/depends.py [fs read 0ms] (3ms)
[IDX(4)]       binding: /home/adrian/dev/vscode-python-roots-test/.venv/lib/python3.9/site-packages/setuptools/depends.py (0ms)
[IDX(4)]     indexing: /home/adrian/dev/vscode-python-roots-test/.venv/lib/python3.9/site-packages/setuptools/__init__.py [found 8] (30ms)
[IDX(4)]   index execution environment /home/adrian/dev/vscode-python-roots-test/plugins [found 7937 in 408 files] (154ms)
[IDX(4)] index libraries /home/adrian/dev/vscode-python-roots-test/plugins [found 7937 in 1 exec envs] (372ms)
[Info  - 2:47:24 PM] Indexer done(4). indexed 408 files

and the log from when I use ctrl-period to attempt to generate the import via code actions:

Background analysis message: getDiagnosticsForRange

from ctrl-space for autocompletion:

[FG] completion at /home/adrian/dev/vscode-python-roots-test/plugins/a/test_plugin_a/__init__.py:0:13 [found 0 items] (5ms)

Code Snippet / Additional information

Here's a Git repo with my minimal example project where I tested it: https://github.com/ThiefMaster/vscode-python-roots-test

As you can see in the workspace settings, I already tried using the python.*.extraPaths options, but to no avail. I also installed both of the packages in the Python virtualenv via pip install -e ... in case it made a difference - but nope.

In my main project I have indexing enabled btw, but it doesn't seem to make a difference.

@jakebailey
Copy link
Member

It sounds like you're describing #1055. If you haven't already imported the file from your workspace (either directly or via some other file), then we won't have analyzed the file, so won't suggest anything. The indexer is currently disabled for user code except in the case of quick fixes, which is #1055, so having the file already be analyzed is what makes it work.

@judej judej added the waiting for user response Requires more information from user label Jul 22, 2021
@github-actions github-actions bot removed the triage label Jul 22, 2021
@jakebailey
Copy link
Member

Can you try opening that file you want auto-imports from, then see if the auto import works in the other file?

@ThiefMaster
Copy link
Author

I'm pretty sure that was already the case when I tested it earlier today - but I just tested again and I didn't get the completions suggested either..

image

@jakebailey jakebailey added needs investigation Could be an issue - needs investigation and removed waiting for user response Requires more information from user labels Jul 23, 2021
@ThiefMaster
Copy link
Author

Did you already have the opportunity to have a closer look into this problem?

@xiaolongjiangkolena
Copy link

I am having the same issue also

@heejaechang heejaechang self-assigned this Apr 11, 2022
@heejaechang
Copy link
Contributor

heejaechang commented Apr 19, 2022

@ThiefMaster assuming you have indexing option set "python.analysis.indexing": true in settings.json, if you open "vscode-python-roots-test" as root folder, you will see code actions for add imports.

image

we currently don't show symbols defined in user files in completion to reduce number of items in the completion.

in case you are using multi root workspace with pip install -e, we only supports top level symbols by default in completion. you will need to use our hidden options in settings.json to make us to discover symbols in sub modules.

see this #2312 (comment)

@heejaechang
Copy link
Contributor

I also opened this issue to improve multi root workspace UX - #2601

@heejaechang heejaechang removed the needs investigation Could be an issue - needs investigation label Apr 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants