hrsh7th / vim-vsnip-integ

vim-vsnip integrations to other plugins.
MIT License
128 stars 16 forks source link

Smart auto expansion #22

Closed Shatur closed 4 years ago

Shatur commented 4 years ago

Previously you have added auto_expand feature. I use it every day, it is very convenient. But sometimes I do not need expansion, for example:

object.my_function(argument1, argument2);

I want to change my_function I can't use completion because it will be expanded automatically and I will have something like the following:

object.another_function(snippet_argument1, snippet_argument2)(argument1, argument2);

So, I suggest to make this function more smart. For example, do not expand function if next symbol is not a space. This is how it works in most IDE's. Or, as alternative, the ability to complete text without expansion manually. For example, autoexpand on <CR> and insert without expansion with <C-y>.

hrsh7th commented 4 years ago

Thank you for reporting. I have the same opinion we should improve expansion handling.

The LSP spec has the CompletionItem#commitCharacters that is the same concept.

But I'm busy now... anyway I will start considering it.

Shatur commented 4 years ago

Interesting, did not know about commitCharacters property.

hrsh7th commented 4 years ago

Sorry, vsnip_integ can not support LSP's commit character (It would be good to support on completion-engine or LSP client).

But I implemented vsnip#skip_complete_done API. Could you test it?

Shatur commented 4 years ago

Sorry, vsnip_integ can not support LSP's commit character (It would be good to support on completion-engine or LSP client).

Thanks for the explanation!

I tested add-manual-skip with the following mapping from the readme:

inoremap <expr> <C-y> vsnip_integ#skip_complete_done('<C-y>')

But I have the following error on snippet expansion: изображение I just selected built-in function snippet in vim-language-server and pressed <CR>. Also the same with <C-y>.

Do I configured it correctly?

hrsh7th commented 4 years ago

My tested environment are the following.

Hm... this problem seems to have a complex dependency on many of the plugins.

Probably, We should consider more better API than current one.

FYI: I think the error may be avoidable by updating nvim to the latest.

hrsh7th commented 4 years ago

Could you tell me the your tested environment (I think you used completion-nvim + nvim built-in lsp.

Shatur commented 4 years ago

My tested environment are the following.

I tested with exact the same environment! I also updated neovim to the latest commit in master.

But you are right, the problem was in my completion-nvim and pear-tree conflict. The following setting causes the issue:

let g:completion_confirm_key = ''

It used to make the following mapping (the problem exists even without this mapping, only settings above is enough):

imap <expr> <CR> pumvisible() ? complete_info()['selected'] != '-1' ? '<Plug>(completion_confirm_completion)' : '<C-e><CR>' : '<Plug>(PearTreeExpand)'

Can I somehow avoid this conflict? Maybe there is exists another "pairs" plugin without key mappings?

hrsh7th commented 4 years ago

I think the problem does not occurs when if you use C-e instead of C-y.

I want more better solution but I don't know that for now...

Shatur commented 4 years ago

I think the problem does not occurs when if you use C-e instead of C-y.

I tried with the following mapping: inoremap <expr> <C-e> vsnip_integ#skip_complete_done('<C-e>') but it just closes completion window :(

Maybe it is possible to add a function to skip expansion manually? Say, expand completion items on <CR> / <C-y> and do not expand with <A-CR> (for example, user will can map it to any key)?..

Shatur commented 4 years ago

BTW, ho do you handle it? You just do not use snippet auto expansion?

hrsh7th commented 4 years ago

Oh, Sorry I expected to map inoremap <expr> <C-e> vsnip_integ#skip_complete_done('<C-y>').

I guess completion-nvim sends <C-y> as imap instead of inoremap.

So probably we can't use properly <C-y> and <CR> for separate use-case.

Shatur commented 4 years ago

Got it! I think that will be better to send a proposal to completion-nvim to solve this issue. Thank you for your effort!