Update diagnostic matches only in current window

This commit is contained in:
micbou 2018-11-25 23:33:26 +01:00
parent 8216dec954
commit 3151820ff5
No known key found for this signature in database
GPG Key ID: C7E8FD1F3BDA1E05
3 changed files with 21 additions and 65 deletions

View File

@ -129,9 +129,10 @@ class DiagnosticInterface( object ):
if not self._user_options[ 'enable_diagnostic_highlighting' ]: if not self._user_options[ 'enable_diagnostic_highlighting' ]:
return return
with vimsupport.CurrentWindow(): # Vim doesn't provide a way to update the matches for a different window
for window in vimsupport.GetWindowsForBufferNumber( self._bufnr ): # than the current one (which is a view of the current buffer).
vimsupport.SwitchWindow( window ) if vimsupport.GetCurrentBufferNumber() != self._bufnr:
return
matches_to_remove = vimsupport.GetDiagnosticMatchesInCurrentWindow() matches_to_remove = vimsupport.GetDiagnosticMatchesInCurrentWindow()

View File

@ -1047,14 +1047,13 @@ def YouCompleteMe_AsyncDiagnosticUpdate_PerFile_test( ycm,
] ) ] )
] ) ] )
# FIXME: diagnostic matches in windows other than the current one are not
# updated.
assert_that( assert_that(
test_utils.VIM_MATCHES_FOR_WINDOW, test_utils.VIM_MATCHES_FOR_WINDOW,
has_entries( { has_entries( {
1: contains( 1: contains(
VimMatch( 'YcmErrorSection', '\\%1l\\%1c\\_.\\{-}\\%1l\\%1c' ) VimMatch( 'YcmErrorSection', '\\%1l\\%1c\\_.\\{-}\\%1l\\%1c' )
),
3: contains(
VimMatch( 'YcmErrorSection', '\\%3l\\%3c\\_.\\{-}\\%3l\\%3c' )
) )
} ) } )
) )

View File

@ -23,7 +23,6 @@ from __future__ import absolute_import
from builtins import * # noqa from builtins import * # noqa
from future.utils import iterkeys from future.utils import iterkeys
import contextlib
import vim import vim
import os import os
import json import json
@ -1218,49 +1217,6 @@ def BuildRange( start_line, end_line ):
} }
@contextlib.contextmanager
def AutocommandEventsIgnored( events = [ 'all' ] ):
"""Context manager to perform operations without triggering autocommand
events. |events| is a list of events to ignore. By default, all events are
ignored."""
old_eventignore = vim.options[ 'eventignore' ]
ignored_events = {
event for event in ToUnicode( old_eventignore ).split( ',' ) if event }
ignored_events.update( events )
vim.options[ 'eventignore' ] = ','.join( ignored_events )
try:
yield
finally:
vim.options[ 'eventignore' ] = old_eventignore
def GetPreviousWindowNumber():
return GetIntValue( 'winnr("#")' ) - 1
@contextlib.contextmanager
def CurrentWindow():
"""Context manager to perform operations on other windows than the current one
without triggering autocommands related to window movement. Use the
SwitchWindow function to move to other windows while under the context."""
previous_window = vim.windows[ GetPreviousWindowNumber() ]
current_window = vim.current.window
with AutocommandEventsIgnored( [ 'WinEnter', 'Winleave' ] ):
try:
yield
finally:
# Ensure <c-w>p still go to the previous window.
vim.current.window = previous_window
vim.current.window = current_window
def SwitchWindow( window ):
"""Move to the window object |window|. This function should be called under
the CurrentWindow context if you are going to switch back to the original
window."""
vim.current.window = window
# Expects version_string in 'MAJOR.MINOR.PATCH' format, e.g. '8.1.278' # Expects version_string in 'MAJOR.MINOR.PATCH' format, e.g. '8.1.278'
def VimVersionAtLeast( version_string ): def VimVersionAtLeast( version_string ):
major, minor, patch = ( int( x ) for x in version_string.split( '.' ) ) major, minor, patch = ( int( x ) for x in version_string.split( '.' ) )