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

Autocomplete in imports doesn't work when we have packages that are symlinks #1031

Closed
wesleybl opened this issue Mar 11, 2021 · 19 comments
Closed
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@wesleybl
Copy link

Environment data

  • Language Server version: 2021.3.1
  • OS and version: Ubuntu 18.04
  • Python version (& distribution if applicable, e.g. Anaconda): 3.6.9

Expected behaviour

Fill the configuration in settings.json:

"python.analysis.extraPaths": ["/home/user/lib"],

Packages inside /home/user/lib are symlinks to real path.

Type in the code:

from my

I hope the autocomplete will suggest all packages that start with my inside the /home/user/lib folder.

Actual behaviour

The autocomplete doesn't suggest packages inside the /home/user/lib folder .

Logs

Background analysis message: setFileOpened
Background analysis message: markFilesDirty
[FG] completion at /home/wesleybl/symbolic.package/src/symbolic/package/__init__.py:1:6 ...
[FG]   parsing: /home/wesleybl/symbolic.package/src/symbolic/package/__init__.py (0ms)
[FG]   binding: /home/wesleybl/symbolic.package/src/symbolic/package/__init__.py (0ms)
[FG] completion at /home/wesleybl/symbolic.package/src/symbolic/package/__init__.py:1:6 [found 74 items] (6ms)
Background analysis message: getDiagnosticsForRange
Background analysis message: getDiagnosticsForRange
Background analysis message: getSemanticTokens
[BG(1)] parsing: /home/wesleybl/symbolic.package/src/symbolic/package/__init__.py (0ms)
[BG(1)] binding: /home/wesleybl/symbolic.package/src/symbolic/package/__init__.py (0ms)
Background analysis message: setFileOpened
Background analysis message: markFilesDirty
Background analysis message: analyze
[BG(1)] analyzing: /home/wesleybl/symbolic.package/src/symbolic/package/__init__.py ...
[BG(1)]   parsing: /home/wesleybl/symbolic.package/src/symbolic/package/__init__.py (1ms)
[BG(1)]   binding: /home/wesleybl/symbolic.package/src/symbolic/package/__init__.py (0ms)
[BG(1)]   checking: /home/wesleybl/symbolic.package/src/symbolic/package/__init__.py (0ms)
[BG(1)] analyzing: /home/wesleybl/symbolic.package/src/symbolic/package/__init__.py (1ms)
Background analysis message: resumeAnalysis
Background analysis message: getSemanticTokens
[FG] parsing: /home/wesleybl/symbolic.package/src/symbolic/package/__init__.py (1ms)
[FG] binding: /home/wesleybl/symbolic.package/src/symbolic/package/__init__.py (0ms)
Background analysis message: setFileOpened
Background analysis message: markFilesDirty
[FG] completion at /home/wesleybl/symbolic.package/src/symbolic/package/__init__.py:1:6 ...
[FG]   parsing: /home/wesleybl/symbolic.package/src/symbolic/package/__init__.py (0ms)
[FG]   binding: /home/wesleybl/symbolic.package/src/symbolic/package/__init__.py (1ms)
[FG] completion at /home/wesleybl/symbolic.package/src/symbolic/package/__init__.py:1:6 [found 74 items] (5ms)
Background analysis message: getDiagnosticsForRange
Background analysis message: getDiagnosticsForRange
Background analysis message: getSemanticTokens
[BG(1)] parsing: /home/wesleybl/symbolic.package/src/symbolic/package/__init__.py (1ms)
[BG(1)] binding: /home/wesleybl/symbolic.package/src/symbolic/package/__init__.py (1ms)
Background analysis message: setFileOpened
Background analysis message: markFilesDirty
[FG] completion at /home/wesleybl/symbolic.package/src/symbolic/package/__init__.py:1:7 ...
[FG]   parsing: /home/wesleybl/symbolic.package/src/symbolic/package/__init__.py (1ms)
[FG]   binding: /home/wesleybl/symbolic.package/src/symbolic/package/__init__.py (0ms)
[FG] completion at /home/wesleybl/symbolic.package/src/symbolic/package/__init__.py:1:7 [found 6 items] (4ms)
Background analysis message: analyze
[BG(1)] analyzing: /home/wesleybl/symbolic.package/src/symbolic/package/__init__.py ...
[BG(1)]   parsing: /home/wesleybl/symbolic.package/src/symbolic/package/__init__.py (1ms)
[BG(1)]   binding: /home/wesleybl/symbolic.package/src/symbolic/package/__init__.py (1ms)
[BG(1)]   checking: /home/wesleybl/symbolic.package/src/symbolic/package/__init__.py (0ms)
[BG(1)] analyzing: /home/wesleybl/symbolic.package/src/symbolic/package/__init__.py (2ms)
Background analysis message: getDiagnosticsForRange
Background analysis message: resumeAnalysis
Background analysis message: getDiagnosticsForRange
Background analysis message: getSemanticTokens
Background analysis message: getDiagnosticsForRange
Background analysis message: getDiagnosticsForRange

Code Snippet / Additional information

See:

autocomplete

In the figure, lib is a folder that is in python.analysis.extraPaths. my, inside the lib folder is a symbolic link to the real package.

I created a repository to simulate this:

https://github.com/wesleybl/symbolic.package

See:

https://github.com/wesleybl/symbolic.package#symbolicpackage

It appears that there has been an increase in support for symbolic links in:

microsoft/pyright#1607

But that didn’t solve the autocomplete problem.

@jakebailey @erictraut FYI

@jakebailey
Copy link
Member

Just to precheck, does the import itself work if you were to just say import my, or does only completion break for the module?

@wesleybl
Copy link
Author

wesleybl commented Mar 11, 2021

autocomplete doesn't work with import my. After typing it doesn't give a module not found error. The problem is only in the autocomplete.

@jakebailey
Copy link
Member

Thanks, that's very helpful.

@wesleybl
Copy link
Author

Oops I think I got it wrong. autocomplete doesn't work with import my

@jakebailey
Copy link
Member

As in when you write import my and then do my. you do not see the expected results? Or just that the autocompletion for import my fails?

@wesleybl
Copy link
Author

Typing import my doesn't give me the expected results, if my is a symbolic link. I fix my answer above.

@jakebailey
Copy link
Member

So long as no import resolution error happens (e.g. we find the module when manually specified), then things are still getting narrowed down to the completion provider, which is what I'm looking for. 🙂

@wesleybl
Copy link
Author

No import error occurs:

import

@judej judej added the needs investigation Could be an issue - needs investigation label Mar 11, 2021
@github-actions github-actions bot removed the triage label Mar 11, 2021
@jakebailey
Copy link
Member

This is a simple copy/paste error here: https://github.com/microsoft/pyright/blob/2eba7458eb38952822a144bb2e111b7c0d90ff72/packages/pyright-internal/src/common/pathUtils.ts#L600

If I fix it so that it's adding the directory to the directories list, things work as expected.

@jakebailey
Copy link
Member

This will be fixed in the next version of Pylance. Many thanks for the test case, it was very helpful!

@jakebailey jakebailey added bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version and removed needs investigation Could be an issue - needs investigation labels Mar 11, 2021
@wesleybl
Copy link
Author

Awesome! Thanks for the great work!

@jakebailey
Copy link
Member

This issue has been fixed in version 2021.3.2, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/main/CHANGELOG.md#202132-17-march-2021

@Hadatko
Copy link

Hadatko commented Apr 27, 2021

Pleace take look to this mine comment: microsoft/vscode-python#13198 (comment)

@jakebailey
Copy link
Member

@Hadatko Can you please file a new issue with your reproduction?

@Hadatko
Copy link

Hadatko commented Apr 28, 2021

Sure. Sorry.

@Hadatko
Copy link

Hadatko commented Apr 28, 2021

Sorry nevermind. Fixed with python.analysis.extraPaths

@Benkendorfer
Copy link

Hello, this is no longer working for me in v2023.09.30

It is not just autocomplete not working; Pylance is also throwing an import not resolved error. I have tried python.analysis.extraPaths to no avail

@wesleybl
Copy link
Author

@Benkendorfer I tested the symbolic link issue in version v2023.09.30 and autocomplete worked. You must have another problem. I suggest you open another issue detailing your problem in more detail.

@Benkendorfer
Copy link

Ok. I just started writing a new issue and when extracting the environment configuration I noticed that it is suddenly working now... if the problem appears again I will open a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version
Projects
None yet
Development

No branches or pull requests

5 participants