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

CompletionItem::textEdit support is incorrect #662

Closed
MaskRay opened this issue Nov 23, 2018 · 4 comments
Closed

CompletionItem::textEdit support is incorrect #662

MaskRay opened this issue Nov 23, 2018 · 4 comments

Comments

@MaskRay
Copy link
Contributor

MaskRay commented Nov 23, 2018

Describe the bug

When CompletionItem.textEdit is present but CompletionItem.insertText is absent, completion triggered by triggerCharacter does not display the completion item correctly.

#include <bits/stdc++.h>
int main() { std::xplicit }
/*
atomic_fetch_and_explicit
*/

I've set g:LanguageClient_completionPreferTextEdit to 1

And IMHO g:LanguageClient_completionPreferTextEdit should just default to 1 if the server sends CompletionItem.textEdit.

Environment

  • neovim/vim version (nvim --version or vim --version): NVIM v0.3.2-649-g512e0caae
  • This plugin version (git rev-parse --short HEAD): 13fc7e2
  • This plugin's binary version (bin/languageclient --version): languageclient 0.1.129
  • Language server link and version: https://github.com/MaskRay/ccls/

To Reproduce

Steps to reproduce the behavior:

  1. Start vim
  2. let g:LanguageClient_completionPreferTextEdit = 1
  3. Insert boilerplate and std::
  4. Select the first completion item
  5. See error

Current behavior

newText is somehow inserted from the line beginning though it does not overwrite existing characters.

Expected behavior

newText should be inserted in the correct position, not from the line beginning.

@JeanMertz
Copy link
Contributor

I believe I am hitting the same issue, while using rust-analyser.

When I complete the selection at this point:

screenshot 2019-02-14 at 08 23 12

I end up with this result:

screenshot 2019-02-14 at 08 23 24

If I disable g:LanguageClient_completionPreferTextEdit, things work as expected.

@dimbleby
Copy link
Contributor

dimbleby commented Aug 1, 2019

I believe that the specific way in which prefer-text-edits is broken is per my comment in #857 (comment)

The way that this language client tries to implement prefer-text-edits is to accept the completion as specified by the server in the label, and then when the completion is done it undoes that and applies the text edits instead.

See languageClient_handleCompleteDone, called at the CompleteDone autocmd - here is the undo.

Unfortunately this is not so good unless you break the undo sequence before starting the completion (see :help i_Ctrl-G_u), because otherwise you are likely to undo much more than is intended, and then also end up making the text edit in completely the wrong place.

@dimbleby
Copy link
Contributor

dimbleby commented Aug 1, 2019

https://github.com/prabirshrestha/vim-lsp/blob/master/autoload/lsp/omni.vim#L321 is an interesting solution. Instead of undoing the original completion, expand the text edit so that it just removes the unwanted completion.

@martskins
Copy link
Collaborator

I believe this is no longer an issue so I'll close this one, but feel free to re-open if you are still seeing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants