Closed rbhanot4739 closed 2 years ago
Showing auto import entries in completion is expensive operation. so we won't scan and show everything. we do not want to show completion with a few thousands entries for every possible match in every possible packages installed.
so by default, we only show as small as we can. basically we only show ones user already used in some way, and nothing new. and only third party packages will be shown in completion, user types will be only in code action.
but we do provide knobs for users as long as they accept the perf hit.
First knob is the "python.analysis.indexing", if user turns it on, we will spend more time to analyze packages, user files before-hand to build indexing. that will make more items to show up in completion and code actions.
but, if that is not enough, you can add this hidden option to your settings.json. see this comment - https://github.com/microsoft/pylance-release/issues/2991#issuecomment-1176560066
after that, you should be able to see all types defined in packages.
by the way, Workspace indexing has hit its upper limit: 2000 files
this is for user files. so for your case, this shouldn't matter.
by the way, did you select right interpreter that has all packages installed?
@heejaechang for the response, yeah I have selected the right interpreter and it has all the packages installed.
so by default, we only show as small as we can. basically we only show ones user already used in some way, and nothing new. and only third party packages will be shown in completion, user types will be only in code action.
The issue for me is that third party packages are not being shown in the completion list unless i turn on the indexing with python.analysis.indexing: true
. And even after turning on the hidden option "python.analysis.packageIndexDepths":[["",20, true]]
still I don't see all of the relevant entries in the completion, i.e. for my my specific case, I don't see Request
completion entry from flask
, starlette
; even though you might never have these two packages in a single project but I am just trying to highlight namespace collision here.
I also checked the https://github.com/microsoft/pylance-release/issues/2991#issuecomment-1176560066 where you mentioned for library packages only the toplevel symbols are being shown in completion list, so even though the Request
module in import in the __init__.py
of flask package it still does not show in the completion list.
Let me know if you need more details to troubleshoot more on this.
by the way, Workspace indexing has hit its upper limit: 2000 files this is for user files. so for your case, this shouldn't matter.
Does that mean this limit is only for workspace source files only ?
so, it works for me as you can see below.
for me, flask works only with "python.analysis.indexing" on, for startlette, need hidden option to include all symbols for me.
just to be clear, if you had everything on, did you wait for indexing to actually finish? you should have something like this in "Python Language Server" output pane.
[Info - 10:55:41 PM] (60736) Indexing(3) started
[Info - 10:56:13 PM] (60736) [IDX(3)] Long operation: index execution environment e:\python (29964ms)
[Info - 10:56:13 PM] (60736) [IDX(3)] Long operation: index libraries e:\python (32082ms)
[Info - 10:56:13 PM] (60736) Indexer done(3). indexed 1450 files
Does that mean this limit is only for workspace source files only ?
It means that limitation is for files under your opened folders, not ones in site-packages (such as ones in venv).
by the way, if "python.analysis.packageIndexDepths":[["",20, true]]
takes too long to index (for me, it took about 30 seconds to index everything in site-packages), you can put explicit package name at the hidden option and how deep you want to scan.
"python.analysis.packageIndexDepths":[["package name
", number of level to scan
, include all symbols
]]
package name
- ex) flask, starlette
number of level to scan
- ex) 1 will scan only starlette, 2 will scan starlette.requests and so on.
include all symbols
- ex) true
will put every top level symbols in the module to indices, false
will only put symbols that appear in __all__
to indicies.
ex) "python.analysis.packageIndexDepths":[["flask", 1, false], ["starlette", 2, true]]
Does the indexer runs every-time I launch vscode or it indexes the packages and stores somewhere unless the sources change ?
it launches every time, and that is the reason we limit it by default and user has to explicitly opt-in.
we do considered caching but for now, decided not to do it due to all the complication comes from caching. but we might do it in future, but not now.
So I have set this "python.analysis.packageIndexDepths": [["",20, true]]
just to test and I still don't see flask or starlette.
And yes the indexer did complete
[Info - 11:57:08 AM] (67691) Indexing(5) started
[Info - 11:57:12 AM] (67691) [IDX(5)] Long operation: index execution environment /Users/rbhanot/dummy_projecte (2747ms)
[Info - 11:57:12 AM] (67691) [IDX(5)] Long operation: index libraries /Users/rbhanot/dummy_projecte (3709ms)
[Info - 11:57:12 AM] (67691) Indexer done(5). indexed 1162 files
Okay it shows for flask now but still starlette imports won't show.
can you provide logs with "python.analysis.logLevel": "Trace"?
that should give us info on what files are indexed.
Here is the log file logs.txt
I see this - (74407) [IDX(2)] indexing: /Users/rbhanot/development/personal/self-learning/venv/lib/python3.10/site-packages/starlette/requests.py [found 21] (1ms)
so, it is indexed. so, should be there.
can you try this "python.analysis.packageIndexDepths": [["starlette",3, true]] ? and see whether it shows up?
No it still doesn't show up even though the file is being indexed
(2984) [IDX(2)] parsing: /Users/rbhanot/.vscode/extensions/ms-python.vscode-pylance-2022.8.51/dist/typeshed-fallback/stdlib/http/__init__.pyi [fs read 1ms] (1ms)
(2984) [IDX(2)] binding: /Users/rbhanot/.vscode/extensions/ms-python.vscode-pylance-2022.8.51/dist/typeshed-fallback/stdlib/http/__init__.pyi (0ms)
(2984) [IDX(2)] indexing: /Users/rbhanot/development/personal/self-learning/venv/lib/python3.10/site-packages/starlette/requests.py [found 21] (1ms)
This is what settings look "python.analysis.packageIndexDepths": [ [ "", 20, true ], [ "starlette", 3, true ] ],
remove this [ "", 20, true ],
part
I tried that as well and still same thing, the starlette requests surely gets indexed as evident from logs
(28680) [IDX(2)] parsing: /Users/rbhanot/.vscode/extensions/ms-python.vscode-pylance-2022.9.11/dist/typeshed-fallback/stdlib/http/__init__.pyi [fs read 0ms] (1ms)
(28680) [IDX(2)] binding: /Users/rbhanot/.vscode/extensions/ms-python.vscode-pylance-2022.9.11/dist/typeshed-fallback/stdlib/http/__init__.pyi (0ms)
(28680) [IDX(2)] indexing: /Users/rbhanot/development/personal/self-learning/venv/lib/python3.10/site-packages/starlette/requests.py [found 21] (1ms)
And this is how "python.analysis.packageIndexDepths": [[ "starlette", 3, true ] ]` looks now and this is what I see now
Any further update on this ?
I doesn't repro for me, can you share zip file that has python files that let me repro the issue? the log said, it is indexed, and it works for me when I try locally, so it might be something that we don't know affecting the completion, but without live repro, hard to figure out.
please, reopen if it still happens.
@rbhanot4739 You might want to add this line to settings.json
as well:
"python.analysis.autoImportCompletions": true
To me, these settings fix it:
"python.analysis.autoImportCompletions": true,
"python.autoComplete.extraPaths": ["${workspaceFolder}/src"],
"python.analysis.extraPaths": ["${workspaceFolder}/src"],
"python.analysis.indexing": true,
"python.analysis.packageIndexDepths": [
{ "name": "", "depth": 20, "includeAllSymbols": true }
]
Environment data
Code Snippet
Repro Steps
fastapi
,request
andflask
packages for testing purposes.Req
this should trigger auto-completion popup and observe the suggestion, it does not show all the classes which have name starting with wordRequest
Expected behavior
When I type
Req
I should see all entries which have name starting with wordRequest
in the suggestions popup, for example in my case I have these packagesfastapi
,request
andflask
insite-packages
directory and so I should be able to see atleast 3 entries withRequest
as each of these packages haveRequest
class.Actual behavior
Pylance only shows the auto-complete entries from from standard lib packages only which are at this path
<system_python_path>/lib/python3.10/
and does not include packages fromsite-packages
directory.I have also tried by adding
site-packages
path topython.analysis.extraPath
but that did not help. Enabling thepython.analysis.indexing
starts to show few more entries but for larger projects it creates another issue ofWorkspace indexing has hit its upper limit: 2000 files
and so again you don't see the expected result.Logs