From 0edec9c95a5a3252a4e92a0f831feeed2c9211e6 Mon Sep 17 00:00:00 2001 From: Stanislav Golovanov Date: Thu, 9 May 2013 00:38:56 +0400 Subject: [PATCH] Add subcommand completion for YcmCompleter command --- autoload/youcompleteme.vim | 8 +++++++- python/completers/completer.py | 12 ++++++++++++ python/completers/cpp/clang_completer.py | 15 +++++++-------- python/completers/python/jedi_completer.py | 16 +++++++--------- 4 files changed, 33 insertions(+), 18 deletions(-) diff --git a/autoload/youcompleteme.vim b/autoload/youcompleteme.vim index 4b09d113..fd991d50 100644 --- a/autoload/youcompleteme.vim +++ b/autoload/youcompleteme.vim @@ -609,7 +609,13 @@ function! youcompleteme#OpenGoToList() redraw! endfunction -command! -nargs=* YcmCompleter call s:CompleterCommand() +command! -nargs=* -complete=custom,youcompleteme#SubCommandsComplete + \ YcmCompleter call s:CompleterCommand() + +function! youcompleteme#SubCommandsComplete( arglead, cmdline, cursorpos ) + return join( pyeval( 'ycm_state.GetFiletypeCompleter().DefinedSubcommands()' ), + \ "\n") +endfunction function! s:ForceCompile() if !pyeval( 'ycm_state.NativeFiletypeCompletionUsable()' ) diff --git a/python/completers/completer.py b/python/completers/completer.py index 583d7126..0523a8e3 100644 --- a/python/completers/completer.py +++ b/python/completers/completer.py @@ -176,6 +176,18 @@ class Completer( object ): 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 ): if not candidates: return [] diff --git a/python/completers/cpp/clang_completer.py b/python/completers/cpp/clang_completer.py index 07b8ee4f..c2377d8c 100644 --- a/python/completers/cpp/clang_completer.py +++ b/python/completers/cpp/clang_completer.py @@ -28,12 +28,6 @@ from flags import Flags CLANG_FILETYPES = set( [ 'c', 'cpp', 'objc', 'objcpp' ] ) MAX_DIAGNOSTICS_TO_DISPLAY = int( vimsupport.GetVariableValue( "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 ): @@ -130,10 +124,15 @@ class ClangCompleter( Completer ): return results + def DefinedSubcommands( self ): + return [ "GoToDefinition", + "GoToDeclaration", + "GoToDefinitionElseDeclaration" ] + + def OnUserCommand( self, arguments ): if not arguments: - vimsupport.EchoText( USER_COMMANDS_HELP_MESSAGE ) - return + return self.UserCommandsHelpMessage() command = arguments[ 0 ] if command == 'GoToDefinition': diff --git a/python/completers/python/jedi_completer.py b/python/completers/python/jedi_completer.py index 47909098..a1316e94 100644 --- a/python/completers/python/jedi_completer.py +++ b/python/completers/python/jedi_completer.py @@ -38,13 +38,6 @@ except ImportError: 'In the YouCompleteMe folder, run "git submodule update --init --recursive"') 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 ): """ @@ -80,10 +73,15 @@ class JediCompleter( ThreadedCompleter ): for completion in script.complete() ] + def DefinedSubcommands( self ): + return [ "GoToDefinition", + "GoToDeclaration", + "GoToDefinitionElseDeclaration" ] + + def OnUserCommand( self, arguments ): if not arguments: - vimsupport.EchoText( USER_COMMANDS_HELP_MESSAGE ) - return + return self.UserCommandsHelpMessage() command = arguments[ 0 ] if command == 'GoToDefinition':