garbas / vim-snipmate

snipMate.vim aims to be a concise vim script that implements some of TextMate's snippets features in Vim.
www.vim.org/scripts/script.php?script_id=2540
2.01k stars 181 forks source link

Feature request: recognize the v:completed_item.snippet and v:completed_item.snippet_trigger for completion snippet expansion #258

Open roxma opened 7 years ago

roxma commented 7 years ago

Hi, I'm the author of nvim-completion-manager (NCM)

Currently NCM uses snipmate for function parameter expansion, and snippets expansions from language server

My current approach is quite hacky

In short, NCM injects the snippet into snipmate. And it remembers to cleanup the injected snippet afterwards.

As discussed in https://github.com/Shougo/neosnippet.vim/issues/398#issuecomment-326472600

This approach has some disavantages.

Here's my proposal:

Things would be a lot easier if a common convension is set up so that snippet engines recognize the v:completed_item.snippet and v:completed_item.snippet_trigger.

The snippet_trigger is useful, for example, in ncm, the popup menu looks like this when there's a file named datetime.noww. A more complicated situation would be non-parameter-expansion snippets.

from datetime import datetime

now = datetime.now
     |         now  [+] now(cls, tz=None) |
     |datetime.noww [ ] ~buf              |

The completion items are

[{
    'word': 'datetime.now',
    'snippet':'now($1)$0',
    'snippet_trigger': 'now',
    'abbr': '         now'
},  {
    'word': 'datetime.noww'
}]

Notice that the now method is left-padded with datetime. to be merged with the items from filepath completion. Without snippet_trigger, the engine may not be able to know it should replace now instead of datetime.now.

This is also related to https://github.com/neovim/neovim/issues/7179, since vim doesn't forward custom field name like snippet and snippet_trigger. Currently ncm also uses some dirty hack to get this to work.

ajzafar commented 7 years ago

This is something I've wanted to do for a long time actually. I think using a pop up completion menu would be a lot simpler than the current multisnip method, and it'd remove the tlib dependency. I've just been struggling finding time for SnipMate as I started a new job not too long ago. Hopefully I can find some time this Labor Day at the latest.

prabirshrestha commented 6 years ago

I'm the author of asyncomplete.vim and vim-lsp. I would also be very much interested in this.