ultisnips icon indicating copy to clipboard operation
ultisnips copied to clipboard

Add a denite source

Open languitar opened this issue 7 years ago • 9 comments

unite is officially declared as deprecated by the author and denite is the successor. If there is a unite source for ultisnips, there should also be on for denite then.

https://github.com/neoclide/ultisnips already has an implementation for that. Would be nice if that could get merged.

languitar avatar Jun 30 '17 11:06 languitar

@chemzqm It seems you are the author of a few patches to UltiSnips, including a denite source. Would you mind contributing them back?

SirVer avatar Apr 11 '18 06:04 SirVer

@SirVer the problem is it requires snippet location for edit action to work, in pythonx/UltiSnips/snippet_manager.py there is:

            _vim.command(as_unicode(
                "let g:current_ulti_dict['{key}'] = '{val}'").format(
                    key=key.replace("'", "''"),
                    val=description.replace("'", "''")))

there is no way to add extra location information without change the API, so I did that in my fork, I've changed to use list for the return value of snippets_in_current_scope

chemzqm avatar Apr 11 '18 08:04 chemzqm

@chemzqm Can you not always call let snippet_list = UltiSnips#SnippetsInCurrentScope(1) ? That always passes you the location back.

SirVer avatar Apr 12 '18 19:04 SirVer

@SirVer There is argument check for UltiSnips#SnippetsInCurrentScope(1) https://github.com/neoclide/ultisnips/blob/2cd5230abaf1066d403fe8f1329d1e02d30cc5b0/rplugin/python3/denite/source/ultisnips.py#L48

I need to get the location of all snippets so I can provide edit action, I have changed the source code of snippets_in_current_scope function to always give more infomation at https://github.com/neoclide/ultisnips/blob/2cd5230abaf1066d403fe8f1329d1e02d30cc5b0/pythonx/UltiSnips/snippet_manager.py#L172

I didn't contribute that since I noticed this is a break change.

Just find #981 is related

chemzqm avatar May 13 '18 02:05 chemzqm

Any progress on this? Would be really helpful to have such a source for remembering the snippets that are available.

languitar avatar Jul 11 '18 14:07 languitar

I just tried to hack something. What about this:

from .base import Base


class Source(Base):

    def __init__(self, vim):
        super().__init__(vim)

        self.name = 'ultisnips'
        self.kind = 'command'

    def gather_candidates(self, context):
        candidates = []
        snippets = self.vim.eval(
            'UltiSnips#SnippetsInCurrentScope()')
        for trigger in snippets:
            candidates.append({
                'word': '{} -- {}'.format(trigger, snippets.get(trigger, '')),
                'action__command': 'exe "normal a{} " | '
                                   'call UltiSnips#ExpandSnippet()'.format(
                                       trigger),
            })
        return candidates

languitar avatar Jul 11 '18 16:07 languitar

I am interested in this working. Is this something that is on the horizon?

pdoak avatar Dec 06 '18 16:12 pdoak

@pdoak Help would be appreciated! I think the right way to go about this is to add a new function that returns the information required and mark the already existing one as deprecated. This is essentially retracing what @chemzqm did in his fork, but retaining backwards compatibility + adding tests.

SirVer avatar Dec 14 '19 11:12 SirVer

Depends on #981.

SirVer avatar Dec 18 '19 09:12 SirVer