DetachHead / basedpyright

pyright fork with various type checking improvements, improved vscode support and pylance features built into the language server
https://docs.basedpyright.com
Other
1.02k stars 19 forks source link

Language server does't offer autocomplete for functions in modules or packages that haven't been opened or loaded #545

Open dekomote opened 2 months ago

dekomote commented 2 months ago

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.

image

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:

  1. If mod1 has been opened, or a module that references mod1 or any file in pack1 has been opened, I will get an autocomplete.
image
  1. If only mod2.py has been opened since opening the editor, I don't get anything.
image

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.

image

Same thing happens with pyright. Hoever, with pylance, the problem doesn't exist.

DetachHead commented 2 months ago

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

DetachHead commented 1 month ago

i reproduced the same issue in sublime text, so i don't think it's specific to vscode

dekomote commented 1 month ago

Have you enabled workspace instead of open files only?

DetachHead commented 1 month ago

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:

image

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?

dekomote commented 1 month ago

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.

DetachHead commented 1 month ago

weird, i can reproduce the issue on a different machine. will investigate further, thanks

notes to self:

dekomote commented 1 month ago

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

DetachHead commented 1 month ago

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:

image

image

issues with import suggestions are always so hard to debug, because the behavior seems to always change randomly.

dekomote commented 1 month ago

You probably have "python.languageServer": "None" set in .vscode/settings.json automatically, so pylance doesn't work. I can reliably get autocomplete with pylance.

DetachHead commented 1 month ago

nah i have a separate isolated pylance profile with python.languageServer set to "Default"

rbhanot4739 commented 1 week ago

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.

npip99 commented 1 week ago

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