zed icon indicating copy to clipboard operation
zed copied to clipboard

Completion: LSP doc not showing and inline doc delay cause blinking

Open farbodvand opened this issue 10 months ago • 7 comments

Summary

When code completion enabled, completion list, documentation window and inline doc flickers and for a split second you can see the text behind code completion windows.

Description

Steps to reproduce:

  1. Open JS/TS or any language file supported by a LSP
  2. Start typing with code completion enabled

Expected Behavior: Expected for code completion to stay consistent while typing.

Actual Behavior:

Video

Demo of the bug on a sample JS file

https://github.com/user-attachments/assets/b5636ee9-f678-40c7-a0c3-ab3d26475b76

Zed Version and System Specs

Zed: v0.181.6 (Zed) OS: macOS 15.4.0 Memory: 16 GiB Architecture: x86_64

settings.json

farbodvand avatar Apr 12 '25 15:04 farbodvand

This issue isn't only relevant in this case but happens a lot randomly too.

KorigamiK avatar Apr 13 '25 18:04 KorigamiK

The flickering isn't great for sure, but unfortunately, not updating the completions menu while typing is not a good solution as the whole point of having the menu appear is so that as you type more, the completion suggestions get better (hopefully!)

Do you think debouncing the completions, animating between the different completion lists instead of flickering, or something else would be the best solution here?

probably-neb avatar Apr 22 '25 14:04 probably-neb

Hey Ben, I am unaware of Zed's internals, but from my observation it seems like the completion menu redraws horizontally in some situations. Whereas for example on Webstorm or VScode the menu stays consistent and does not redraw or animate on key strokes (unless we reach a "." etc). Although the completion menu adjusts vertically based on how many suggestions there is, and that's normal behavior.

Avoiding a full menu redraw each time the LSP provides data, and using a fixed-width completion menu (with an option to resize), could resolve this issue:

Video

Demo of right behavior on VScode (docs are disabled here)

https://github.com/user-attachments/assets/67d1af59-d796-4e56-837c-752c51681a2f

That's for the completion menu, and for the text inside the completion menu, there seems to be a delay in how Zed retrieves completions from the LSP, causing text flickering (just a hypothesis).

Another related bug I’ve noticed is that the completion menu’s documentation is initially empty, then After 1–2 seconds, it fills with documentation from the LSP, or it doesn’t show at all unless I move the mouse. Video showing the bug:

Video

Demo of the bug on a sample Go file (also tested on JS), watch the very small empty window below the list

https://github.com/user-attachments/assets/6939e3b7-885f-4699-8904-fef0f00468bf

So, there are three problems here:

  1. The completion menu redraws horizontally in some cases.
  2. A delay in retrieving LSP suggestions causes text flickering in the completion menu.
  3. Documentation in the completion menu is delayed or doesn’t appear unless the mouse is moved.

settings.json

farbodvand avatar Apr 22 '25 18:04 farbodvand

The completion menu redrawing is fixed with #30598 on v0.187.0 but other two problems still happen (LSP doc not showing on some occasions and inline doc delay that cause blinking) so I will keep this open.

farbodvand avatar May 14 '25 21:05 farbodvand

Could you please edit the issue description to reflect the current issues?

probably-neb avatar May 22 '25 08:05 probably-neb

Thanks for taking the time to describe these issues!

A delay in retrieving LSP suggestions causes text flickering in the completion menu.

The menu flicker is probably caused by not using isIncomplete from the language server - completions are being re-fetched on every change. Ideally when isIncomplete is false there would be no refetch.

Documentation in the completion menu is delayed or doesn’t appear unless the mouse is moved.

This was pretty bad, been bugging me for a while, probably exacerbated by having cursor blink disabled (default cursor blink causes redraw). Fixed in #31486.

After that fix, docs would still flicker when using arrow keys to change selection, due to the parsing happening async and so not being available for a frame. #31546 fixes this by caching parsed markdown for adjacent items in the completions list.

The completion menu redraws horizontally in some cases.

I don't follow what this means. Is it that the documentation sometimes displays to the right? I think this is a feature because that position is less likely to overlap code. The implementation of this avoids frequent position changes while typing - it should only jump position once.

mgsloan avatar May 27 '25 19:05 mgsloan

@mgsloan Thanks for looking into this, so I waited for V0.189.0 to test the latest fixes on my end:

  1. The text in doc window not showing is fixed with #31486.
  2. The inline doc flickering is not as obvious as before because the delay is now longer. Fixed with #31546.
  3. Completion menu horizontally redrawing was fixed with #30598 (you can also see the video on this for a reference).

Obviously the inline doc delay is noticeable, and a good solution for now would be an option to disable inline doc. All three issues are addressed now, we can close this if there's nothing to add here.

farbodvand avatar May 28 '25 19:05 farbodvand

@farbodvand Cool, thanks for taking a look! In #31872, I implemented not requerying completions in some cases when the language server reports isIncomplete: false and added caching of markdown parsing even across re-queries. If your language servers are providing complete lists of completions, this should help a lot with inline doc population - delay will still be noticeable but the inline docs will stick around while typing instead of being re-fetched.

mgsloan avatar Jun 02 '25 22:06 mgsloan