Skip to content

Commit

Permalink
Fix signature help tests
Browse files Browse the repository at this point in the history
  • Loading branch information
puremourning committed Jun 26, 2019
1 parent 0328f5e commit 2061b3b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 52 deletions.
5 changes: 2 additions & 3 deletions ycmd/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def GetSignatureHelp():
request_data = RequestWrap( request.json )

if not _server_state.ShouldUseFiletypeCompleter( request_data ):
return _JsonResponse( {} )
return _JsonResponse( BuildSignatureHelpResponse( None ) )

errors = None
signature_info = None
Expand All @@ -144,8 +144,7 @@ def GetSignatureHelp():
# No fallback for signature help. The general completer is unlikely to be able
# to offer anything of for that here.
return _JsonResponse(
BuildSignatureHelpResponse( signature_info if signature_info else {},
errors = errors ) )
BuildSignatureHelpResponse( signature_info, errors = errors ) )


@app.post( '/filter_and_sort_candidates' )
Expand Down
10 changes: 9 additions & 1 deletion ycmd/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,17 @@ def BuildCompletionResponse( completions,
}


EMPTY_SIGNATURE_INFO = {
'activeSignature': 0,
'activeParameter': 0,
'signatures': []
}


def BuildSignatureHelpResponse( signature_info, errors = None ):
return {
'signature_help': signature_info,
'signature_help':
signature_info if signature_info else EMPTY_SIGNATURE_INFO,
'errors': errors if errors else [],
}

Expand Down
60 changes: 23 additions & 37 deletions ycmd/tests/clangd/signature_help_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
contains,
empty,
equal_to,
has_entries,
is_not )
has_entries )

from ycmd.tests.clangd import PathToTestFile, SharedYcmd
from ycmd.tests.test_utils import ( BuildRequest,
Expand All @@ -42,6 +41,13 @@
from ycmd.utils import ReadFile


EMPTY_SIGNATURE_HELP = has_entries( {
'activeParameter': 0,
'activeSignature': 0,
'signatures': empty(),
} )


def RunTest( app, test ):
"""
Method to run a simple completion test and verify the result
Expand Down Expand Up @@ -79,7 +85,8 @@ def RunTest( app, test ):

# We also ignore errors here, but then we check the response code ourself.
# This is to allow testing of requests returning errors.
response = app.post_json( '/completions', BuildRequest( **request ),
response = app.post_json( '/signature_help',
BuildRequest( **request ),
expect_errors = True )

eq_( response.status_code, test[ 'expect' ][ 'response' ] )
Expand Down Expand Up @@ -118,9 +125,8 @@ def Signature_Help_Trigger_test( app ):
'expect': {
'response': requests.codes.ok,
'data': has_entries( {
'completions': empty(),
'errors': empty(),
'signature_info': has_entries( {
'signature_help': has_entries( {
'activeSignature': 0,
'activeParameter': 0,
'signatures': contains(
Expand Down Expand Up @@ -160,9 +166,8 @@ def Signature_Help_NoTrigger_test( app ):
'expect': {
'response': requests.codes.ok,
'data': has_entries( {
'completions': is_not( empty() ),
'errors': empty(),
'signature_info': empty(),
'signature_help': EMPTY_SIGNATURE_HELP,
} ),
},
} )
Expand All @@ -183,9 +188,8 @@ def Signature_Help_NoTrigger_After_Trigger_test( app ):
'expect': {
'response': requests.codes.ok,
'data': has_entries( {
'completions': empty(),
'errors': empty(),
'signature_info': empty(),
'signature_help': EMPTY_SIGNATURE_HELP,
} ),
},
} )
Expand All @@ -206,9 +210,8 @@ def Signature_Help_Trigger_After_Trigger_test( app ):
'expect': {
'response': requests.codes.ok,
'data': has_entries( {
'completions': empty(),
'errors': empty(),
'signature_info': has_entries( {
'signature_help': has_entries( {
'activeSignature': 0,
'activeParameter': 0,
'signatures': contains(
Expand Down Expand Up @@ -248,9 +251,8 @@ def Signature_Help_Trigger_After_Trigger_PlusText_test( app ):
'expect': {
'response': requests.codes.ok,
'data': has_entries( {
'completions': is_not( empty() ),
'errors': empty(),
'signature_info': has_entries( {
'signature_help': has_entries( {
'activeSignature': 0,
'activeParameter': 0,
'signatures': contains(
Expand Down Expand Up @@ -290,9 +292,8 @@ def Signature_Help_Trigger_After_Trigger_PlusCompletion_test( app ):
'expect': {
'response': requests.codes.ok,
'data': has_entries( {
'completions': is_not( empty() ),
'errors': empty(),
'signature_info': has_entries( {
'signature_help': has_entries( {
'activeSignature': 0,
'activeParameter': 0,
'signatures': contains(
Expand Down Expand Up @@ -332,9 +333,8 @@ def Signature_Help_Trigger_After_OtherTrigger_test( app ):
'expect': {
'response': requests.codes.ok,
'data': has_entries( {
'completions': empty(),
'errors': empty(),
'signature_info': has_entries( {
'signature_help': has_entries( {
'activeSignature': 0,
'activeParameter': 1,
'signatures': contains(
Expand Down Expand Up @@ -374,9 +374,8 @@ def Signature_Help_Trigger_After_Arguments_Narrow_test( app ):
'expect': {
'response': requests.codes.ok,
'data': has_entries( {
'completions': empty(),
'errors': empty(),
'signature_info': has_entries( {
'signature_help': has_entries( {
'activeSignature': 0,
'activeParameter': 2,
'signatures': contains(
Expand Down Expand Up @@ -409,9 +408,8 @@ def Signature_Help_Trigger_After_Arguments_Narrow2_test( app ):
'expect': {
'response': requests.codes.ok,
'data': has_entries( {
'completions': empty(),
'errors': empty(),
'signature_info': has_entries( {
'signature_help': has_entries( {
'activeSignature': 0,
'activeParameter': 2,
'signatures': contains(
Expand Down Expand Up @@ -444,9 +442,8 @@ def Signature_Help_Trigger_After_OtherTrigger_ReTrigger_test( app ):
'expect': {
'response': requests.codes.ok,
'data': has_entries( {
'completions': empty(),
'errors': empty(),
'signature_info': has_entries( {
'signature_help': has_entries( {
'activeSignature': 0,
'activeParameter': 1,
'signatures': contains(
Expand Down Expand Up @@ -486,9 +483,8 @@ def Signature_Help_Trigger_JustBeforeClose( app ):
'expect': {
'response': requests.codes.ok,
'data': has_entries( {
'completions': empty(),
'errors': empty(),
'signature_info': has_entries( {
'signature_help': has_entries( {
'activeSignature': 0,
'activeParameter': 2,
'signatures': contains(
Expand Down Expand Up @@ -521,13 +517,8 @@ def Signature_Help_Clears_After_EndFunction( app ):
'expect': {
'response': requests.codes.ok,
'data': has_entries( {
'completions': empty(),
'errors': empty(),
'signature_info': has_entries( {
'activeSignature': 0,
'activeParameter': 0,
'signatures': empty(),
} ),
'signature_help': EMPTY_SIGNATURE_HELP,
} ),
},
} )
Expand All @@ -548,13 +539,8 @@ def Signature_Help_Clears_After_Function_Call( app ):
'expect': {
'response': requests.codes.ok,
'data': has_entries( {
'completions': empty(),
'errors': empty(),
'signature_info': has_entries( {
'activeSignature': 0,
'activeParameter': 0,
'signatures': empty(),
} ),
'signature_help': EMPTY_SIGNATURE_HELP,
} ),
},
} )
11 changes: 0 additions & 11 deletions ycmd/tests/clangd/testdata/general_fallback/make_drink.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,6 @@

using namespace Test;

int a_really_really_really_really_annoyingly_long_method_name(
int with,
char a,
bool lot,
const char * of,
float arguments
);
int a_really_really_really_really_annoyingly_long_method_name(
int with_only_one_really_really_really_annoyingly_long_argument
);

int main( int , char ** )
{
make_drink( TypeOfDrink::COFFEE, 10.0, Flavour::ELDERFLOWER );
Expand Down

0 comments on commit 2061b3b

Please sign in to comment.