Skip to content

Commit

Permalink
Merge pull request #4199 from bstaletic/diag-popup-multiline
Browse files Browse the repository at this point in the history
[READY] Properly handle diag text property length in multiline diags
  • Loading branch information
mergify[bot] committed Dec 28, 2023
2 parents 7b83740 + 20d08a2 commit ad9fe2e
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 21 deletions.
8 changes: 4 additions & 4 deletions README.md
Expand Up @@ -210,13 +210,13 @@ Installation

| Runtime | Min Version | Recommended Version (full support) | Python |
|---------|-------------|------------------------------------|--------|
| Vim | 8.1.2269 | 9.0.214 | 3.8 |
| Vim | 8.2.3995 | 9.0.214 | 3.8 |
| Neovim | 0.5 | Vim 9.0.214 | 3.8 |

#### Supported Vim Versions

Our policy is to support the Vim version that's in the latest LTS of Ubuntu.
That's currently Ubuntu 20.04 which contains `vim-nox` at `v8.1.2269`.
That's currently Ubuntu 22.04 which contains `vim-nox` at `v8.2.3995`.

Vim must have a [working Python 3 runtime](#supported-python-runtime).

Expand Down Expand Up @@ -417,7 +417,7 @@ that are conservatively turned off by default that you may want to turn on.

### Linux 64-bit

The following assume you're using Ubuntu 20.04.
The following assume you're using Ubuntu 22.04.

#### Quick start, installing all completers

Expand Down Expand Up @@ -1088,7 +1088,7 @@ On supported architectures, the `install.py` script will download a suitable
clangd (`--clangd-completer`) or libclang (`--clang-completer`) for you.
Supported architectures are:

* Linux glibc >= 2.31 (Intel, armv7-a, aarch64) - built on ubuntu 20.04
* Linux glibc >= 2.31 (Intel, armv7-a, aarch64) - built on ubuntu 22.04
* MacOS >=10.15 (Intel, arm64)
- For Intel, compatibility per clang.llvm.org downloads
- For arm64, macOS 10.15+
Expand Down
8 changes: 4 additions & 4 deletions doc/youcompleteme.txt
Expand Up @@ -428,7 +428,7 @@ Requirements ~
===============================================================================
| _Runtime_ | _Min Version_ | _Recommended Version (full support)_ | _Python_ |
===============================================================================
| Vim | 8.1.2269 | 9.0.214 | 3.8 |
| Vim | 8.2.3995 | 9.0.214 | 3.8 |
-------------------------------------------------------------------------------
| Neovim | 0.5 | Vim 9.0.214 | 3.8 |
-------------------------------------------------------------------------------
Expand All @@ -439,7 +439,7 @@ Requirements ~
Supported Vim Versions ~

Our policy is to support the Vim version that's in the latest LTS of Ubuntu.
That's currently Ubuntu 20.04 which contains 'vim-nox' at 'v8.1.2269'.
That's currently Ubuntu 22.04 which contains 'vim-nox' at 'v8.2.3995'.

Vim must have a working Python 3 runtime.

Expand Down Expand Up @@ -639,7 +639,7 @@ that are conservatively turned off by default that you may want to turn on.
*youcompleteme-linux-64-bit*
Linux 64-bit ~

The following assume you're using Ubuntu 20.04.
The following assume you're using Ubuntu 22.04.

-------------------------------------------------------------------------------
Quick start, installing all completers ~
Expand Down Expand Up @@ -1313,7 +1313,7 @@ On supported architectures, the 'install.py' script will download a suitable
clangd ('--clangd-completer') or libclang ('--clang-completer') for you.
Supported architectures are:

- Linux glibc >= 2.31 (Intel, armv7-a, aarch64) - built on ubuntu 20.04
- Linux glibc >= 2.31 (Intel, armv7-a, aarch64) - built on ubuntu 22.04
- MacOS >=10.15 (Intel, arm64)
- For Intel, compatibility per clang.llvm.org downloads
- For arm64, macOS 10.15+
Expand Down
6 changes: 3 additions & 3 deletions plugin/youcompleteme.vim
Expand Up @@ -24,17 +24,17 @@ function! s:restore_cpo()
unlet s:save_cpo
endfunction

" NOTE: The minimum supported version is 8.1.2269, but neovim always reports as
" NOTE: The minimum supported version is 8.2.3995, but neovim always reports as
" v:version 800, but will largely work.
let s:is_neovim = has( 'nvim' )

if exists( "g:loaded_youcompleteme" )
call s:restore_cpo()
finish
elseif ( v:version < 801 || (v:version == 801 && !has( 'patch2269' )) ) &&
elseif ( v:version < 802 || (v:version == 802 && !has( 'patch3995' )) ) &&
\ !s:is_neovim
echohl WarningMsg |
\ echomsg "YouCompleteMe unavailable: requires Vim 8.1.2269+." |
\ echomsg "YouCompleteMe unavailable: requires Vim 8.2.3995+." |
\ echohl None
call s:restore_cpo()
finish
Expand Down
10 changes: 6 additions & 4 deletions python/ycm/diagnostic_interface.py
Expand Up @@ -277,11 +277,13 @@ def _UpdateSigns( self ):
def _ConvertDiagListToDict( self ):
self._line_to_diags = defaultdict( list )
for diag in self._diagnostics:
location = diag[ 'location' ]
bufnr = vimsupport.GetBufferNumberForFilename( location[ 'filepath' ] )
location_extent = diag[ 'location_extent' ]
start = location_extent[ 'start' ]
end = location_extent[ 'end' ]
bufnr = vimsupport.GetBufferNumberForFilename( start[ 'filepath' ] )
if bufnr == self._bufnr:
line_number = location[ 'line_num' ]
self._line_to_diags[ line_number ].append( diag )
for line_number in range( start[ 'line_num' ], end[ 'line_num' ] + 1 ):
self._line_to_diags[ line_number ].append( diag )

for diags in self._line_to_diags.values():
# We also want errors to be listed before warnings so that errors aren't
Expand Down
29 changes: 26 additions & 3 deletions python/ycm/tests/youcompleteme_test.py
Expand Up @@ -78,15 +78,14 @@ def YouCompleteMe_UpdateDiagnosticInterface( ycm, post_vim_message, *args ):
'line_num': 2,
'column_num': 31
},
# Looks strange but this is really what ycmd is returning.
'location_extent': {
'start': {
'filepath': '',
'filepath': 'buffer',
'line_num': 2,
'column_num': 31,
},
'end': {
'filepath': '',
'filepath': 'buffer',
'line_num': 2,
'column_num': 32,
}
Expand Down Expand Up @@ -624,6 +623,18 @@ def test_YouCompleteMe_ShowDiagnostics_DiagnosticsFound_DoNotOpenLocationList(
'filepath': 'buffer',
'line_num': 19,
'column_num': 2
},
'location_extent': {
'start': {
'filepath': 'buffer',
'line_num': 19,
'column_num': 2
},
'end': {
'filepath': 'buffer',
'line_num': 19,
'column_num': 3
}
}
}

Expand Down Expand Up @@ -673,6 +684,18 @@ def test_YouCompleteMe_ShowDiagnostics_DiagnosticsFound_OpenLocationList(
'filepath': 'buffer',
'line_num': 19,
'column_num': 2
},
'location_extent': {
'start': {
'filepath': 'buffer',
'line_num': 19,
'column_num': 2
},
'end': {
'filepath': 'buffer',
'line_num': 19,
'column_num': 2
}
}
}

Expand Down
17 changes: 16 additions & 1 deletion python/ycm/vimsupport.py
Expand Up @@ -284,7 +284,22 @@ def GetTextPropertyForDiag( buffer_number, line_number, diag ):
range = diag[ 'location_extent' ]
start = range[ 'start' ]
end = range[ 'end' ]
length = end[ 'column_num' ] - start[ 'column_num' ]
start_line = start[ 'line_num' ]
end_line = end[ 'line_num' ]
if start_line == end_line:
length = end[ 'column_num' ] - start[ 'column_num' ]
elif start_line == line_number:
# -1 switches to 0-based indexing.
current_line_len = len( vim.buffers[ buffer_number ][ line_number - 1 ] )
# +2 includes the start columnand accounts for properties at the end of line
# covering \n as well.
length = current_line_len - start[ 'column_num' ] + 2
elif end_line == line_number:
length = end[ 'column_num' ] - 1
else:
# -1 switches to 0-based indexing.
# +1 accounts for properties at the end of line covering \n as well.
length = len( vim.buffers[ buffer_number ][ line_number - 1 ] ) + 1
if diag[ 'kind' ] == 'ERROR':
property_name = 'YcmErrorProperty'
else:
Expand Down
80 changes: 80 additions & 0 deletions test/diagnostics.test.vim
Expand Up @@ -347,3 +347,83 @@ function! Test_ShowDetailedDiagnostic_Popup_WithCharacters()

%bwipe!
endfunction

function! Test_ShowDetailedDiagnostic_Popup_MultilineDiag()
let f = tempname() . '.cc'
execut 'edit' f
call setline( 1, [
\ 'int main () {',
\ 'const int &&',
\ ' /* */',
\ ' rd = 1;',
\ 'rd = 4;',
\ '}',
\ ] )
call youcompleteme#test#setup#WaitForInitialParse( {} )

call WaitForAssert( {->
\ assert_true(
\ py3eval(
\ 'len( ycm_state.CurrentBuffer()._diag_interface._diagnostics )'
\ ) ) } )

" Start of multiline diagnostic.
call cursor( [ 2, 1 ] )
YcmShowDetailedDiagnostic popup

let popup_location = screenpos( bufwinid( '%' ), 3, 13 )
let id = popup_locate( popup_location[ 'row' ], popup_location[ 'col' ] )
call assert_notequal( 0, id, "Couldn't find popup!" )

call youcompleteme#test#popup#CheckPopupPosition( id, {
\ 'visible': 1,
\ 'col': 13,
\ 'line': 3,
\ } )
call assert_match(
\ "^Variable 'rd' declared const here.*",
\ getbufline( winbufnr(id), 1, '$' )[ 0 ] )

" Middle of multiline diagnostic.
call cursor( [ 3, 9 ] )
YcmShowDetailedDiagnostic popup

let popup_location = screenpos( bufwinid( '%' ), 3, 13 )
let id = popup_locate( popup_location[ 'row' ], popup_location[ 'col' ] )
call assert_notequal( 0, id, "Couldn't find popup!" )

" End of multiline diagnostic.
call youcompleteme#test#popup#CheckPopupPosition( id, {
\ 'visible': 1,
\ 'col': 13,
\ 'line': 3,
\ } )
call assert_match(
\ "^Variable 'rd' declared const here.*",
\ getbufline( winbufnr(id), 1, '$' )[ 0 ] )

call cursor( [ 4, 5 ] )
YcmShowDetailedDiagnostic popup

let popup_location = screenpos( bufwinid( '%' ), 3, 13 )
let id = popup_locate( popup_location[ 'row' ], popup_location[ 'col' ] )
call assert_notequal( 0, id, "Couldn't find popup!" )

call youcompleteme#test#popup#CheckPopupPosition( id, {
\ 'visible': 1,
\ 'col': 13,
\ 'line': 3,
\ } )
call assert_match(
\ "^Variable 'rd' declared const here.*",
\ getbufline( winbufnr(id), 1, '$' )[ 0 ] )

" From vim's test_popupwin.vim
" trigger the check for last_cursormoved by going into insert mode
call test_override( 'char_avail', 1 )
call feedkeys( "ji\<Esc>", 'xt' )
call assert_equal( {}, popup_getpos( id ) )
call test_override( 'ALL', 0 )

%bwipe!
endfunction
4 changes: 2 additions & 2 deletions test/docker/ci/image/Dockerfile
@@ -1,9 +1,9 @@
FROM ubuntu:20.04
FROM ubuntu:22.04

ENV DEBIAN_FRONTEND=noninteractive
ENV LC_ALL C.UTF-8

ARG VIM_VERSION=v8.2.2735
ARG VIM_VERSION=v9.0.0214
ARG YCM_VIM_PYTHON=python3
ARG NODE_MAJOR=18

Expand Down

0 comments on commit ad9fe2e

Please sign in to comment.