Browse Source

Do not hardcode async diagnostic filetype support

Hardcoding supported filetypes prooved to be error prone, as we have
forgot to add `go`, `rust` and in my fork `swift` to the set. Another
problem with hardcoded filetypes is the `GenericLSPCompleter` which can
provide diagnostics for arbitrary filetypes.

This PR does away with `DIAGNOSTIC_UI_ASYNC_FILETYPES`.
Boris Staletic 5 years ago
parent
commit
7bd054485b
3 changed files with 10 additions and 170 deletions
  1. 5 7
      python/ycm/buffer.py
  2. 0 142
      python/ycm/tests/youcompleteme_test.py
  3. 5 21
      python/ycm/youcompleteme.py

+ 5 - 7
python/ycm/buffer.py

@@ -26,10 +26,8 @@ from ycm import vimsupport
 from ycm.client.event_notification import EventNotification
 from ycm.diagnostic_interface import DiagnosticInterface
 
-
 DIAGNOSTIC_UI_FILETYPES = { 'cpp', 'cs', 'c', 'objc', 'objcpp', 'cuda',
                             'javascript', 'typescript' }
-DIAGNOSTIC_UI_ASYNC_FILETYPES = { 'java' }
 
 
 # Emulates Vim buffer
@@ -39,7 +37,7 @@ DIAGNOSTIC_UI_ASYNC_FILETYPES = { 'java' }
 class Buffer( object ):
 
   def __init__( self, bufnr, user_options, async_diags ):
-    self.number = bufnr
+    self._number = bufnr
     self._parse_tick = 0
     self._handled_tick = 0
     self._parse_request = None
@@ -70,7 +68,7 @@ class Buffer( object ):
     return bool( self._parse_request and self._parse_request.ShouldResend() )
 
 
-  def UpdateDiagnostics( self, force=False ):
+  def UpdateDiagnostics( self, force = False ):
     if force or not self._async_diags:
       self.UpdateWithNewDiagnostics( self._parse_request.Response() )
     else:
@@ -117,7 +115,7 @@ class Buffer( object ):
 
 
   def _ChangedTick( self ):
-    return vimsupport.GetBufferChangedTick( self.number )
+    return vimsupport.GetBufferChangedTick( self._number )
 
 
 class BufferDict( dict ):
@@ -131,7 +129,7 @@ class BufferDict( dict ):
     new_value = self[ key ] = Buffer(
       key,
       self._user_options,
-      any( x in DIAGNOSTIC_UI_ASYNC_FILETYPES
-           for x in vimsupport.GetBufferFiletypes( key ) ) )
+      not any( x in DIAGNOSTIC_UI_FILETYPES
+               for x in vimsupport.GetBufferFiletypes( key ) ) )
 
     return new_value

+ 0 - 142
python/ycm/tests/youcompleteme_test.py

@@ -54,9 +54,6 @@ from ycm.tests.mock_utils import ( MockAsyncServerResponseDone,
                                    MockAsyncServerResponseException )
 
 
-import ycm.youcompleteme as ycm_module
-
-
 @YouCompleteMeInstance()
 def YouCompleteMe_YcmCoreNotImported_test( ycm ):
   assert_that( 'ycm_core', is_not( is_in( sys.modules ) ) )
@@ -720,70 +717,10 @@ def YouCompleteMe_UpdateMatches_ClearDiagnosticMatchesInNewBuffer_test( ycm ):
                has_entries( { 1: empty() } ) )
 
 
-@YouCompleteMeInstance( { 'g:ycm_echo_current_diagnostic': 1,
-                          'g:ycm_always_populate_location_list': 1,
-                          'g:ycm_enable_diagnostic_highlighting': 1 } )
-@patch( 'ycm.youcompleteme.YouCompleteMe.FiletypeCompleterExistsForFiletype',
-        return_value = True )
-@patch( 'ycm.vimsupport.PostVimMessage', new_callable = ExtendedMock )
-def YouCompleteMe_AsyncDiagnosticUpdate_NotAvailableForFIletype_test(
-    ycm, post_vim_message, *args ):
-  diagnostics = [
-    {
-      'kind': 'ERROR',
-      'text': 'error text in current buffer',
-      'location': {
-        'filepath': '/current',
-        'line_num': 1,
-        'column_num': 1
-      },
-      'location_extent': {
-        'start': {
-          'filepath': '/current',
-          'line_num': 1,
-          'column_num': 1,
-        },
-        'end': {
-          'filepath': '/current',
-          'line_num': 1,
-          'column_num': 1,
-        }
-      },
-      'ranges': []
-    },
-  ]
-  current_buffer = VimBuffer( '/current',
-                              filetype = 'ycmtest',
-                              contents = [ 'current' ] * 10,
-                              number = 1 )
-  buffers = [ current_buffer ]
-  windows = [ current_buffer ]
-
-  # Register each buffer internally with YCM
-  for current in buffers:
-    with MockVimBuffers( buffers, [ current ] ):
-      ycm.OnFileReadyToParse()
-  with patch( 'ycm.vimsupport.SetLocationListForWindow',
-              new_callable = ExtendedMock ) as set_location_list_for_window:
-    with MockVimBuffers( buffers, windows ):
-      ycm.UpdateWithNewDiagnosticsForFile( '/current', diagnostics )
-
-  post_vim_message.assert_has_exact_calls( [] )
-  set_location_list_for_window.assert_has_exact_calls( [] )
-
-  assert_that(
-    test_utils.VIM_MATCHES_FOR_WINDOW,
-    empty()
-  )
-
-
 @YouCompleteMeInstance( { 'g:ycm_echo_current_diagnostic': 1,
                           'g:ycm_always_populate_location_list': 1,
                           'g:ycm_show_diagnostics_ui': 0,
                           'g:ycm_enable_diagnostic_highlighting': 1 } )
-@patch.object( ycm_module,
-               'DIAGNOSTIC_UI_ASYNC_FILETYPES',
-               [ 'ycmtest' ] )
 @patch( 'ycm.youcompleteme.YouCompleteMe.FiletypeCompleterExistsForFiletype',
         return_value = True )
 @patch( 'ycm.vimsupport.PostVimMessage', new_callable = ExtendedMock )
@@ -841,71 +778,7 @@ def YouCompleteMe_AsyncDiagnosticUpdate_UserDisabled_test( ycm,
 
 @YouCompleteMeInstance( { 'g:ycm_echo_current_diagnostic': 1,
                           'g:ycm_always_populate_location_list': 1,
-                          'g:ycm_show_diagnostics_ui': 0,
                           'g:ycm_enable_diagnostic_highlighting': 1 } )
-@patch.object( ycm_module,
-               'DIAGNOSTIC_UI_ASYNC_FILETYPES',
-               [ 'ycmtest' ] )
-@patch( 'ycm.youcompleteme.YouCompleteMe.FiletypeCompleterExistsForFiletype',
-        return_value = True )
-@patch( 'ycm.vimsupport.PostVimMessage', new_callable = ExtendedMock )
-def YouCompleteMe_AsyncDiagnosticUpdate_UserDisabledAndNoFiletypeSupport_test(
-    ycm, post_vim_message, *args ):
-  diagnostics = [
-    {
-      'kind': 'ERROR',
-      'text': 'error text in current buffer',
-      'location': {
-        'filepath': '/current',
-        'line_num': 1,
-        'column_num': 1
-      },
-      'location_extent': {
-        'start': {
-          'filepath': '/current',
-          'line_num': 1,
-          'column_num': 1,
-        },
-        'end': {
-          'filepath': '/current',
-          'line_num': 1,
-          'column_num': 1,
-        }
-      },
-      'ranges': []
-    },
-  ]
-  current_buffer = VimBuffer( '/current',
-                              filetype = 'ycmtest',
-                              contents = [ 'current' ] * 10,
-                              number = 1 )
-  buffers = [ current_buffer ]
-  windows = [ current_buffer ]
-
-  # Register each buffer internally with YCM
-  for current in buffers:
-    with MockVimBuffers( buffers, [ current ] ):
-      ycm.OnFileReadyToParse()
-  with patch( 'ycm.vimsupport.SetLocationListForWindow',
-              new_callable = ExtendedMock ) as set_location_list_for_window:
-    with MockVimBuffers( buffers, windows ):
-      ycm.UpdateWithNewDiagnosticsForFile( '/current', diagnostics )
-
-  post_vim_message.assert_has_exact_calls( [] )
-  set_location_list_for_window.assert_has_exact_calls( [] )
-
-  assert_that(
-    test_utils.VIM_MATCHES_FOR_WINDOW,
-    empty()
-  )
-
-
-@YouCompleteMeInstance( { 'g:ycm_echo_current_diagnostic': 1,
-                          'g:ycm_always_populate_location_list': 1,
-                          'g:ycm_enable_diagnostic_highlighting': 1 } )
-@patch.object( ycm_module,
-               'DIAGNOSTIC_UI_ASYNC_FILETYPES',
-               [ 'ycmtest' ] )
 @patch( 'ycm.youcompleteme.YouCompleteMe.FiletypeCompleterExistsForFiletype',
         return_value = True )
 @patch( 'ycm.vimsupport.PostVimMessage', new_callable = ExtendedMock )
@@ -1067,14 +940,8 @@ def YouCompleteMe_AsyncDiagnosticUpdate_SingleFile_test( ycm,
 @YouCompleteMeInstance( { 'g:ycm_echo_current_diagnostic': 1,
                           'g:ycm_always_populate_location_list': 1,
                           'g:ycm_enable_diagnostic_highlighting': 1 } )
-@patch.object( ycm_module,
-               'DIAGNOSTIC_UI_ASYNC_FILETYPES',
-               [ 'ycmtest' ] )
 @patch( 'ycm.youcompleteme.YouCompleteMe.FiletypeCompleterExistsForFiletype',
         return_value = True )
-@patch( 'ycm.youcompleteme.YouCompleteMe.'
-        'DiagnosticUiSupportedForCurrentFiletype',
-        return_value = True )
 @patch( 'ycm.vimsupport.PostVimMessage', new_callable = ExtendedMock )
 def YouCompleteMe_AsyncDiagnosticUpdate_PerFile_test( ycm,
                                                       post_vim_message,
@@ -1270,9 +1137,6 @@ def YouCompleteMe_OnPeriodicTick_ServerNotReady_test( ycm, *args ):
 
 
 @YouCompleteMeInstance()
-@patch.object( ycm_module,
-               'DIAGNOSTIC_UI_ASYNC_FILETYPES',
-               [ 'ycmtest' ] )
 @patch( 'ycm.youcompleteme.YouCompleteMe.FiletypeCompleterExistsForFiletype',
         return_value = True )
 @patch( 'ycm.client.base_request._ValidateResponseObject', return_value = True )
@@ -1319,9 +1183,6 @@ def YouCompleteMe_OnPeriodicTick_DontRetry_test( ycm,
 
 
 @YouCompleteMeInstance()
-@patch.object( ycm_module,
-               'DIAGNOSTIC_UI_ASYNC_FILETYPES',
-               [ 'ycmtest' ] )
 @patch( 'ycm.youcompleteme.YouCompleteMe.FiletypeCompleterExistsForFiletype',
         return_value = True )
 @patch( 'ycm.client.base_request._ValidateResponseObject', return_value = True )
@@ -1355,9 +1216,6 @@ def YouCompleteMe_OnPeriodicTick_Exception_test( ycm,
 
 
 @YouCompleteMeInstance()
-@patch.object( ycm_module,
-               'DIAGNOSTIC_UI_ASYNC_FILETYPES',
-               [ 'ycmtest' ] )
 @patch( 'ycm.youcompleteme.YouCompleteMe.FiletypeCompleterExistsForFiletype',
         return_value = True )
 @patch( 'ycm.client.base_request._ValidateResponseObject', return_value = True )

+ 5 - 21
python/ycm/youcompleteme.py

@@ -32,9 +32,7 @@ import vim
 from subprocess import PIPE
 from tempfile import NamedTemporaryFile
 from ycm import base, paths, signature_help, vimsupport
-from ycm.buffer import ( BufferDict,
-                         DIAGNOSTIC_UI_FILETYPES,
-                         DIAGNOSTIC_UI_ASYNC_FILETYPES )
+from ycm.buffer import BufferDict
 from ycmd import utils
 from ycmd.request_wrap import RequestWrap
 from ycm.omni_completer import OmniCompleter
@@ -451,7 +449,7 @@ class YouCompleteMe( object ):
 
 
   def UpdateWithNewDiagnosticsForFile( self, filepath, diagnostics ):
-    if not self.ShouldDisplayDiagnostics():
+    if not self._user_options[ 'show_diagnostics_ui' ]:
       return
 
     bufnr = vimsupport.GetBufferNumberForFilename( filepath )
@@ -583,17 +581,6 @@ class YouCompleteMe( object ):
     return self.CurrentBuffer().GetWarningCount()
 
 
-  def DiagnosticUiSupportedForCurrentFiletype( self ):
-    return any( x in DIAGNOSTIC_UI_FILETYPES or
-                x in DIAGNOSTIC_UI_ASYNC_FILETYPES
-                for x in vimsupport.CurrentFiletypes() )
-
-
-  def ShouldDisplayDiagnostics( self ):
-    return bool( self._user_options[ 'show_diagnostics_ui' ] and
-                 self.DiagnosticUiSupportedForCurrentFiletype() )
-
-
   def _PopulateLocationListWithLatestDiagnostics( self ):
     return self.CurrentBuffer().PopulateLocationList()
 
@@ -616,15 +603,12 @@ class YouCompleteMe( object ):
          current_buffer.FileParseRequestReady( block ) and
          self.NativeFiletypeCompletionUsable() ):
 
-      if self.ShouldDisplayDiagnostics():
+      if self._user_options[ 'show_diagnostics_ui' ]:
         # Forcefuly update the location list, etc. from the parse request when
         # doing something like :YcmDiags
-        current_buffer.UpdateDiagnostics( block is True )
+        current_buffer.UpdateDiagnostics( block )
       else:
-        # YCM client has a hard-coded list of filetypes which are known
-        # to support diagnostics, self.DiagnosticUiSupportedForCurrentFiletype()
-        #
-        # For filetypes which don't support diagnostics, we just want to check
+        # If the user disabled diagnostics, we just want to check
         # the _latest_file_parse_request for any exception or UnknownExtraConf
         # response, to allow the server to raise configuration warnings, etc.
         # to the user. We ignore any other supplied data.