pyrefly icon indicating copy to clipboard operation
pyrefly copied to clipboard

LSP (Zed): Auto-import completions incomplete for symbols with common prefix

Open baab7 opened this issue 2 months ago • 11 comments

Describe the Bug

Summary

Completion filtering doesn't update when typing continues - shows only initially fetched results.

Description

When multiple classes start with the same prefix, Pyrefly's auto-import completions only show the results that were fetched first and don't continue fetching as more characters are typed.

MRE:

  1. Setup environment:
uv init --bare
uv add --dev pyrefly  
uvx pyrefly init

install pyrefly extension

  1. Create files with code

a.py:

class UsersManager:
    pass

b.py:

class UsersController:
    pass
    
# start typing UsersM here
  1. Start typing UsersM in b.py
  2. Only UsersController appears
  3. The UsersManager from a.py doesn't show up
Screen recording

Zed (what is actually) (appears only after manual trigger as write and delete backspace):

https://github.com/user-attachments/assets/1bb41c16-be4c-45d4-8fcd-c0bcc1fbd687

VS Code (what is expected):

https://github.com/user-attachments/assets/33bde756-8bc3-4337-9cde-04b05c17a4f7

LSP log

log.log

Original issue: https://github.com/zed-industries/zed/issues/39945 (semi-fixed)

Related commit: https://github.com/facebook/pyrefly/commit/aa33ce3c077194e3e4c5d34f17cf7642ca01902e

Sandbox Link

No response

(Only applicable for extension issues) IDE Information

Zed: v0.209.6 (Zed) OS: macOS 26.0.1 Memory: 16 GiB Architecture: aarch64

baab7 avatar Oct 27 '25 22:10 baab7

@lolpack recently made a change to this. do you know which version of zed your changes were in?

kinto0 avatar Oct 27 '25 23:10 kinto0

@kinto0, it was v0.208.4

baab7 avatar Oct 27 '25 23:10 baab7

@baab7 thanks for reporting this. I tested in Pylance and I see that the autocomplete import is not available, but it does give the option to import it via quickfix. That seems reasonable. I'll see if I can get to it this week.

Image

lolpack avatar Oct 28 '25 15:10 lolpack

@baab7 I tested this again and I do see the auto import available, but it's not as obvious because we don't show the yellow underline. Right now we only show the red underline, and that's if you have type checking enabled (either a setting in your config or a pyrefly.toml file/[tool.pyrefly] in pyproject.toml).

Image Image

lolpack avatar Oct 28 '25 19:10 lolpack

@lolpack, just to clarify - do you see the auto-import completions while actively typing, or only when manually checking completions (because that's what it looks like from your screenshots)?

Because in my testing (videos attached), it works as expected in VSCode exactly while typing, but doesn't work in Zed.

I confirm it does work, but not while typing

baab7 avatar Oct 28 '25 19:10 baab7

Perhaps a good next step is to get the LSP trace logs for the repro in both zed & VsCode, and compare them to see if there's a request that the zed client is omitting that we need to update the completion results. @kinto0 are you able to provide instructions for how to do this?

yangdanny97 avatar Nov 04 '25 18:11 yangdanny97

Perhaps a good next step is to get the LSP trace logs for the repro in both zed & VsCode, and compare them to see if there's a request that the zed client is omitting that we need to update the completion results. @kinto0 are you able to provide instructions for how to do this?

I've never used zed so I'm not sure about how it works there. but in vscode, LSP trace is shown in the output panel under the pyrefly dropdown when Pyrefly > trace > server is set to verbose

kinto0 avatar Nov 06 '25 15:11 kinto0

@kinto0, @yangdanny97,

Perhaps a good next step is to get the LSP trace logs for the repro in both zed & VsCode

I've never used zed so I'm not sure about how it works there

Zed log is already attached in the first message. But not VSCode

baab7 avatar Nov 06 '25 15:11 baab7

having the same problem here in nvim.

the auto import is back only after i typed M or any letter after M, exit and enter insert mode again, then trigger the completion, it shows the auto import in the completion options.

but if i remove the letters to Users, the auto import disappears and won't show up even if i continue typing to M

ogios avatar Nov 27 '25 14:11 ogios

though if the identifier is lower than 3 characters, it works fine. for exmaple:

# a.py

class UsManager:
    pass
# b.py

class UsController:
    pass
    
# start typing UsM here

guessing because of this code here: https://github.com/facebook/pyrefly/blob/0cd3d4da6a5c54fb394d584dca0b930a292dc8c0/pyrefly/lib/state/lsp.rs#L2832-L2834

so i'm assuming the problem is about the is_incomplete.

while we typed to Users we get lsp response with isInComplete = false which means that the client will not continue sending request to the lsp while we continue typing to M, is that correct?

i haven't really thought of a proper solution for this, but remove if !has_local_completions has fixed it brutally.

ogios avatar Nov 28 '25 12:11 ogios

i haven't really thought of a proper solution for this, but remove if !has_local_completions has fixed it brutally.

Yeah, the same for me, I've been doing this for a month

baab7 avatar Nov 28 '25 12:11 baab7

sorry about the delay - big backlog and we've taken some time off for the holidays. I hope we can get to it soon. removing assignees in case someone else can pick it up

kinto0 avatar Dec 04 '25 00:12 kinto0

will look into this issue!

AryanBagade avatar Dec 13 '25 22:12 AryanBagade