Merge pull request #304 from JazzCore/subcommand_complete

Add subcommand completion for :YcmCompleter command
This commit is contained in:
Val Markovic 2013-05-09 20:21:26 -07:00
commit 48281d1379
4 changed files with 33 additions and 18 deletions

View File

@ -609,7 +609,13 @@ function! youcompleteme#OpenGoToList()
redraw! redraw!
endfunction endfunction
command! -nargs=* YcmCompleter call s:CompleterCommand(<f-args>) command! -nargs=* -complete=custom,youcompleteme#SubCommandsComplete
\ YcmCompleter call s:CompleterCommand(<f-args>)
function! youcompleteme#SubCommandsComplete( arglead, cmdline, cursorpos )
return join( pyeval( 'ycm_state.GetFiletypeCompleter().DefinedSubcommands()' ),
\ "\n")
endfunction
function! s:ForceCompile() function! s:ForceCompile()
if !pyeval( 'ycm_state.NativeFiletypeCompletionUsable()' ) if !pyeval( 'ycm_state.NativeFiletypeCompletionUsable()' )

View File

@ -176,6 +176,18 @@ class Completer( object ):
self.CandidatesForQueryAsyncInner( query, start_column ) self.CandidatesForQueryAsyncInner( query, start_column )
def DefinedSubcommands( self ):
return []
def UserCommandsHelpMessage( self ):
if self.DefinedSubcommands():
vimsupport.EchoText( "Supported commands are:\n" +
'\n'.join( self.DefinedSubcommands() )+
"\nSee the docs for information on what they do." )
else:
vimsupport.EchoText( "No supported subcommands" )
def FilterAndSortCandidates( self, candidates, query ): def FilterAndSortCandidates( self, candidates, query ):
if not candidates: if not candidates:
return [] return []

View File

@ -28,12 +28,6 @@ from flags import Flags
CLANG_FILETYPES = set( [ 'c', 'cpp', 'objc', 'objcpp' ] ) CLANG_FILETYPES = set( [ 'c', 'cpp', 'objc', 'objcpp' ] )
MAX_DIAGNOSTICS_TO_DISPLAY = int( vimsupport.GetVariableValue( MAX_DIAGNOSTICS_TO_DISPLAY = int( vimsupport.GetVariableValue(
"g:ycm_max_diagnostics_to_display" ) ) "g:ycm_max_diagnostics_to_display" ) )
USER_COMMANDS_HELP_MESSAGE = """
Supported commands are:
GoToDefinition
GoToDeclaration
GoToDefinitionElseDeclaration
See the docs for information on what they do."""
class ClangCompleter( Completer ): class ClangCompleter( Completer ):
@ -130,10 +124,15 @@ class ClangCompleter( Completer ):
return results return results
def DefinedSubcommands( self ):
return [ "GoToDefinition",
"GoToDeclaration",
"GoToDefinitionElseDeclaration" ]
def OnUserCommand( self, arguments ): def OnUserCommand( self, arguments ):
if not arguments: if not arguments:
vimsupport.EchoText( USER_COMMANDS_HELP_MESSAGE ) return self.UserCommandsHelpMessage()
return
command = arguments[ 0 ] command = arguments[ 0 ]
if command == 'GoToDefinition': if command == 'GoToDefinition':

View File

@ -38,13 +38,6 @@ except ImportError:
'In the YouCompleteMe folder, run "git submodule update --init --recursive"') 'In the YouCompleteMe folder, run "git submodule update --init --recursive"')
sys.path.pop( 0 ) sys.path.pop( 0 )
USER_COMMANDS_HELP_MESSAGE = """
Supported commands are:
GoToDefinition
GoToDeclaration
GoToDefinitionElseDeclaration
See the docs for information on what they do."""
class JediCompleter( ThreadedCompleter ): class JediCompleter( ThreadedCompleter ):
""" """
@ -80,10 +73,15 @@ class JediCompleter( ThreadedCompleter ):
for completion in script.complete() ] for completion in script.complete() ]
def DefinedSubcommands( self ):
return [ "GoToDefinition",
"GoToDeclaration",
"GoToDefinitionElseDeclaration" ]
def OnUserCommand( self, arguments ): def OnUserCommand( self, arguments ):
if not arguments: if not arguments:
vimsupport.EchoText( USER_COMMANDS_HELP_MESSAGE ) return self.UserCommandsHelpMessage()
return
command = arguments[ 0 ] command = arguments[ 0 ]
if command == 'GoToDefinition': if command == 'GoToDefinition':