iamcco / coc-vimlsp

viml language server
216 stars 7 forks source link

When there's a single match, <CR> starts new line #21

Closed psprint closed 4 years ago

psprint commented 4 years ago

Describe the bug When I'm writing VimL I often encounter the following:

  1. I enter a part of a keyword, e.g.: a function name substi…(tute).
  2. I get the single, only match — the substitute function (or command, unsure).
  3. So I press enter to accept the match — it's already selected (because suggest.noselect ← false).
  4. However, instead of the complete action I get: abruptly ended keyword and a cursor in new, inserted line.
  5. Fiddling with cursors to reselect before pressing doesn't help.

To Reproduce Steps to reproduce the behavior:

  1. vim ~/.vimrc
  2. Go to insert mode, then start typing substitu… untill there's only single completion candidate (single entry in the pum).
  3. If you don't have suggest.noselect ← false, then press an arrow key to select the single match.
  4. Press Enter.

Expected behavior The single, selected/active candidate should be simply completed on Enter.

Screenshots If applicable, add screenshots to help explain your problem. 2020-09-27-110619_1375x242_scrot

Desktop (please complete the following information):

Relevant CocOpenLog contents:

2020-09-27T11:11:23.170 DEBUG (pid:536791) [events] - Event: InsertCharPre [ 'b' ]
2020-09-27T11:11:23.182 DEBUG (pid:536791) [events] - Event: MenuPopupChanged [
  {
    col: 0,
    row: 0,
    scrollbar: true,
    completed_item: {
      word: 'sunmap',
      menu: 'sunm[ap] [LS]',
      user_data: '{"cid":1601197882,"source":"vimlsp-1","index":17}',
      info: 'like ":unmap" but for Select mode',
      kind: '¿',
      abbr: '1 sunmap'
    },
    width: 34,
    height: 15,
    size: 21
  },
  15
]
2020-09-27T11:11:23.183 DEBUG (pid:536791) [events] - Event: TextChangedP [ 1, { lnum: 15, col: 4, changedtick: 16, pre: 'sub' } ]
2020-09-27T11:11:23.191 DEBUG (pid:536791) [completion-complete] - Source "vimlsp-1" takes 5ms
2020-09-27T11:11:23.195 DEBUG (pid:536791) [events] - Event: CompleteDone [ {} ]
2020-09-27T11:11:23.204 DEBUG (pid:536791) [events] - Event: MenuPopupChanged [
  {
    col: 0,
    row: 16,
    scrollbar: false,
    completed_item: {
      word: 'substitute',
      menu: 's[ubstitute] [LS]',
      user_data: '{"cid":1601197883,"source":"vimlsp-1","index":0}',
      info: 'find and replace text',
      kind: '¿',
      abbr: '1 substitute'
    },
    width: 33,
    height: 1,
    size: 1
  },
  15
]
2020-09-27T11:11:23.204 DEBUG (pid:536791) [events] - Event: BufWinLeave [ 5, -1 ]
2020-09-27T11:11:23.205 DEBUG (pid:536791) [events] - Event: BufHidden [ 5 ]
2020-09-27T11:11:23.430 DEBUG (pid:536791) [events] - Event: InsertCharPre [ 's' ]
2020-09-27T11:11:23.443 DEBUG (pid:536791) [events] - Event: MenuPopupChanged [
  {
    col: 0,
    row: 16,
    scrollbar: false,
    completed_item: {
      word: 'substitute',
      menu: 's[ubstitute] [LS]',
      user_data: '{"cid":1601197883,"source":"vimlsp-1","index":0}',
      info: 'find and replace text',
      kind: '¿',
      abbr: '1 substitute'
    },
    width: 33,
    height: 1,
    size: 1
  },
  15
]
2020-09-27T11:11:23.445 DEBUG (pid:536791) [events] - Event: TextChangedP [ 1, { lnum: 15, col: 5, changedtick: 25, pre: 'subs' } ]
2020-09-27T11:11:23.451 DEBUG (pid:536791) [completion-complete] - Source "vimlsp-1" takes 2ms
2020-09-27T11:11:23.455 DEBUG (pid:536791) [events] - Event: CompleteDone [ {} ]
2020-09-27T11:11:23.463 DEBUG (pid:536791) [events] - Event: MenuPopupChanged [
  {
    col: 0,
    row: 16,
    scrollbar: false,
    completed_item: {
      word: 'substitute',
      menu: 's[ubstitute] [LS]',
      user_data: '{"cid":1601197883,"source":"vimlsp-1","index":0}',
      info: 'find and replace text',
      kind: '¿',
      abbr: '1 substitute'
    },
    width: 33,
    height: 1,
    size: 1
  },
  15
]
2020-09-27T11:11:23.464 DEBUG (pid:536791) [events] - Event: BufWinLeave [ 5, -1 ]
2020-09-27T11:11:23.465 DEBUG (pid:536791) [events] - Event: BufHidden [ 5 ]
2020-09-27T11:11:24.260 DEBUG (pid:536791) [events] - Event: InsertCharPre [ 't' ]
2020-09-27T11:11:24.274 DEBUG (pid:536791) [events] - Event: MenuPopupChanged [
  {
    col: 0,
    row: 16,
    scrollbar: false,
    completed_item: {
      word: 'substitute',
      menu: 's[ubstitute] [LS]',
      user_data: '{"cid":1601197883,"source":"vimlsp-1","index":0}',
      info: 'find and replace text',
      kind: '¿',
      abbr: '1 substitute'
    },
    width: 33,
    height: 1,
    size: 1
  },
  15
]
2020-09-27T11:11:24.276 DEBUG (pid:536791) [events] - Event: TextChangedP [ 1, { lnum: 15, col: 6, changedtick: 36, pre: 'subst' } ]
2020-09-27T11:11:24.280 DEBUG (pid:536791) [completion-complete] - Source "vimlsp-1" takes 2ms
2020-09-27T11:11:24.284 DEBUG (pid:536791) [events] - Event: CompleteDone [ {} ]
2020-09-27T11:11:24.297 DEBUG (pid:536791) [events] - Event: MenuPopupChanged [
  {
    col: 0,
    row: 16,
    scrollbar: false,
    completed_item: {
      word: 'substitute',
      menu: 's[ubstitute] [LS]',
      user_data: '{"cid":1601197884,"source":"vimlsp-1","index":0}',
      info: 'find and replace text',
      kind: '¿',
      abbr: '1 substitute'
    },
    width: 33,
    height: 1,
    size: 1
  },
  15
]
2020-09-27T11:11:24.298 DEBUG (pid:536791) [events] - Event: BufWinLeave [ 5, -1 ]
2020-09-27T11:11:24.298 DEBUG (pid:536791) [events] - Event: BufHidden [ 5 ]
2020-09-27T11:11:24.723 DEBUG (pid:536791) [events] - Event: InsertCharPre [ 'i' ]
2020-09-27T11:11:24.733 DEBUG (pid:536791) [events] - Event: MenuPopupChanged [
  {
    col: 0,
    row: 16,
    scrollbar: false,
    completed_item: {
      word: 'substitute',
      menu: 's[ubstitute] [LS]',
      user_data: '{"cid":1601197884,"source":"vimlsp-1","index":0}',
      info: 'find and replace text',
      kind: '¿',
      abbr: '1 substitute'
    },
    width: 33,
    height: 1,
    size: 1
  },
  15
]
2020-09-27T11:11:24.734 DEBUG (pid:536791) [events] - Event: TextChangedP [ 1, { lnum: 15, col: 7, changedtick: 49, pre: 'substi' } ]
2020-09-27T11:11:24.741 DEBUG (pid:536791) [completion-complete] - Source "vimlsp-1" takes 5ms
2020-09-27T11:11:24.745 DEBUG (pid:536791) [events] - Event: CompleteDone [ {} ]
2020-09-27T11:11:24.752 DEBUG (pid:536791) [events] - Event: MenuPopupChanged [
  {
    col: 0,
    row: 16,
    scrollbar: false,
    completed_item: {
      word: 'substitute',
      menu: 's[ubstitute] [LS]',
      user_data: '{"cid":1601197884,"source":"vimlsp-1","index":0}',
      info: 'find and replace text',
      kind: '¿',
      abbr: '1 substitute'
    },
    width: 33,
    height: 1,
    size: 1
  },
  15
]
2020-09-27T11:11:24.753 DEBUG (pid:536791) [events] - Event: BufWinLeave [ 5, -1 ]
2020-09-27T11:11:24.754 DEBUG (pid:536791) [events] - Event: BufHidden [ 5 ]
2020-09-27T11:11:25.252 DEBUG (pid:536791) [events] - Event: InsertCharPre [ 't' ]
2020-09-27T11:11:25.265 DEBUG (pid:536791) [events] - Event: MenuPopupChanged [
  {
    col: 0,
    row: 16,
    scrollbar: false,
    completed_item: {
      word: 'substitute',
      menu: 's[ubstitute] [LS]',
      user_data: '{"cid":1601197884,"source":"vimlsp-1","index":0}',
      info: 'find and replace text',
      kind: '¿',
      abbr: '1 substitute'
    },
    width: 33,
    height: 1,
    size: 1
  },
  15
]
2020-09-27T11:11:25.266 DEBUG (pid:536791) [events] - Event: TextChangedP [ 1, { lnum: 15, col: 8, changedtick: 64, pre: 'substit' } ]
2020-09-27T11:11:25.276 DEBUG (pid:536791) [completion-complete] - Source "vimlsp-1" takes 6ms
2020-09-27T11:11:25.279 DEBUG (pid:536791) [events] - Event: CompleteDone [ {} ]
2020-09-27T11:11:25.289 DEBUG (pid:536791) [events] - Event: MenuPopupChanged [
  {
    col: 0,
    row: 16,
    scrollbar: false,
    completed_item: {
      word: 'substitute',
      menu: 's[ubstitute] [LS]',
      user_data: '{"cid":1601197885,"source":"vimlsp-1","index":0}',
      info: 'find and replace text',
      kind: '¿',
      abbr: '1 substitute'
    },
    width: 33,
    height: 1,
    size: 1
  },
  15
]
2020-09-27T11:11:25.290 DEBUG (pid:536791) [events] - Event: BufWinLeave [ 5, -1 ]
2020-09-27T11:11:25.290 DEBUG (pid:536791) [events] - Event: BufHidden [ 5 ]
2020-09-27T11:11:25.412 DEBUG (pid:536791) [events] - Event: InsertCharPre [ 'u' ]
2020-09-27T11:11:25.425 DEBUG (pid:536791) [events] - Event: MenuPopupChanged [
  {
    col: 0,
    row: 16,
    scrollbar: false,
    completed_item: {
      word: 'substitute',
      menu: 's[ubstitute] [LS]',
      user_data: '{"cid":1601197885,"source":"vimlsp-1","index":0}',
      info: 'find and replace text',
      kind: '¿',
      abbr: '1 substitute'
    },
    width: 33,
    height: 1,
    size: 1
  },
  15
]
2020-09-27T11:11:25.425 DEBUG (pid:536791) [events] - Event: TextChangedP [ 1, { lnum: 15, col: 9, changedtick: 81, pre: 'substitu' } ]
2020-09-27T11:11:25.434 DEBUG (pid:536791) [completion-complete] - Source "vimlsp-1" takes 6ms
2020-09-27T11:11:25.437 DEBUG (pid:536791) [events] - Event: CompleteDone [ {} ]
2020-09-27T11:11:25.447 DEBUG (pid:536791) [events] - Event: MenuPopupChanged [
  {
    col: 0,
    row: 16,
    scrollbar: false,
    completed_item: {
      word: 'substitute',
      menu: 's[ubstitute] [LS]',
      user_data: '{"cid":1601197885,"source":"vimlsp-1","index":0}',
      info: 'find and replace text',
      kind: '¿',
      abbr: '1 substitute'
    },
    width: 33,
    height: 1,
    size: 1
  },
  15
]
2020-09-27T11:11:25.448 DEBUG (pid:536791) [events] - Event: BufWinLeave [ 5, -1 ]
2020-09-27T11:11:25.448 DEBUG (pid:536791) [events] - Event: BufHidden [ 5 ]
2020-09-27T11:11:26.473 DEBUG (pid:536791) [events] - Event: CompleteDone [ {} ]
2020-09-27T11:11:26.491 DEBUG (pid:536791) [events] - Event: CursorMovedI [ 1, [ 16, 1 ] ]
2020-09-27T11:11:26.491 DEBUG (pid:536791) [events] - Event: TextChangedI [ 1, { lnum: 16, col: 1, changedtick: 82, pre: '' } ]
2020-09-27T11:11:26.492 DEBUG (pid:536791) [events] - Event: BufWinLeave [ 5, -1 ]
2020-09-27T11:11:26.493 DEBUG (pid:536791) [events] - Event: BufHidden [ 5 ]
2020-09-27T11:11:26.793 DEBUG (pid:536791) [events] - Event: CursorHoldI [ 1 ]
2020-09-27T11:11:28.140 DEBUG (pid:536791) [events] - Event: InsertLeave [ 1 ]
2020-09-27T11:11:30.720 DEBUG (pid:536791) [events] - Event: BufWinLeave [ 1, 1000 ]
iamcco commented 4 years ago

This extension doesn't control any select behavior, you should do your own mapping to the what you want.

Example https://github.com/iamcco/dotfiles/blob/master/nvim/viml/plugins.config/coc.nvim.vim#L89

psprint commented 4 years ago

Yes, I've noticed this and solved the issue. It was because of the official configuration snippet from Coc:

  inoremap <expr> <cr> complete_info()["selected"] != "-1" ? "\<C-y>" : "\<C-g>u\<CR>"

Replacing the comple…ted"] token with 1 yields a working single-match completing. The snippet that you've gave is an improvement — no new line is inserted on — however the single-match isn't completed still. I wonder why… is it a bug in complete_info()?

iamcco commented 4 years ago

No idea, it works fine for me.