From ca8211a64b7fdb4f6f66ce13af558f17b1d8d31b Mon Sep 17 00:00:00 2001 From: micbou Date: Sun, 25 Mar 2018 15:55:57 +0200 Subject: [PATCH] Fix column clamping when highlighting diagnostics on Python 3 --- python/ycm/tests/vimsupport_test.py | 13 +++++++++++++ python/ycm/vimsupport.py | 4 +++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/python/ycm/tests/vimsupport_test.py b/python/ycm/tests/vimsupport_test.py index 65148e21..660b7031 100644 --- a/python/ycm/tests/vimsupport_test.py +++ b/python/ycm/tests/vimsupport_test.py @@ -1281,6 +1281,19 @@ def AddDiagnosticSyntaxMatch_WarningAtEndOfLine_test(): ) +def AddDiagnosticSyntaxMatch_UnicodeAtEndOfLine_test(): + current_buffer = VimBuffer( + 'some_file', + contents = [ 'Highlight unicøde' ] + ) + + with patch( 'vim.current.buffer', current_buffer ): + assert_that( + vimsupport.GetDiagnosticMatchPattern( 1, 16, 1, 19 ), + equal_to( '\%1l\%16c\_.\{-}\%1l\%19c' ) + ) + + @patch( 'vim.command', new_callable=ExtendedMock ) @patch( 'vim.current', new_callable=ExtendedMock) def WriteToPreviewWindow_test( vim_current, vim_command ): diff --git a/python/ycm/vimsupport.py b/python/ycm/vimsupport.py index 559e8f33..427f0b0f 100644 --- a/python/ycm/vimsupport.py +++ b/python/ycm/vimsupport.py @@ -267,7 +267,9 @@ def LineAndColumnNumbersClamped( line_num, column_num ): if line_num and line_num > max_line: new_line_num = max_line - max_column = len( vim.current.buffer[ new_line_num - 1 ] ) + # Vim buffers are a list of byte objects on Python 2 but Unicode objects on + # Python 3. + max_column = len( ToBytes( vim.current.buffer[ new_line_num - 1 ] ) ) if column_num and column_num > max_column: new_column_num = max_column