Subcommand name completion works again

This commit is contained in:
Strahinja Val Markovic 2013-09-27 16:20:35 -07:00
parent 718e9974b7
commit 446d02f66e
4 changed files with 72 additions and 21 deletions

View File

@ -619,17 +619,13 @@ function! youcompleteme#OpenGoToList()
endfunction endfunction
command! -nargs=* YcmCompleter call s:CompleterCommand(<f-args>) command! -nargs=* -complete=custom,youcompleteme#SubCommandsComplete
\ YcmCompleter call s:CompleterCommand(<f-args>)
" TODO: Make this work again function! youcompleteme#SubCommandsComplete( arglead, cmdline, cursorpos )
" command! -nargs=* -complete=custom,youcompleteme#SubCommandsComplete return join( pyeval( 'ycm_state.GetDefinedSubcommands()' ),
" \ YcmCompleter call s:CompleterCommand(<f-args>) \ "\n")
" endfunction
"
" function! youcompleteme#SubCommandsComplete( arglead, cmdline, cursorpos )
" return join( pyeval( 'ycm_state.GetFiletypeCompleter().DefinedSubcommands()' ),
" \ "\n")
" endfunction
function! s:ForceCompile() function! s:ForceCompile()

View File

@ -26,14 +26,15 @@ import bottle
bottle.debug( True ) bottle.debug( True )
# 'contents' should be just one line of text # 'contents' should be just one line of text
def RequestDataForFileWithContents( filename, contents ): def RequestDataForFileWithContents( filename, contents = None ):
real_contents = contents if contents else ''
return { return {
'filetypes': ['foo'], 'filetypes': ['foo'],
'filepath': filename, 'filepath': filename,
'line_value': contents, 'line_value': real_contents,
'file_data': { 'file_data': {
filename: { filename: {
'contents': contents, 'contents': real_contents,
'filetypes': ['foo'] 'filetypes': ['foo']
} }
} }
@ -71,7 +72,7 @@ def GetCompletions_IdentifierCompleter_Works_test():
@with_setup( Setup ) @with_setup( Setup )
def GetCompletions_IdentifierCompleter_SyntaxKeywordsAdded_test(): def GetCompletions_IdentifierCompleter_SyntaxKeywordsAdded_test():
app = TestApp( ycmd.app ) app = TestApp( ycmd.app )
event_data = RequestDataForFileWithContents( '/foo/bar', '' ) event_data = RequestDataForFileWithContents( '/foo/bar' )
event_data.update( { event_data.update( {
'event_name': 'FileReadyToParse', 'event_name': 'FileReadyToParse',
'syntax_keywords': ['foo', 'bar', 'zoo'] 'syntax_keywords': ['foo', 'bar', 'zoo']
@ -96,7 +97,7 @@ def GetCompletions_IdentifierCompleter_SyntaxKeywordsAdded_test():
@with_setup( Setup ) @with_setup( Setup )
def GetCompletions_UltiSnipsCompleter_Works_test(): def GetCompletions_UltiSnipsCompleter_Works_test():
app = TestApp( ycmd.app ) app = TestApp( ycmd.app )
event_data = RequestDataForFileWithContents( '/foo/bar', '' ) event_data = RequestDataForFileWithContents( '/foo/bar' )
event_data.update( { event_data.update( {
'event_name': 'BufferVisit', 'event_name': 'BufferVisit',
'ultisnips_snippets': [ 'ultisnips_snippets': [
@ -197,6 +198,41 @@ int main()
app.post_json( '/run_completer_command', goto_data ).json ) app.post_json( '/run_completer_command', goto_data ).json )
@with_setup( Setup )
def DefinedSubcommands_Works_test():
app = TestApp( ycmd.app )
subcommands_data = RequestDataForFileWithContents( '/foo/bar' )
subcommands_data.update( {
'completer_target': 'python',
} )
eq_( [ 'GoToDefinition',
'GoToDeclaration',
'GoToDefinitionElseDeclaration' ],
app.post_json( '/defined_subcommands', subcommands_data ).json )
@with_setup( Setup )
def DefinedSubcommands_WorksWhenNoExplicitCompleterTargetSpecified_test():
app = TestApp( ycmd.app )
filename = 'foo.py'
subcommands_data = {
'filetypes': ['python'],
'filepath': filename,
'file_data': {
filename: {
'contents': '',
'filetypes': ['python']
}
}
}
eq_( [ 'GoToDefinition',
'GoToDeclaration',
'GoToDefinitionElseDeclaration' ],
app.post_json( '/defined_subcommands', subcommands_data ).json )
@with_setup( Setup ) @with_setup( Setup )
def FiletypeCompletionAvailable_Works_test(): def FiletypeCompletionAvailable_Works_test():
app = TestApp( ycmd.app ) app = TestApp( ycmd.app )

View File

@ -69,12 +69,7 @@ def EventNotification():
def RunCompleterCommand(): def RunCompleterCommand():
LOGGER.info( 'Received command request') LOGGER.info( 'Received command request')
request_data = request.json request_data = request.json
completer_target = request_data[ 'completer_target' ] completer = _GetCompleterForRequestData( request_data )
if completer_target == 'identifier':
completer = SERVER_STATE.GetGeneralCompleter().GetIdentifierCompleter()
else:
completer = SERVER_STATE.GetFiletypeCompleter( request_data[ 'filetypes' ] )
return _JsonResponse( completer.OnUserCommand( return _JsonResponse( completer.OnUserCommand(
request_data[ 'command_arguments' ], request_data[ 'command_arguments' ],
@ -124,6 +119,14 @@ def FiletypeCompletionAvailable():
request.json[ 'filetypes' ] ) ) request.json[ 'filetypes' ] ) )
@app.post( '/defined_subcommands')
def DefinedSubcommands():
LOGGER.info( 'Received defined subcommands request')
completer = _GetCompleterForRequestData( request.json )
return _JsonResponse( completer.DefinedSubcommands() )
# The type of the param is Bottle.HTTPError # The type of the param is Bottle.HTTPError
@app.error( 500 ) @app.error( 500 )
def ErrorHandler( httperror ): def ErrorHandler( httperror ):
@ -136,6 +139,17 @@ def _JsonResponse( data ):
return json.dumps( data ) return json.dumps( data )
def _GetCompleterForRequestData( request_data ):
completer_target = request_data.get( 'completer_target', None )
if completer_target == 'identifier':
return SERVER_STATE.GetGeneralCompleter().GetIdentifierCompleter()
elif completer_target == 'filetype_default' or not completer_target:
return SERVER_STATE.GetFiletypeCompleter( request_data[ 'filetypes' ] )
else:
return SERVER_STATE.GetFiletypeCompleter( [ completer_target ] )
@atexit.register @atexit.register
def _ServerShutdown(): def _ServerShutdown():
if SERVER_STATE: if SERVER_STATE:

View File

@ -100,6 +100,11 @@ class YouCompleteMe( object ):
return SendCommandRequest( arguments, completer ) return SendCommandRequest( arguments, completer )
def GetDefinedSubcommands( self ):
return BaseRequest.PostDataToHandler( BuildRequestData(),
'defined_subcommands' )
def GetCurrentCompletionRequest( self ): def GetCurrentCompletionRequest( self ):
return self._current_completion_request return self._current_completion_request