Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Completions in VS Code #400

Open
2 tasks
zachallaun opened this issue Oct 11, 2023 · 6 comments
Open
2 tasks

Completions in VS Code #400

zachallaun opened this issue Oct 11, 2023 · 6 comments
Labels
bug Something isn't working completions Enhancements to Lexical's autocompleter

Comments

@zachallaun
Copy link
Collaborator

zachallaun commented Oct 11, 2023

The following improvements cannot be made until related issues in VS Code are resolved:


While doing some work on completions, I found a number of VS Code issues that affect completions pretty significantly. The workarounds for these may need to occur both here and in lexical-lsp/vscode-lexical, so I'm creating a single tracking issue to consolidate information for now.


When a completion request is issued by the client, the response from the server can optionally set an isIncomplete flag. If it's set to true, according to the spec1: "This list is not complete. Further typing should result in recomputing this list." This means that further typing could add/reorder items.

Without isIncomplete set to true, VS Code makes the assumption that the initial set of items is complete, and further characters in the same "word" are filtered client-side. This means that for each word, only a single completion request will be issued. This led to some completions never appearing in VS Code, fixed by #398.

Unfortunately, this fix isn't complete: VS Code has what I think must be considered a bug2: If a completion result is empty, i.e. the list of completion items is [], even if isIncomplete is set to true, VS Code will not issue additional completion requests. So if we return no completions on the first character, VS Code will never show additional completions from the server.

There have been additional issues and suggestions34 for how VS Code's behavior should be improved, but I think all of them hinge on the original bug being resolved.


Looking through the linked issues, multiple language servers have tried various workarounds. For now, however, it may be necessary to move away from using isIncomplete if possible and always return the full set of completions on the first character.

Footnotes

  1. LSP Specification: textDocument/completion

  2. Support CompletionList.isIncomplete=true on empty lists (or at least, clearly document current behaviour) microsoft/vscode#155738

  3. Filter completion client-side even if the LSP returns incomplete results microsoft/vscode#168329

  4. CompletionList.isIncomplete=true results in showing "stale" results when typing quickly due to cancelled requests microsoft/vscode#147830

@zachallaun zachallaun added bug Something isn't working completions Enhancements to Lexical's autocompleter labels Oct 11, 2023
zachallaun added a commit that referenced this issue Oct 11, 2023
Related: #400

VS Code in particular handles empty completions lists very poorly,
refusing to make further completion requests. This commit removes the
logic that was preventing completions from being returned when the
prefix is a single character.
zachallaun added a commit that referenced this issue Oct 12, 2023
Related: #400

VS Code in particular handles empty completions lists very poorly,
refusing to make further completion requests. This commit removes the
logic that was preventing completions from being returned when the
prefix is a single character.
zachallaun added a commit that referenced this issue Oct 12, 2023
Related: #400

VS Code in particular handles empty completions lists very poorly,
refusing to make further completion requests. This commit removes the
logic that was preventing completions from being returned when the
prefix is a single character.
zachallaun added a commit that referenced this issue Oct 12, 2023
Related: #400

VS Code in particular handles empty completions lists very poorly,
refusing to make further completion requests. This commit removes the
logic that was preventing completions from being returned when the
prefix is a single character.
zachallaun added a commit that referenced this issue Oct 13, 2023
Related: #400

VS Code in particular handles empty completions lists very poorly,
refusing to make further completion requests. This commit removes the
logic that was preventing completions from being returned when the
prefix is a single character.
zachallaun added a commit that referenced this issue Oct 13, 2023
Related: #400

VS Code in particular handles empty completions lists very poorly,
refusing to make further completion requests. This commit removes the
logic that was preventing completions from being returned when the
prefix is a single character.
zachallaun added a commit that referenced this issue Oct 13, 2023
Related: #400

VS Code in particular handles empty completions lists very poorly,
refusing to make further completion requests. This commit removes the
logic that was preventing completions from being returned when the
prefix is a single character.
@scottming
Copy link
Collaborator

scottming commented Oct 14, 2023

I found that the fix in PR #398 has caused some new issues. In my understanding, is_incomplete: true means that the server did not return all the data, and the client needs to continue making requests. This leads to more frequent communication between them and complicates the situation.

For example, in Neovim, there is now frequent flickering when completing structs, which was not the case before.

now

CleanShot.2023-10-14.at.15.18.49.mp4

Before(Better UX)

CleanShot.2023-10-14.at.15.16.52-converted.mp4

Regarding the thing you mentioned in reference [^2], I also think it is a bug because other clients can handle this aspect well. Therefore, I also think we should not return all completion results in the same format with Completion.List.new(items: items, is_incomplete: true).

@zachallaun
Copy link
Collaborator Author

You're correct, @scottming -- this is a UX regression from #398. If we start returning completions for single-character prefixes (#410 does this for all completions except atoms), we can revert #398.

The problem is that, for VS Code, it seems to be all or nothing: return all possible completions on the first character, or no completions will be shown at all for subsequent input until a trigger character or new word is seen.

zachallaun added a commit that referenced this issue Oct 15, 2023
Related: #400

VS Code in particular handles empty completions lists very poorly,
refusing to make further completion requests. This commit removes the
logic that was preventing completions from being returned when the
prefix is a single character.
zachallaun added a commit that referenced this issue Oct 16, 2023
Related: #400

VS Code in particular handles empty completions lists very poorly,
refusing to make further completion requests. This commit removes the
logic that was preventing completions from being returned when the
prefix is a single character.
zachallaun added a commit that referenced this issue Oct 16, 2023
This commit improves completions for the general case and adds special handling when the client is VS Code that fixes numerous issues related to completions in that editor.

General improvements:

* Partially revert #398, which introduced a UX regression that caused slow/high latency completions.
* Don't insert additional, unnecessary newlines with multi-line snippets.
* Improved snippets for `defdelegate`, `defguard`, `defguardp`, `with`.
* Consistent capitalization and naming in completion labels.
* Fix a bug that caused a do/end block completion to be proposed when the cursor was after `@do`, which would occur whenever typing `@doc`.

VS Code:

VS Code has some problematic behavior when dealing with empty completion lists. When the client is VS Code, we now attempt to never send empty completion lists if it is possible that further typing will result in some completions. Instead, we send a larger list up front and allow the editor to filter.

See #400 for more context.

---------

Co-authored-by: Scott Ming <[email protected]>
@zachallaun
Copy link
Collaborator Author

Behavior in VS Code was much improved by #410, but I'd like to leave this issue open to make it hopefully easier to track the upstream issues in VS Code and as context for people coming here to report other potential issues with VS Code completions.

@scohen scohen added this to the 0.4 release milestone Oct 18, 2023
@scohen
Copy link
Collaborator

scohen commented Oct 18, 2023

@zachallaun I don't like long-lived issues, unless they're tracking several sub-issues. Can we either close this or provide a set of tasks that when completed would close this issue?

@zachallaun
Copy link
Collaborator Author

@scohen There are (at least) 2 features we can't have, at least for VS Code, until related issues are resolved. I added them to the top of the OP.

@scohen
Copy link
Collaborator

scohen commented Oct 19, 2023

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working completions Enhancements to Lexical's autocompleter
Projects
None yet
Development

No branches or pull requests

3 participants