Closed iswoqqe closed 5 years ago
Thanks for the detailed report. Ideally this would get fixed in vim, because a workaround in YCM will impose a performance impact* on every completion request. However, from my brief testing, this seems to solve it.
diff --git a/python/ycm/youcompleteme.py b/python/ycm/youcompleteme.py
index d94c4f99..bb8cb61a 100644
--- a/python/ycm/youcompleteme.py
+++ b/python/ycm/youcompleteme.py
@@ -316,6 +316,10 @@ class YouCompleteMe( object ):
response = self._latest_completion_request.Response()
response[ 'completions' ] = base.AdjustCandidateInsertionText(
response[ 'completions' ] )
+ # Vim can't pyeval strings with embedded \0 characters.
+ for completion in response[ 'completions' ]:
+ if 'info' in completion:
+ completion[ 'info' ] = completion[ 'info' ].replace( '\x00', '\\x00' )
return response
@iswoqqe Can you try the patch and see if it works for you?
* I have not measured the performance impact, but, since we're looping over all completions, I wouldn't be surprised if this affects users of Windows.h
and unlimited ycm_max_num_candidates
.
Removing null bytes from info seems to fix the issue for now. I'll leave another comment if i run into any problems.
This should be fixed by PR #3208.
@iswoqqe Is this docstring yours or from a third-party library? I am asking this because using null characters in a docstring is most likely a mistake (they won't be displayed when generating the documentation). If it's from a third-party library, you should tell its author to fix it.
they won't be displayed when generating the documentation
I did see the embedded NULL character and the docstring when I used YcmComplter GetDoc
with the current master.
I did see the embedded NULL character and the docstring when I used YcmComplter GetDoc with the current master.
I am not talking about YCM but documentation tools like Sphinx. It's even worse when using the help
function to print the docstring: in that case, the string is truncated at the first null character.
@micbou The docstring was from https://github.com/libtcod/python-tcod. I'll tell them about the issue. Are you referring to pythons help
function? Because it does not truncate the docstring on my machine.
Are you referring to pythons help function? Because it does not truncate the docstring on my machine.
Yes. Looks like it depends on the shell (or the terminal?): I found that it can be printed as ^@
, can be ignored, can be interpreted as a new line, or the string is truncated.
Looks like it depends on the shell (or the terminal?)
Probably both, plus the $TERM
variable and the lister invoked by python. My $MANPAGER
is vim, so python's help
invokes vim
to display help.
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.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
Python functions with docstrings containing null-characters will cause YouCompleteMe.GetCompletionResponse() (in the file
YouCompleteMe/python/ycm/youcompleteme.py
) to return an object that cannot be converted to a vim object. This prevents the auto-completion from working properly and causes the following errors:Possible explanation why objects cannot be converted
It seems like vim uses c-strings (which cannot contain null-characters) internally. I tried converting a couple of python objects to vim objects and got a return value of 0 and the error
E859: Failed to convert returned python object to vim value
for any object containing a string with a null-character.:echo py3eval('"asd"')
returnsasd
:echo py3eval('["as",2]')
return['as', 2]
:echo py3eval('{"key1": 1, "key2": 2}')
returns {'key1': 1, 'key2': 2}:echo py3eval('"asd\x00"')
returns0
and gives errorE859
:echo py3eval('["as\x00",2]')
return0
and gives errorE859
:echo py3eval('{"key\x00": 1, "key2": 2}')
returns0
and gives errorE859
:echo py3eval('{"key1": 1, "key2": "\x00"}')
returns0
and gives errorE859
pyeval
gives the same result aspy3eval
for the above tests.Steps to reproduce
Create two python files in the same directory:
What did you expect to happen?
What actually happened?
Possible solution
I believe it should be possible to simply remove any null bytes from the python strings before they are converted to vim strings without breaking anything.
Diagnostic data
Output of
vim --version
Output of
YcmDebugInfo
Contents of YCM, ycmd and completion engine logfiles
OS version, distribution, etc.
Manjaro linux - fully updated as of 2018-10-28 (using stable repositories)
Output of build/install commands
I do not belive this is relevant to the reported issue, please tell me if it is.