Subcommand name completion works again
This commit is contained in:
parent
718e9974b7
commit
446d02f66e
@ -619,17 +619,13 @@ function! youcompleteme#OpenGoToList()
|
||||
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
|
||||
" 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! youcompleteme#SubCommandsComplete( arglead, cmdline, cursorpos )
|
||||
return join( pyeval( 'ycm_state.GetDefinedSubcommands()' ),
|
||||
\ "\n")
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:ForceCompile()
|
||||
|
@ -26,14 +26,15 @@ import bottle
|
||||
bottle.debug( True )
|
||||
|
||||
# 'contents' should be just one line of text
|
||||
def RequestDataForFileWithContents( filename, contents ):
|
||||
def RequestDataForFileWithContents( filename, contents = None ):
|
||||
real_contents = contents if contents else ''
|
||||
return {
|
||||
'filetypes': ['foo'],
|
||||
'filepath': filename,
|
||||
'line_value': contents,
|
||||
'line_value': real_contents,
|
||||
'file_data': {
|
||||
filename: {
|
||||
'contents': contents,
|
||||
'contents': real_contents,
|
||||
'filetypes': ['foo']
|
||||
}
|
||||
}
|
||||
@ -71,7 +72,7 @@ def GetCompletions_IdentifierCompleter_Works_test():
|
||||
@with_setup( Setup )
|
||||
def GetCompletions_IdentifierCompleter_SyntaxKeywordsAdded_test():
|
||||
app = TestApp( ycmd.app )
|
||||
event_data = RequestDataForFileWithContents( '/foo/bar', '' )
|
||||
event_data = RequestDataForFileWithContents( '/foo/bar' )
|
||||
event_data.update( {
|
||||
'event_name': 'FileReadyToParse',
|
||||
'syntax_keywords': ['foo', 'bar', 'zoo']
|
||||
@ -96,7 +97,7 @@ def GetCompletions_IdentifierCompleter_SyntaxKeywordsAdded_test():
|
||||
@with_setup( Setup )
|
||||
def GetCompletions_UltiSnipsCompleter_Works_test():
|
||||
app = TestApp( ycmd.app )
|
||||
event_data = RequestDataForFileWithContents( '/foo/bar', '' )
|
||||
event_data = RequestDataForFileWithContents( '/foo/bar' )
|
||||
event_data.update( {
|
||||
'event_name': 'BufferVisit',
|
||||
'ultisnips_snippets': [
|
||||
@ -197,6 +198,41 @@ int main()
|
||||
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 )
|
||||
def FiletypeCompletionAvailable_Works_test():
|
||||
app = TestApp( ycmd.app )
|
||||
|
@ -69,12 +69,7 @@ def EventNotification():
|
||||
def RunCompleterCommand():
|
||||
LOGGER.info( 'Received command request')
|
||||
request_data = request.json
|
||||
completer_target = request_data[ 'completer_target' ]
|
||||
|
||||
if completer_target == 'identifier':
|
||||
completer = SERVER_STATE.GetGeneralCompleter().GetIdentifierCompleter()
|
||||
else:
|
||||
completer = SERVER_STATE.GetFiletypeCompleter( request_data[ 'filetypes' ] )
|
||||
completer = _GetCompleterForRequestData( request_data )
|
||||
|
||||
return _JsonResponse( completer.OnUserCommand(
|
||||
request_data[ 'command_arguments' ],
|
||||
@ -124,6 +119,14 @@ def FiletypeCompletionAvailable():
|
||||
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
|
||||
@app.error( 500 )
|
||||
def ErrorHandler( httperror ):
|
||||
@ -136,6 +139,17 @@ def _JsonResponse( 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
|
||||
def _ServerShutdown():
|
||||
if SERVER_STATE:
|
||||
|
@ -100,6 +100,11 @@ class YouCompleteMe( object ):
|
||||
return SendCommandRequest( arguments, completer )
|
||||
|
||||
|
||||
def GetDefinedSubcommands( self ):
|
||||
return BaseRequest.PostDataToHandler( BuildRequestData(),
|
||||
'defined_subcommands' )
|
||||
|
||||
|
||||
def GetCurrentCompletionRequest( self ):
|
||||
return self._current_completion_request
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user