Skip to content

Commit

Permalink
Do not depend on UltiSnips internals
Browse files Browse the repository at this point in the history
Use UltiSnips#SnippetsInCurrentScope to fetch snippets.
Add an entry in the FAQ about the :UltiSnipsAddFiletypes command.
  • Loading branch information
micbou committed Sep 11, 2016
1 parent e804705 commit 882f4ec
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 29 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2648,6 +2648,16 @@ g:UltiSnipsJumpForwardTrigger
g:UltiSnipsJumpBackwardTrigger
```

### Snippets added with `:UltiSnipsAddFiletypes` do not appear in the popup menu

For efficiency, YCM only fetches UltiSnips snippets in specific scenarios like
visiting a buffer or setting its filetype. You can force YCM to retrieve them by
manually triggering the `FileType` autocommand:

```viml
:doautocmd FileType
```

### Why isn't YCM just written in plain VimScript, FFS?

Because of the identifier completion engine and subsequence-based filtering.
Expand Down
43 changes: 14 additions & 29 deletions python/ycm/youcompleteme.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,6 @@
EventNotification )
from ycm.client.shutdown_request import SendShutdownRequest

try:
from UltiSnips import UltiSnips_Manager
USE_ULTISNIPS_DATA = True
except ImportError:
USE_ULTISNIPS_DATA = False


def PatchNoProxy():
current_value = os.environ.get('no_proxy', '')
Expand Down Expand Up @@ -319,7 +313,7 @@ def OnBufferVisit( self ):
if not self.IsServerAlive():
return
extra_data = {}
_AddUltiSnipsDataIfNeeded( extra_data )
self._AddUltiSnipsDataIfNeeded( extra_data )
SendEventNotificationAsync( 'BufferVisit', extra_data )


Expand Down Expand Up @@ -690,25 +684,16 @@ def BuildExtraConfData( extra_conf_vim_data ):
extra_conf_vim_data )


def _AddUltiSnipsDataIfNeeded( extra_data ):
if not USE_ULTISNIPS_DATA:
return

try:
# Since UltiSnips may run in a different python interpreter (python 3) than
# YCM, UltiSnips_Manager singleton is not necessary the same as the one
# used by YCM. In particular, it means that we cannot rely on UltiSnips to
# set the current filetypes to the singleton. We need to do it ourself.
UltiSnips_Manager.reset_buffer_filetypes()
UltiSnips_Manager.add_buffer_filetypes(
vimsupport.GetVariableValue( '&filetype' ) )
rawsnips = UltiSnips_Manager._snips( '', True )
except:
return

# UltiSnips_Manager._snips() returns a class instance where:
# class.trigger - name of snippet trigger word ( e.g. defn or testcase )
# class.description - description of the snippet
extra_data[ 'ultisnips_snippets' ] = [
{ 'trigger': x.trigger, 'description': x.description } for x in rawsnips
]
def _AddUltiSnipsDataIfNeeded( self, extra_data ):
# See :h UltiSnips#SnippetsInCurrentScope.
try:
vim.eval( 'UltiSnips#SnippetsInCurrentScope( 1 )' )
except vim.error:
return

snippets = vimsupport.GetVariableValue( 'g:current_ulti_dict_info' )
extra_data[ 'ultisnips_snippets' ] = [
{ 'trigger': trigger,
'description': snippet[ 'description' ] }
for trigger, snippet in iteritems( snippets )
]

0 comments on commit 882f4ec

Please sign in to comment.