1

Pylance, and IntelliSense work fine with default modules, let's say, os or datetime or so, but I've installed aiogram (any 'custom' modules have the same issues in VScode) and use some classes from it as here enter image description here

vscode doesn't see where to import it from... so they are in aiogram.types and I should manually type that from aiogram.types import InlineKeyboarMarup every time. I've tried import magic - no changes... Pylance has settings for auto import suggestions and as I said it works fine ONLY with default modules, no question, every installed module - get that problem. please help, don't want to use PyCharm, hope a solution is somewhere

J_cyber
  • 62
  • 5
OM26R
  • 127
  • 1
  • 9
  • Can [this](https://github.com/microsoft/pylance-release/issues/3324) help? It seems that automatic import can only be started after method has been imported. – MingJie-MSFT Sep 20 '22 at 01:51
  • @MingJie-MSFT no, it doesn't help. They're talking about issues with users modules or so, but I'm using module installed via pip. I've tried "python.analysis.indexing":true, enabling and disabling extensions with no result. PyCharm doesn't have such problems. – OM26R Sep 28 '22 at 07:10
  • I have exacctllly the same problem. I exactly don't want to use Pycharm because it is slow and bulky – Bashir Abdelwahed Oct 23 '22 at 14:45
  • @BashirAbdelwahed there a fix down below – OM26R Nov 26 '22 at 19:19
  • Yes I used it and it worked – Bashir Abdelwahed Nov 28 '22 at 13:30

1 Answers1

2

Add the following code(This is a hidden content) to your settings.json:

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

What it basically means is ["package name", "max depth to search"]. "max depth" basically means how many dot you need to access the module you want. Deeper you go, Pylance will take more time to scan python files.

InlineKeyboarMarup is a deep method. Usually, pylance will only retrieve the methods in the first level directory.

MingJie-MSFT
  • 5,569
  • 1
  • 2
  • 13
  • thanks, it works. But for some reason that lines of code are color faded in json file and have hint `Unknown Configuration Setting` , is it ok? And I still have problems with other imports, for example `FSMContext` I have to type manualy `from aiogram.fsm.context import FSMContext` , so here I have 2 dots then I have to change that number in your setting from 2 to 3, haven't I? – OM26R Sep 28 '22 at 10:46
  • I've changed `"python.analysis.packageIndexDepths"` from 2 to 3 and now I see that `FSMContent` even when I type that as agrument of fucntion... I hope it's a good practice without any issues with working on a big project. Do you have any problems with CPU, memory or so by using such settings? Don't know why PyCharm has it from start but VSCode see nothing from start – OM26R Sep 28 '22 at 10:53
  • And I found this _"that's because it is hidden option yet. we might change the name when we make it a official public option. for now, it is hidden option."_ - it's about that color fade and a hint about unknown configuration. Don't know what does it mean, maybe a kind of beta version of something. So before nobody had such features in VSCode? – OM26R Sep 28 '22 at 11:11
  • @OM26R It has been grayed out in recent versions, which may be because it is a hidden option and does not really want to be used. Vscode itself is a lightweight editing software, and this setting will take up a lot of memory – MingJie-MSFT Sep 29 '22 at 01:42