Language server does't offer autocomplete for functions in modules or packages that haven't been opened or loaded
This happens in vscode. The diagnostic mode is set to "workspace"
"basedpyright.analysis.diagnosticMode": "workspace"
I have an example project with 2 packages and 2 modules inside.
In pack1/mod1.py I have a function
def some_function(arg: str):
...
If I open mod2.py, write "some_" and try to get autocomplete one of two things happen:
- If mod1 has been opened, or a module that references mod1 or any file in pack1 has been opened, I will get an autocomplete.
- If only mod2.py has been opened since opening the editor, I don't get anything.
If I now open pack1/mod1.py, go back to mod2.py and try the same thing, I get an autocomplete.
I have the same setup for sublime and there it works as it should.
Same thing happens with pyright. Hoever, with pylance, the problem doesn't exist.
thanks for reporting. i've noticed similar behaviour but haven't been able to narrow down anything specific. interesting that it only happens in vscode though
i reproduced the same issue in sublime text, so i don't think it's specific to vscode
Have you enabled workspace instead of open files only?
oh wow, i thought diagnosticMode was "workspace" by default. i should change that (#559)
now that i've set mine to "workspace", i can't seem to reproduce the issue in vscode or sublime text:
how exactly are you configuring diagnosticMode in vscode? is it in your workspace or user settings? maybe it's being overwritten or something? also which version of basedpyright are you using?
I use basedpyright.analysis.diagnosticMode, set to workspace.
I use v1.15.2
I tried it again, it doesn't work in vscode. Make sure you haven't opened any files from pack1 prior to opening mod2, even if they are closed now. Once they are read, it works.
weird, i can reproduce the issue on a different machine. will investigate further, thanks
notes to self:
- prob need to revert #560 before the next release, its way too slow on a large project
- perhaps the default can be set back to `"workspace" once #427 is done?
- is this an issue in pylance?
is this an issue in pylance?
No. In pylance, it works, even if you set the diagnostic mode to open files only. I think this is what separates pylance from pyright
ok i think i can reliably reproduce the issue now
No. In pylance, it works, even if you set the diagnostic mode to open files only. I think this is what separates pylance from pyright
it doesn't seem to work for me in pylance at all. instead i get a quick fix to search for additional imports which i think is a recent change. it does end up showing it but i don't know why they'd add an extra step and make it more annoying:
issues with import suggestions are always so hard to debug, because the behavior seems to always change randomly.
You probably have "python.languageServer": "None" set in .vscode/settings.json automatically, so pylance doesn't work. I can reliably get autocomplete with pylance.
nah i have a separate isolated pylance profile with python.languageServer set to "Default"
The auto-complete via code actions behavior is quite unpredictable for me. It seems to work for most of the stdlib modules like os, itetools , subprocess but not for a few ones like logging and unittest(there could be more but I just happened to notice these two).
And for third party modules, it didn't work for me at all, I did try setting extraPaths to site-packages path, and changing the diagnosticMode to workspace but none of these options worked.
Although this is only via code actions, if I start typing, the entries do show up in the auto-completion popup menu.
For reference I am using Neovim with native lsp.
Confirm the same issue on VSCode and vim for me.
Example file: test.py
class Test(BaseModel):
id: str
test: str
t = Test(
id="Hey",
test="yo",
)
Startup: https://pastebin.com/RVYHKwDE Code Action Issue: https://pastebin.com/RcWuYcTf
Actually I've also ran into this issue recently and didn't figure out what's wrong with it. Sometimes a file would properly get saved into autocomplete but an adjacent file in that folder would not. Maybe it's because of this issue...
same issue
same in vim, zed, vs code
Same with neovim. Strange thing, because Sqlalchemy it supports, but not FastAPI, Django, DRF, Flask.
I've been poking and prodding the code for the past two days. Initially, all the files are analyzed and the symbols are correctly mapped and processed, but somehow, the symbol table gets reset after that.
I'll investigate more.
Did you ever make any progress on figuring this one out? I'm using the Cursor fork of basedpyright and getting very similar behavior, so I'd love to see this get fixed.
Wasted a ton of time on this issue, and found nothing. All the files in the workspace are getting processed when you open the project correctly, just not offered for autocomplete for some reason I can't understand.
Makes me think @DetachHead (or someone similarly deeply familiar with how basedpyright works) is going to have to dig into this, then.
No, I just updated my configuration to the latest version of lspconfig. I figured out that it is looking for some dynamic libraries like fastapi if you insert some its imports in workspace. For example if I write in workspace from FastAPI import FastAPI and from fastapi.security import ... it is looking in these modules.> Did you ever make any progress on figuring this one out? I'm using the Cursor fork of basedpyright and getting very similar behavior, so I'd love to see this get fixed.
I'm having the same issue. Gosh this is a little troublesome.