Only top level suggestions are offered for auto imports #2681
Replies: 13 comments
-
The extension brainfit.vscode-importmagic can resolve imports correctly. |
Beta Was this translation helpful? Give feedback.
-
By design we only offer top level suggestions for auto imports, except for a number of popular packages. This was a perf trade off. In the future we could address this issue by making the levels configurable. For now we will wait for up votes on this issue |
Beta Was this translation helpful? Give feedback.
-
Would be great to customize :D |
Beta Was this translation helpful? Give feedback.
-
Is there any fix/hack for the moment? |
Beta Was this translation helpful? Give feedback.
-
currently there is no workaround. |
Beta Was this translation helpful? Give feedback.
-
Would also like this, I'm often frustrated by auto imports (sometimes they work, sometimes they don't, it feels a bit arbitrary). Edit: Ah, apparently you're already on it #2069 😁 |
Beta Was this translation helpful? Give feedback.
-
@bschnurr Hi! Where I can vote for the feature? It's useless when autocomplete/import ignores packages installed in the venv. |
Beta Was this translation helpful? Give feedback.
-
I think this should be stated more obviously in the readme. I read "auto import" in the readme and spent half an hour trying to 'fix' my VS Code, venv, etc... setup, because i could only get the It took me a while to get here to find out, that auto import only works on arbitrary packages. As there might be more people like me, you might get less 'bug' reports on this feature, if this is stated more clearly in the readme. |
Beta Was this translation helpful? Give feedback.
-
fyi to override the default indexing add this to your settings.json
|
Beta Was this translation helpful? Give feedback.
-
Great! Thanks @bschnurr, could you please add some description? |
Beta Was this translation helpful? Give feedback.
-
see #2533 (comment) |
Beta Was this translation helpful? Give feedback.
-
looks like there is still and issue possibly due do to |
Beta Was this translation helpful? Give feedback.
-
YMMV but it seems that the default indexing isn't deep enough for auto-import to work when the function or class you import is not at the root level, so here's what I had to put in my settings.json for it to work properly: {
"python.analysis.autoImportCompletions": true,
"python.analysis.indexing": true,
"python.analysis.packageIndexDepths": [
{
"name": "",
"depth": 3
},
]
} |
Beta Was this translation helpful? Give feedback.
-
VS Code version
1.62.2
Extension version
v2021.11.1422169775
OS type
Linux
OS version
Ubuntu 20.04.3
Python distribution
python.org
Python version
3.9.2
Language server
Pylance
Expected behaviour
I would expect vs code to suggest imports from venvs.
If you want to install a package on the venv, for example discord.py, and then import, for example,
commands.Bot
from discord.ext, press Ctrl +. tocommands
.I would expect the import
from discord.ext import commands
to be suggested, but it is not.Actual behaviour
Any other import found is suggested, but not from packages in venv.
This also doesn't work with auto-imports.
Steps to reproduce
python -m venv venv source venv/bin/activate pip install discord.py
Create Python file:
commands
is not defined so try to import it...If it works, the problem is mine
Logs
I think this line is relevant:
[Info - 18:57:41] Auto-excluding /home/user/project/venv
Code of Conduct
Beta Was this translation helpful? Give feedback.
All reactions