ncm2 / ncm2-vim-lsp

MIT License
13 stars 2 forks source link

Parameter expansion broken/improvement #3

Closed phux closed 5 years ago

phux commented 5 years ago

a) The ultisnips parameter expansion is broken for functions that receive an argument of type interface{}.

I type:

fmt.Er
" select Errorf and press the ncm2_ultisnips#expand_or shortcut 

Result: fmt.Errorf(format string, a ...interface{}) is inserted. Cursor is at the $0 position after the closing bracket.

b) The type information is inserted as well when expanding snippets.

I think this is inconvenient, as you always have to modify the expanded arguments. In ncm2-go this is not necessary as the type information is removed from the expanded arguments.

I guess by implementing b) theinterface{} issue in a) would be resolved automatically, right?

roxma commented 5 years ago

Which language server did you use?

Please post your minimal vimrc so that I could reproduce.

phux commented 5 years ago

I use bingo - latest master.

Minimal init.vim:

if !filereadable(expand('/tmp/nvim/autoload/plug.vim'))
    silent call mkdir(expand('/tmp/nvim/autoload', 1), 'p')
    execute '!curl -fLo '.expand('/tmp/nvim/autoload/plug.vim', 1).' https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
    autocmd VimEnter * PlugInstall
endif

call plug#begin('/tmp/nvim/plugged')
Plug 'ncm2/ncm2' | Plug 'roxma/nvim-yarp'
Plug 'ncm2/ncm2-vim-lsp'
Plug 'prabirshrestha/vim-lsp' | Plug 'prabirshrestha/async.vim'
Plug 'ncm2/ncm2-ultisnips' | Plug 'SirVer/ultisnips'
call plug#end()

augroup nvim
  au!
  autocmd BufEnter * call ncm2#enable_for_buffer()
  " enable auto complete for `<backspace>`, `<c-w>` keys.
  " known issue https://github.com/ncm2/ncm2/issues/7
  au TextChangedI * call ncm2#auto_trigger()
  au User Ncm2PopupOpen set completeopt=noinsert,menuone,noselect
  au User Ncm2PopupClose set completeopt=menuone
augroup END

if executable('bingo')
    au User lsp_setup call lsp#register_server({
        \ 'name': 'bingo',
        \ 'cmd': {server_info->['bingo', '-mode', 'stdio', '--logfile', '/tmp/lspserver.log', '--trace']},
        \ 'whitelist': ['go'],
        \ })
endif

inoremap <silent> <expr> <CR> (pumvisible() ? ncm2_ultisnips#expand_or("\<CR>", 'n') : "\<CR>")
inoremap <expr> <TAB> pumvisible() ? "\<c-n>" : "\<TAB>"
phux commented 5 years ago

This is what bingo returns:

{
    "label": "Errorf(format string, a ...interface{})",
    "kind": 3,
    "detail": "error",
    "sortText": "00000",
    "insertText": "Errorf(${1:format string}, ${2:a ...interface\\{\\}})",
    "insertTextFormat": 2,
    "textEdit": {
        "range": {
            "start": {
                "line": 28,
                "character": 5
            },
            "end": {
                "line": 28,
                "character": 5
            }
        },
        "newText": "Errorf(${1:format string}, ${2:a ...interface\\{\\}})"
    }
}
roxma commented 5 years ago

Bingo snippet syntax is invalid,

https://microsoft.github.io/language-server-protocol/specification

Below is the EBNF (extended Backus-Naur form) for snippets. With \ (backslash), you can escape $, } and \. Within choice elements, the backslash also escapes comma and pipe characters.

You could enable ncm2 logging to get the error log: alias nvim-debug='NVIM_PYTHON_LOG_LEVEL=DEBUG NVIM_PYTHON_LOG_FILE=/tmp/nvim.log nvim'

 Exception: encounter invalid syntax: [Errorf(${1:format string}, ${2:a ...interface>>\<<{\}})] expecting '}' character

// cc @saibing

roxma commented 5 years ago

\{ is ambiguous. There's no need to escape {.

phux commented 5 years ago

@roxma what do you think about part b) of my description?

If the type part is removed from the param snippets, the issue would be gone anyway, right?

roxma commented 5 years ago

If the type part is removed from the param snippets, the issue would be gone anyway, right?

The snippet data is served by bingo. We cannot change it without some dirty hack. I think this is out of scope for this plugin.

You might need to look for help at https://github.com/saibing/bingo.

phux commented 5 years ago

Closing as fix was merged into bingo:master