Closed Aster89 closed 5 months ago
What happens?
I missed quite an important info! Updated.
@Aster89 Itl think your html formatting got a little screwed. What is the 5th step exactly?
@bstaletic , yep, <kbd>\<kbd>
instead of <kbd>\\<kbd>
is the culprit. Corrected now.
I've hit this again with an Haskell file. Specifically, the following erronous (for whatever reason, ahah) XMonad config file causes the same error as above, when asking diagnostics from the line with def
(all is fine from the following 5 lines):
import XMonad
import qualified XMonad.Prompt as P
main :: IO ()
main = xmonad def
{ terminal = "urxvt"
, modMask = mod4Mask
, borderWidth = 3
, P.borderColor = undefined
}
Managed to repro! Sorry for taking so long. Looks like GetTextPropertyForDiag()
does not take into account multi-line diags.
Here's the raw data that leads to the error (for the C example):
{
"start": {
"line_num": 2,
"column_num": 1,
"filepath": "/home/bstaletic/work/test/foo.cpp"
},
"end": {
"line_num": 3,
"column_num": 11,
"filepath": "/home/bstaletic/work/test/foo.cpp"
}
}
[
{
"id": "4",
"col": "1",
"type_bufnr": "0",
"end": "0",
"type": "YcmWarningProperty",
"length": "13",
"start": "1"
},
{
"id": "3",
"col": "1",
"type_bufnr": "0",
"end": "0",
"type": "YcmWarningProperty",
"length": "13",
"start": "1"
}
]
In GetTextPropertyForDiag()
we end up subtracting end column of next line from start column of this line, leading to bad length calculation.
@Aster89 Try this patch:
diff --git a/python/ycm/vimsupport.py b/python/ycm/vimsupport.py
index 14798145..61852477 100644
--- a/python/ycm/vimsupport.py
+++ b/python/ycm/vimsupport.py
@@ -284,7 +284,16 @@ 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:
+ length = len( vim.buffers[ buffer_number ][ line_number - 1 ] ) - start[ 'column_num' ] + 2
+ elif end_line == line_num:
+ length = end[ 'column_num' ] - 1
+ else:
+ length = len( vim.buffers[ buffer_number ][ line_number - 1 ] )
if diag[ 'kind' ] == 'ERROR':
property_name = 'YcmErrorProperty'
else:
The popup placement is very weird on my computer. Though I thing that has something to do with my vim version.
The patch works!
I've hit another similar error (I'm now on 2b33bf3dc822f6c68b39d235e24efa5508cf9857) with this Haskell code
import Data.Function
getCharAndProcess :: IO ()
getCharAndProcess = do
fix $ \recurse previous -> do
c <- getChar -- on this line
return previous -- or on this line
Trying to show the detailed diag popup on one of the two lines with a comment results in the error above.
Damnit... I did not realize that the previous fix had a sneaky assumption - all mutliline diagnostics start at line 1.
Here's the patch:
diff --git a/python/ycm/vimsupport.py b/python/ycm/vimsupport.py
index ca603206..826a5b59 100644
--- a/python/ycm/vimsupport.py
+++ b/python/ycm/vimsupport.py
@@ -288,18 +288,22 @@ def GetTextPropertyForDiag( buffer_number, line_number, diag ):
end_line = end[ 'line_num' ]
if start_line == end_line:
length = end[ 'column_num' ] - start[ 'column_num' ]
+ column = 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
+ column = start[ 'column_num' ]
elif end_line == line_number:
length = end[ 'column_num' ] - 1
+ column = 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
+ column = 1
if diag[ 'kind' ] == 'ERROR':
property_name = 'YcmErrorProperty'
else:
@@ -309,7 +313,7 @@ def GetTextPropertyForDiag( buffer_number, line_number, diag ):
f'{{ "bufnr": { buffer_number }, '
f'"types": [ "{ property_name }" ] }} )' )
return next( filter(
- lambda p: start[ 'column_num' ] == int( p[ 'col' ] ) and
+ lambda p: column == int( p[ 'col' ] ) and
length == int( p[ 'length' ] ),
vim_props ) )
else:
I'll make a pull request after adjusting the tests.
Sorry for the notification. I had updated YCM but forgotten to close and reopen Vim :D
Actually I have indeed found repro steps for a similar error.
The repros are essentially identical to those in my previous message, except that the following one-line Haskell file should be used instead:
foo txt = (tail txt, tail txt)
The error (again, upon trying to show the detailed diag in the popup) is this:
Error detected while processing function <SNR>32_ShowDetailedDiagnostic:
line 3:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/enrico/.vim/plugged/YouCompleteMe/python/ycm/youcompleteme.py", line 870, in ShowDetailedDiagnostic
options.pop( 'col' )
KeyError: 'col'
This time it was not my oversight! Here's the patch:
diff --git a/python/ycm/youcompleteme.py b/python/ycm/youcompleteme.py
index a09b2ef2..76c8c0a5 100644
--- a/python/ycm/youcompleteme.py
+++ b/python/ycm/youcompleteme.py
@@ -867,7 +867,7 @@ class YouCompleteMe:
'textpropid': prop[ 'id' ],
'textprop': prop[ 'type' ],
} )
- options.pop( 'col' )
+ options.pop( 'col', None )
vim.eval( f'{ popup_func }( { json.dumps( lines ) }, '
f'{ json.dumps( options ) } )' )
else:
Tests incoming.
Yes, the above fixes the issue.
Fixed in #4219
Issue Prelude
Please complete these steps and check these boxes (by putting an
x
inside the brackets) before filing your issue:vim --version
.:YcmDebugInfo
.:YcmToggleLogs
command.vim -Nu /path/to/YCM/vimrc_ycm_minimal
, including what I expected to happen and what actually happened.install.py
(orcmake
/make
/ninja
) including its invocationThank you for adhering to this process! It ensures your issue is resolved quickly and that neither your nor our time is needlessly wasted.
Issue Details
vim -Nu /path/to/YCM/ycm_vimrc_minimal
let g:ycm_show_detailed_diag_in_popup = 1
The C++ error shown in the popup.
A YCM error
Diagnostic data
Output of
vim --version
Output of
YcmDebugInfo
Output of
YcmDiags
Output of
git rev-parse HEAD
in YouCompleteMe installation directoryContents of YCM, ycmd and completion engine logfiles
OS version, distribution, etc.
Up-to-date ArchLinux
Output of build/install commands
No install problem