Skip to content

Commit 0bf7872

Browse files
committed
Improve visibility of wrong configuration
1 parent 6fd558f commit 0bf7872

2 files changed

Lines changed: 34 additions & 6 deletions

File tree

ycmd/completers/language_server/language_server_completer.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,9 @@ def __init__( self, user_options, connection_type = 'stdio' ):
10291029
self._stderr_file = None
10301030
self._server_started = False
10311031

1032+
# Store configuration warnings to show in debug_info
1033+
self._config_warnings = []
1034+
10321035
self._Reset()
10331036

10341037

@@ -1926,11 +1929,11 @@ def _GetSettingsFromExtraConf( self, request_data ):
19261929
matched_keys = [ key for key in lookup_keys if key in completer_settings ]
19271930
if matched_keys:
19281931
if len( matched_keys ) > 1:
1929-
LOGGER.warning( 'Multiple settings found for %s completer: %s. '
1930-
'Using first match %r. Please provide only one key.',
1931-
self.GetServerName(),
1932-
matched_keys,
1933-
matched_keys[ 0 ] )
1932+
warning_msg = ( f'Multiple settings found for {self.GetServerName()} '
1933+
f'completer: {matched_keys}. Using first match '
1934+
f'{matched_keys[ 0 ]!r}. Please provide only one key.' )
1935+
LOGGER.warning( warning_msg )
1936+
self._config_warnings.append( warning_msg )
19341937

19351938
# Use first match
19361939
global_settings = completer_settings[ matched_keys[ 0 ] ]
@@ -3174,7 +3177,7 @@ def ServerStateDescription():
31743177

31753178
return 'Initialized'
31763179

3177-
return [ responses.DebugInfoItem( 'Server State',
3180+
items = [ responses.DebugInfoItem( 'Server State',
31783181
ServerStateDescription() ),
31793182
responses.DebugInfoItem( 'Project Directory',
31803183
self._project_directory ),
@@ -3187,6 +3190,15 @@ def ServerStateDescription():
31873190
sort_keys = True ) ) ]
31883191

31893192

3193+
# Add configuration warnings if any exist
3194+
if self._config_warnings:
3195+
items.append( responses.DebugInfoItem(
3196+
'Configuration Warnings',
3197+
'\n'.join( self._config_warnings ) ) )
3198+
3199+
return items
3200+
3201+
31903202
def _DistanceOfPointToRange( point, range ):
31913203
"""Calculate the distance from a point to a range.
31923204

ycmd/tests/language_server/language_server_completer_test.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@
2020
from hamcrest import ( all_of,
2121
assert_that,
2222
calling,
23+
contains_string,
2324
empty,
2425
ends_with,
2526
equal_to,
27+
has_length,
2628
instance_of,
2729
contains_exactly,
2830
has_entries,
@@ -1632,6 +1634,7 @@ def test_GetSettingsFromExtraConf_WithCompleterSettings_PrimaryKey( self,
16321634
} ) )
16331635

16341636

1637+
16351638
@IsolatedYcmd( {
16361639
'completer_settings': {
16371640
'test-server': {
@@ -1679,6 +1682,19 @@ def test_GetSettingsFromExtraConf_WithDuplicateKeys_UsesFirst( self, app ):
16791682

16801683
# Should have logged warning
16811684
assert_that( logger.warning.called )
1685+
# Get debug items
1686+
debug_items = completer.CommonDebugItems()
1687+
1688+
# Check that warning is in debug info
1689+
warning_items = [ item for item in debug_items
1690+
if item.key == 'Configuration Warnings' ]
1691+
assert_that( warning_items, has_length( 1 ) )
1692+
assert_that( warning_items[ 0 ].value,
1693+
contains_string( 'Multiple settings found' ) )
1694+
assert_that( warning_items[ 0 ].value,
1695+
contains_string( 'test' ) )
1696+
assert_that( warning_items[ 0 ].value,
1697+
contains_string( 'test-server' ) )
16821698

16831699

16841700
@IsolatedYcmd( {

0 commit comments

Comments
 (0)