Giter VIP home page Giter VIP logo

Comments (16)

bstaletic avatar bstaletic commented on August 16, 2024 1

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:

from youcompleteme.

bstaletic avatar bstaletic commented on August 16, 2024 1

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.

from youcompleteme.

puremourning avatar puremourning commented on August 16, 2024

What happens?

from youcompleteme.

Aster89 avatar Aster89 commented on August 16, 2024

I missed quite an important info! Updated.

from youcompleteme.

bstaletic avatar bstaletic commented on August 16, 2024

@Aster89 Itl think your html formatting got a little screwed. What is the 5th step exactly?

from youcompleteme.

Aster89 avatar Aster89 commented on August 16, 2024

@bstaletic , yep, <kbd>\<kbd> instead of <kbd>\\<kbd> is the culprit. Corrected now.

from youcompleteme.

Aster89 avatar Aster89 commented on August 16, 2024

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
    }

from youcompleteme.

bstaletic avatar bstaletic commented on August 16, 2024

Managed to repro! Sorry for taking so long. Looks like GetTextPropertyForDiag() does not take into account multi-line diags.

from youcompleteme.

bstaletic avatar bstaletic commented on August 16, 2024

The popup placement is very weird on my computer. Though I thing that has something to do with my vim version.

from youcompleteme.

Aster89 avatar Aster89 commented on August 16, 2024

The patch works!

from youcompleteme.

Aster89 avatar Aster89 commented on August 16, 2024

I've hit another similar error (I'm now on 2b33bf3) 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.

See screencast below:
asciicast

from youcompleteme.

bstaletic avatar bstaletic commented on August 16, 2024

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.

from youcompleteme.

Aster89 avatar Aster89 commented on August 16, 2024

Sorry for the notification. I had updated YCM but forgotten to close and reopen Vim :D

from youcompleteme.

Aster89 avatar Aster89 commented on August 16, 2024

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'

from youcompleteme.

Aster89 avatar Aster89 commented on August 16, 2024

Yes, the above fixes the issue.

from youcompleteme.

bstaletic avatar bstaletic commented on August 16, 2024

Fixed in #4219

from youcompleteme.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.