Merge pull request #155 from kljohann/reload
Implement completer-specific commands
This commit is contained in:
commit
c24d272df6
@ -450,6 +450,15 @@ This will print out various debug information for the current file. Useful to
|
||||
see what compile commands will be used for the file if you're using the semantic
|
||||
completion engine.
|
||||
|
||||
### The `YcmCompleter` command
|
||||
|
||||
This command can be used to invoke completer-specific commands. If the first
|
||||
argument is of the form `ft=...` the completer for that file type will be used
|
||||
(for example `ft=cpp`), else the native completer of the current buffer will be
|
||||
used.
|
||||
Call `YcmCompleter` without further arguments for information about the
|
||||
commands you can call for the selected completer.
|
||||
|
||||
Options
|
||||
-------
|
||||
|
||||
|
@ -484,6 +484,40 @@ endfunction
|
||||
|
||||
command! YcmDebugInfo call s:DebugInfo()
|
||||
|
||||
function! s:CompleterCommand(...)
|
||||
" CompleterCommand will call the OnUserCommand function of a completer.
|
||||
" If the first arguments is of the form "ft=..." it can be used to specify the
|
||||
" completer to use (for example "ft=cpp"). Else the native filetype completer
|
||||
" of the current buffer is used. If no native filetype completer is found and
|
||||
" no completer was specified this throws an error. You can use "ft=ycm:omni"
|
||||
" to select the omni completer or "ft=ycm:ident" to select the identifier
|
||||
" completer. The remaining arguments will passed to the completer.
|
||||
let arguments = copy(a:000)
|
||||
|
||||
if a:0 > 0 && strpart(a:1, 0, 3) == 'ft='
|
||||
if a:1 == 'ft=ycm:omni'
|
||||
py completer = ycm_state.GetOmniCompleter()
|
||||
elseif a:1 == 'ft=ycm:ident'
|
||||
py completer = ycm_state.GetIdentifierCompleter()
|
||||
else
|
||||
py completer = ycm_state.GetFiletypeCompleterForFiletype(
|
||||
\ vim.eval('a:1').lstrip('ft=') )
|
||||
endif
|
||||
let arguments = arguments[1:]
|
||||
elseif pyeval( 'ycm_state.NativeFiletypeCompletionAvailable()' )
|
||||
py completer = ycm_state.GetFiletypeCompleter()
|
||||
else
|
||||
echohl WarningMsg |
|
||||
\ echomsg "No native completer found for current buffer." |
|
||||
\ echomsg "Use ft=... as the first argument to specify a completer." |
|
||||
\ echohl None
|
||||
return
|
||||
endif
|
||||
|
||||
py completer.OnUserCommand( vim.eval( 'l:arguments' ) )
|
||||
endfunction
|
||||
|
||||
command! -nargs=* YcmCompleter call s:CompleterCommand(<f-args>)
|
||||
|
||||
function! s:ForceCompile()
|
||||
if !pyeval( 'ycm_state.NativeFiletypeCompletionUsable()' )
|
||||
|
@ -23,6 +23,7 @@ import vimsupport
|
||||
import ycm_core
|
||||
from collections import defaultdict
|
||||
|
||||
NO_USER_COMMANDS = 'This completer does not define any commands.'
|
||||
|
||||
class Completer( object ):
|
||||
"""A base class for all Completers in YCM.
|
||||
@ -96,7 +97,15 @@ class Completer( object ):
|
||||
their specific events occur. For instance, the identifier completer collects
|
||||
all the identifiers in the file in OnFileReadyToParse() which gets called when
|
||||
the user stops typing for 2 seconds (Vim's CursorHold and CursorHoldI events).
|
||||
"""
|
||||
|
||||
One special function is OnUserCommand. It is called when the user uses the
|
||||
command :YcmCompleter and is passed all extra arguments used on command
|
||||
invocation (e.g. OnUserCommand(['first argument', 'second'])). This can be
|
||||
used for completer-specific commands such as reloading external
|
||||
configuration.
|
||||
When the command is called with no arguments you should print a short summary
|
||||
of the supported commands or point the user to the help section where this
|
||||
information can be found."""
|
||||
|
||||
__metaclass__ = abc.ABCMeta
|
||||
|
||||
@ -234,6 +243,10 @@ class Completer( object ):
|
||||
pass
|
||||
|
||||
|
||||
def OnUserCommand( self, arguments ):
|
||||
vimsupport.PostVimMessage( NO_USER_COMMANDS )
|
||||
|
||||
|
||||
def OnCurrentIdentifierFinished( self ):
|
||||
pass
|
||||
|
||||
|
@ -53,6 +53,10 @@ class YouCompleteMe( object ):
|
||||
return self.identcomp
|
||||
|
||||
|
||||
def GetOmniCompleter( self ):
|
||||
return self.omnicomp
|
||||
|
||||
|
||||
def GetFiletypeCompleter( self ):
|
||||
filetypes = vimsupport.CurrentFiletypes()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user