nvim-lua / completion-nvim

A async completion framework aims to provide completion to neovim's built in LSP written in Lua
Apache License 2.0
975 stars 79 forks source link

Snippet expands with TM message #244

Open ChrisAmelia opened 3 years ago

ChrisAmelia commented 3 years ago

image

My testing minimal init.vim

set runtimepath^=~/.local/share/nvim/plugged/nvim-lspconfig
set runtimepath^=~/.local/share/nvim/plugged/completion-nvim
set runtimepath^=~/.local/share/nvim/plugged/vim-vsnip
set runtimepath^=~/.local/share/nvim/plugged/vim-vsnip-integ

let g:completion_enable_snippet = 'vim-vsnip'

lua << EOF

    local nvim_lsp = require 'nvim_lsp'
    local root_pattern = nvim_lsp.util.root_pattern
    local on_attach_vim = function(client)
        require'completion'.on_attach(client)
    end

    require'nvim_lsp'.jdtls.setup{
        root_dir = root_pattern(".git", "pom.xml"),
        on_attach = on_attach_vim,
    }

EOF

How to reproduce

  1. Create a file Test.java with:
public class Test {

    public static void main(String[] args) {
        // the beneath line might not be necessary,
        // I've managed to reproduce the error without it
        error this is not a valid code;
    }

}
  1. Open the file with:
nvim -u init.vim Test.java
  1. Place the cursor below error this is not a valid code; and type if to display the snippet completion menu.

  2. Select one of the snippets proposed, there should be 4 snippets:

image

The above error doesn't always to appear, it seems to be quite erratic but testing the 4 options should make it happen.

Expected behavior TM message doesn't appear.

haorenW1025 commented 3 years ago

Will this still happen when using the newest commit?

hrsh7th commented 3 years ago

I think it's neovim or completion-nvim's problem.

The completion-nvim will extract completed_item.word that cleaned by vim.lsp.util.parse_snippet. But vim.lsp.util.parse_snippet is

In coc.nvim, the extracting completed_item.word by getValidWord utility (https://github.com/neoclide/coc.nvim/blob/9f9d8a32c4669ba6895e801812c60153b94e22dd/src/util/complete.ts#L77)

When the completion_item.insertText is method($1, $2)$0, the getValidWord will extract method.

hrsh7th commented 3 years ago

Or vim-lamp just use completion_item.label as completed_item.word when the item is snippet kind.

ChrisAmelia commented 3 years ago

Will this still happen when using the newest commit?

Yes, it still happens.