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

Auto import feature doesn't work properly #2312

Closed
bootstrap123002 opened this issue Feb 1, 2022 · 11 comments
Closed

Auto import feature doesn't work properly #2312

bootstrap123002 opened this issue Feb 1, 2022 · 11 comments
Assignees
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version P2

Comments

@bootstrap123002
Copy link

I want to get the auto-import hint when inputing an Class or Function defined in another module. But pylance don't give the correct hint.
In this case,I want to get the quick fixes suggestion for 'DictCursor' defined in the 'cursors.py' of pymysql package. Bud the amazing thing is when I reload the window ,it will give the correct hint whit quick fixes in a few seconds,and soon disappeared.
After review the trace output of pylance,the 'cursors.py' has been parsed.
(99398) [BG(1)] parsing: /Users/python/vscode/vscode/venv/lib/python3.9/site-packages/pymysql/cursors.py [fs read 0ms] (9ms)
(99398) [BG(1)] binding: /Users/python/vscode/vscode/venv/lib/python3.9/site-packages/pymysql/cursors.py (4ms)
What happened,is there any configuration should be setup?

2022-02-01.11.51.54.mov
@github-actions github-actions bot added the triage label Feb 1, 2022
@judej judej added the needs investigation Could be an issue - needs investigation label Feb 1, 2022
@github-actions github-actions bot removed the triage label Feb 1, 2022
@heejaechang
Copy link
Contributor

it looks like a bug. thank you for reporting the issue!

@heejaechang heejaechang added the bug Something isn't working label Feb 2, 2022
@bootstrap123002
Copy link
Author

bootstrap123002 commented Feb 2, 2022 via email

@luabud luabud added the P2 label Mar 1, 2022
@heejaechang
Copy link
Contributor

heejaechang commented Mar 11, 2022

so, it is happening since DictCursor is not in __ all __ nor there is pyi file. and it is not py.typed package. so we don't know whether it is a part of public API or not. so we dropped it.

@heejaechang heejaechang removed the needs investigation Could be an issue - needs investigation label Mar 11, 2022
@heejaechang
Copy link
Contributor

Since we don't want to bloat completion with bunch of symbols, I dont think we want to enable it by default, but I added a hidden option as an escape patch.

Basically, if one adds this to setting.json, we will treat the package special and scan more symbols from it.

"python.analysis.packageIndexDepths": [[packageName: string, depth: number, forceIndexing: boolean]*],

ex)

"python.analysis.packageIndexDepths": [["pymysql", 3, true]],

packageName is the name of the package, depth means how deep the scanner will scan, forceIndexing means it will include all symbols in the py file discovered regardless of __ all __ or py.typed.

@heejaechang heejaechang added the fixed in next version (main) A fix has been implemented and will appear in an upcoming version label Mar 12, 2022
@bschnurr
Copy link
Member

This issue has been fixed in version 2022.3.2, which we've just released. You can find the changelog here: CHANGELOG.md

@cdce8p
Copy link

cdce8p commented Mar 17, 2022

"python.analysis.packageIndexDepths": [["pymysql", 3, true]],

@heejaechang That is awesome! Would something similar work for workspace files too? I keep having issues where auto-import / suggestions don't work or symbols aren't found. Even with "python.analysis.indexing": true.
Would love an option to say Pylance "always index these core and helper modules + constants file".

The project I currently work on usually doesn't use __all__ and hasn't added py.typed yet since we are still in the process of adding all full type annotations.

With indexing: true I also get a warning.

Workspace indexing has hit its upper limit: 2000 files

A somewhat related issue: #1055

@heejaechang
Copy link
Contributor

@cdce8p the option should work with multiroot workspace as long as root is installed with pip install -e ...

but that being said, I opened this issue to track UX on multiroot workspace - #2601

@ajlive
Copy link

ajlive commented Jun 28, 2022

Is there any way to use the packageIndexDepths workaround without specifying the package? The inability to get auto-imports for most of the third-party packages I use is frustrating, and I don't want to have to configure these package by package.

@bschnurr
Copy link
Member

for default 3 levels I believe this is it:

"python.analysis.packageIndexDepths": [
	["",3]
],

@ajlive
Copy link

ajlive commented Jun 28, 2022

Thanks, that works!

@rustam-ashurov-mcx
Copy link

Using normal VS code (not Insiders) with this config in settings.json gives me: an "Unknown Configuration Setting" popup in VS Code and the config line looks gray-out. Also can not say that it fixes anything for me.
Do I need to install anything more/else than the latest VS Code + Python/Pylance extensions to make it work for me?

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 P2
Projects
None yet
Development

No branches or pull requests

8 participants