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

Completion includes types of variables/methods #857

Closed
vorner opened this issue Jul 31, 2019 · 18 comments
Closed

Completion includes types of variables/methods #857

vorner opened this issue Jul 31, 2019 · 18 comments

Comments

@vorner
Copy link

vorner commented Jul 31, 2019

Maybe this is the same thing as #813? I'm not 100% sure.

  • Did you upgrade to latest plugin version?

yes, commit e4478a4789805c66ce24ae786677ae557cd411da

  • Did you upgrade to/compile latest binary? Run shell command
    bin/languageclient --version to get its version number.
$ ./bin/languageclient --version
languageclient 0.1.147
  • (Neovim users only) Did you check output of :checkhealth LanguageClient?
  - OK: binary found: /home/vorner/.local/share/nvim/plugged/LanguageClient-neovim/bin/languageclient
  - OK: languageclient 0.1.147 
  • Did you check [troubleshooting]?

Yes

Describe the bug

I'm using ccls for the language client. The LanguageClient completes the code including types and parameters which don't actually belong to the code and need to be deleted.

It worked fine with 0.1.146 (only the relevant parts were added).

Environment

  • neovim/vim version (nvim --version or vim --version):
NVIM v0.3.7
Build type: Release
LuaJIT 2.0.5
Compilation: /usr/bin/x86_64-pc-linux-gnu-gcc -ggdb0 -O2 -pipe -march=native -Wconversion -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DMIN_LOG_LEVEL=3 -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fdiagnostics-color=auto -Wno-array-bounds -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -I/var/tmp/portage/app-editors/neovim-0.3.7/work/neovim-0.3.7_build/config -I/var/tmp/portage/app-editors/neovim-0.3.7/work/neovim-0.3.7/src -I/usr/include -I/var/tmp/portage/app-editors/neovim-0.3.7/work/neovim-0.3.7_build/src/nvim/auto -I/var/tmp/portage/app-editors/neovim-0.3.7/work/neovim-0.3.7_build/include
Compiled by portage@leviathan

Features: +acl +iconv +jemalloc +tui 
See ":help feature-compile"

   system vimrc file: "/etc/vim/sysinit.vim"
  fall-back for $VIM: "/usr/share/nvim"

Run :checkhealth for more info
  • This plugin version (git rev-parse --short HEAD):

e4478a4789805c66ce24ae786677ae557cd411da

  • This plugin's binary version (bin/languageclient --version):

languageclient 0.1.147

  • Minimal vimrc content (A minimal vimrc is the smallest vimrc that could
    reproduce the issue. Refer to an example [here][min-vimrc.vim]):
source ~/.config/nvim/plug.vim

call plug#begin('~/.local/share/nvim/plugged')

Plug 'autozimu/LanguageClient-neovim', {
    \ 'branch': 'next',
    \ 'do': 'bash install.sh',
    \ }

call plug#end()

let g:LanguageClient_serverCommands = {
    \ 'c': ['nice', '-n5', '/home/vorner/testing/ccls/build/ccls'],
    \ }
let $RUST_BACKTRACE = 1
let g:LanguageClient_loggingLevel = 'INFO'
let g:LanguageClient_loggingFile =  expand('~/.local/share/nvim/LanguageClient.log')
let g:LanguageClient_serverStderr = expand('~/.local/share/nvim/LanguageServer.log')
  • Language server link and version:
$ ./testing/ccls/build/ccls --version
ccls version 0.20190314.1-0-ga41b976a
clang version 8.0.1 (tags/RELEASE_801/final)

(but it seems not to depend on the version)

To Reproduce

Have this C file:

struct Point {
	int x;
};

int main() {
	struct Point point;
}

Then add new line, point. and press Ctrl+X,Ctrl+O to trigger completion (my full setup uses ncm2, so I get the completions open automatically, but the minimal one needs manual trigger).

It is completed to line: point.x : int. The : int obviously doesn't belong to the program code and I have to go and delete it, which rather slows things down. Similar thing happens for method/function parameters, etc.

Expected behavior

Only the x is completed.

Additional context

I'm going to attach the logs.

@vorner
Copy link
Author

vorner commented Jul 31, 2019

@vorner vorner changed the title Completion includes types of Completion includes types of variables/methods Jul 31, 2019
@dimbleby
Copy link
Contributor

dimbleby commented Aug 1, 2019

You probably want let g:LanguageClient_completionPreferTextEdit = 1.

This ought to be the default behaviour, I think, indeed it likely shouldn't even be configurable. cf #856.

@vorner
Copy link
Author

vorner commented Aug 1, 2019

Unfortunately, it's still broken even with this configuration option on 0.1.147. Maybe the option doesn't work properly?

@dimbleby
Copy link
Contributor

dimbleby commented Aug 1, 2019

It works for me - with the caveat that it's more or less unusable!

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.

I guess you could remap <C-x><C-o> to <C-g>u<C-x><C-o>, perhaps that would make this workable.

(However if you're not seeing even that mess - I have no explanation).

@vorner
Copy link
Author

vorner commented Aug 1, 2019

I can probably confirm it acts as you describe. If I enable the option and do the whole <c-g>u<c-x><c-o> dance, I first get the types and they then disappear. If I don't do the <c-g>u part, the whole edit (eg. if I start with O to open a new line, then type the start of line, etc), the whole line with point disappears.

I guess I didn't go as far as to press the escape during the previous experiment, so I was still seeing the before-undo situation.

In the ncm2 automatic mode this is even more unusable. There's no place I'd be pressing <c-g>u, so after pressing esc, the line just disappears like nothing happened. If there were multiple levels (eg. I wanted point.x.y) I want to just get x, type a dot and get another completion ‒ but this way I'd write the dot after the type and obviously wouldn't get any completions, right?

@dimbleby
Copy link
Contributor

dimbleby commented Aug 1, 2019

I dunno, I also use ncm2 with this plugin and it works just fine for me no matter what settings I use, with or without the proposed fix at #858.

This makes no sense given what I think I know.

@vorner
Copy link
Author

vorner commented Aug 1, 2019

OK, I'll try to dig into the ncm2 interaction a bit more once I get some time, to see if either the proposed PR fixes it for me or if I can pinpoint some kind of minimal config that acts weird. I can share my full config, but I guess you probably don't want to dig through that.

@vorner
Copy link
Author

vorner commented Aug 1, 2019

I've managed to reproduce probably something even weirder with that branch. This is the config:

source ~/.config/nvim/plug.vim

call plug#begin('~/.local/share/nvim/plugged')

Plug 'dimbleby/LanguageClient-neovim', { 'do': 'make release', 'branch': 'better-text-edit-completion' }
Plug 'ncm2/ncm2'
Plug 'roxma/nvim-yarp'

call plug#end()

let g:LanguageClient_serverCommands = {
    \ 'c': ['nice', '-n5', '/home/vorner/testing/ccls/build/ccls'],
    \ }
let $RUST_BACKTRACE = 1
let g:LanguageClient_loggingLevel = 'INFO'
let g:LanguageClient_loggingFile =  expand('~/.local/share/nvim/LanguageClient.log')
let g:LanguageClient_serverStderr = expand('~/.local/share/nvim/LanguageServer.log')
"let g:ncm2#auto_popup = 1
autocmd BufEnter * call ncm2#enable_for_buffer()

Now I open a new empty c file, eg nvim -u init.vim a.c and start typing (I want to type struct). But after st, it directly inserts static and shows a popup. The r I type next closes the popup, but static stays (even after pressing Esc). Adding the proposed option to prefer editText doesn't change this behaviour.

When I do that with (freshly compiled) next branch from this repository, static appears after typing st, then changes to staticatic after pressing the r. After pressing esc, it changes to staticaticstatic 😕.

@dimbleby
Copy link
Contributor

dimbleby commented Aug 1, 2019

Not sure whether this is your problem or not, but you seem to have skipped some of the instructions from ncm2:

    " IMPORTANT: :help Ncm2PopupOpen for more information
    set completeopt=noinsert,menuone,noselect

@vorner
Copy link
Author

vorner commented Aug 1, 2019

It seems to be related to the further weirdness allright (I do have this in my full config). So, testing now, with added this option, with the preferred textEdit and the linked branch, returning to the original example.

When I type point., a menu appears, with one option. I press Ctrl+N to select the option, it includes the whole x : int. If I press Esc, it stays there. If I press a space (to continue typing), it also stays there.

@dimbleby
Copy link
Contributor

dimbleby commented Aug 1, 2019

Well, beats me. As I say, it all works astonishingly well for me - https://asciinema.org/a/jk0WXxMbKJR8lHfrLrVIo9EBy.

Feel free to dig through my config and see if you can figure out the difference, if you like - https://github.com/dimbleby/dotfiles/blob/master/.vimrc. But there's very little in there that's relevant to ncm2, so...

@autozimu
Copy link
Owner

autozimu commented Aug 2, 2019

This ought to be the default behaviour

This wasn't turned on by default is that my original implementation is too problematic and sometime unusable.

@vorner
Copy link
Author

vorner commented Aug 2, 2019

There's one thing that I wonder if this might have an effect. What version of neovim do you use? I'm still on stable/0.3.7.

@0xC0FFEE
Copy link

0xC0FFEE commented Aug 6, 2019

There's one thing that I wonder if this might have an effect. What version of neovim do you use? I'm still on stable/0.3.7.

I have basically the same setup as you described and I'm also experiencing the same issue. However I'm using the neovim master (6871445df), so this shouldn't be the source of the problem.

@NightWhistler
Copy link

I can confirm this issue, on Neovim 0.3.7 with Deoplete and Metals as my LanguageServer.

Enabling let g:LanguageClient_completionPreferTextEdit = 1 actually gives me another problem: the type info dissappears, but the cursor jumps and the completion gets put on the wrong line.

@MarkGreeny
Copy link

MarkGreeny commented Aug 30, 2019

Any word on this? This was not an issue a few months back for me. Is it the ccls? Or the client? or Deoplete?
I always used deoplete+languageClient-neovim+ccla, but i recently updated to ubuntu 19.04 and reinstalled everything. Now it is broken, as described. Note that it worked perfectly without let g:LanguageClient_completionPreferTextEdit = 1 before. Now, this option does not change the error for me.

@autozimu
Copy link
Owner

@MarkGreeny it must be an update of ccls that removed the "insertText" field, which LanguageClient-neovim depends to to create vim completion items, https://github.com/autozimu/LanguageClient-neovim/blob/next/src/types.rs#L536

"insertText" has been the older way for language server to return completion items and it is much easier and nicer to integrate to vim completion system.

Unfortunately, the standard has been moving towards "textEdit", which in contrast is much harder to work with, https://microsoft.github.io/language-server-protocol/specification. Option g:LanguageClient_completionPreferTextEdit is to support this "textEdit" approach and for the ccls, it might be the only way going forward. You might have to build from source if you want to take advantage of recent improvements. If you're still experience issue, please provide details.

@NightWhistler
Copy link

@autozimu I run into the same issues with Metals, and the g:LanguageClient_completionPreferTextEdit does not help.

Right now I'm keeping LanguageClient-neovim pinned to the oldest version that still worked for me using silent! let g:plugs['LanguageClient-neovim'].commit = 'ec4af74'

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

6 participants