Closed yanyan33333 closed 7 years ago
Thanks for the report. Do you get the same error when trying to load the default_settings.json
file in the Python interpreter?
>>> import json
>>> json.loads( open( 'default_settings.json' ).read() )
No,it runs no error
Does the error still occur when starting Vim with the following minimal vimrc
set nocompatible
set rtp+=~/.vim/bundle/YouCompleteMe
filetype plugin indent on
?
No,it doesn`t work My python version is 2.7.12 I do some test in here
def DefaultOptions():
settings_path = os.path.join(
os.path.dirname( os.path.abspath( __file__ ) ), 'default_settings.json' )
### test #####
f = ReadFile( settings_path )
pprint.pprint(f)
#f = f.encode('utf8')
#pprint.pprint(f)
options = json.loads(f )
pprint.pprint(options)
#### test end ######
#options = json.loads( ReadFile( settings_path ))
options.pop( 'hmac_secret', None )
return options
output in vim :messages
u'{\n "filepath_completion_use_working_dir": 0,\n "auto_trigger": 1,\n "min_num_of_chars_for_completion": 2,\n "min_num_identifier_candidate_chars": 0,\n "semantic_triggers": {},\n "filetype_specific_completion_to_disable": {\n "gitcommit": 1\n },\n "seed_identifiers_with_syntax": 0,\n "collect_identifiers_from_comments_and_strings": 0,\n "collect_identifie rs_from_tags_files": 0,\n "max_num_identifier_candidates": 10,\n "extra_conf_globlist": [],\n "global_ycm_extra_conf": "",\n "confirm_extra_conf": 1,\n "complete_in_comments": 0,\n "complete_in_strings": 1,\n "max_diagnostics_to_display": 30,\n "filetype_whitelist": {\n "*": 1\n },\n "filetype_blacklist": {\n "tagbar": 1,\n "qf": 1,\n "notes": 1,\n "markdown": 1,\n "netrw": 1,\n "unite": 1,\n "text": 1,\n "vimwiki": 1,\n "pandoc": 1,\n "infolog": 1,\n "mail": 1\n },\n "auto_start_csharp_server": 1,\n "au to_stop_csharp_server": 1,\n "use_ultisnips_completer": 1,\n "csharp_server_port": 0,\n "hmac_secret": "",\n "server_keep_logfiles": 0,\n "gocode_binary_path": "",\n "godefbinary path": "",\n "rust_src_path": "",\n "racerd_binary_path": "",\n "python_binary_path": ""\n}\n' Traceback (most recent call last): File "
", line 24, in File "/home/HeroWong/.vim/bundle/YouCompleteMe/autoload/../python/ycm/setup.py", line 49, in SetUpYCM base.LoadJsonDefaultsIntoVim() File "/home/HeroWong/.vim/bundle/YouCompleteMe/autoload/../python/ycm/base.py", line 54, in LoadJsonDefaultsIntoVim defaults = user_options_store.DefaultOptions() File "/home/HeroWong/.vim/bundle/YouCompleteMe/python/ycm/../../third_party/ycmd/ycmd/user_options_store.py", line 62, in DefaultOptions options = json.loads(f ) File "/tools/lib/python2.7/json/init.py", line 339, in loads return _default_decoder.decode(s) File "/tools/lib/python2.7/json/decoder.py", line 364, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/tools/lib/python2.7/json/decoder.py", line 382, in raw_decode raise ValueError("No JSON object could be decoded") ValueError: No JSON object could be decoded
when I encode to utf8 like
def DefaultOptions():
settings_path = os.path.join(
os.path.dirname( os.path.abspath( __file__ ) ), 'default_settings.json' )
### test #####
f = ReadFile( settings_path )
pprint.pprint(f)
f = f.encode('utf8')
print("########## utf8 ##############")
pprint.pprint(f)
options = json.loads(f )
print("########## json ##############")
pprint.pprint(options)
#### test end ######
#options = json.loads( ReadFile( settings_path ))
options.pop( 'hmac_secret', None )
return options
the json.loads works but occur other error , output in vim :messages
u'{\n "filepath_completion_use_working_dir": 0,\n "auto_trigger": 1,\n "min_num_of_chars_for_completion": 2,\n "min_num_identifier_candidate_chars": 0,\n "semantic_triggers": {},\n "filetype_specific_completion_to_disable": {\n "gitcommit": 1\n },\n "seed_identifiers_with_syntax": 0,\n "collect_identifiers_from_comments_and_strings": 0,\n "collect_identifie rs_from_tags_files": 0,\n "max_num_identifier_candidates": 10,\n "extra_conf_globlist": [],\n "global_ycm_extra_conf": "",\n "confirm_extra_conf": 1,\n "complete_in_comments": 0,\n "complete_in_strings": 1,\n "max_diagnostics_to_display": 30,\n "filetypewhitelist": {\n "": 1\n },\n "filetype_blacklist": {\n "tagbar": 1,\n "qf": 1,\n "notes": 1,\n "markdown": 1,\n "netrw": 1,\n "unite": 1,\n "text": 1,\n "vimwiki": 1,\n "pandoc": 1,\n "infolog": 1,\n "mail": 1\n },\n "auto_start_csharp_server": 1,\n "au to_stop_csharp_server": 1,\n "use_ultisnips_completer": 1,\n "csharp_server_port": 0,\n "hmac_secret": "",\n "server_keep_logfiles": 0,\n "gocode_binary_path": "",\n "godefbinary path": "",\n "rust_src_path": "",\n "racerd_binary_path": "",\n "python_binary_path": ""\n}\n' ########## utf8 ############## '{\n "filepath_completion_use_working_dir": 0,\n "auto_trigger": 1,\n "min_num_of_chars_for_completion": 2,\n "min_num_identifier_candidate_chars": 0,\n "semantic_triggers": {},\n "filetype_specific_completion_to_disable": {\n "gitcommit": 1\n },\n "seed_identifiers_with_syntax": 0,\n "collect_identifiers_from_comments_and_strings": 0,\n "collect_identifier s_from_tags_files": 0,\n "max_num_identifier_candidates": 10,\n "extra_conf_globlist": [],\n "global_ycm_extra_conf": "",\n "confirm_extra_conf": 1,\n "complete_in_comments": 0,\n "complete_in_strings": 1,\n "max_diagnostics_to_display": 30,\n "filetypewhitelist": {\n "": 1\n },\n "filetype_blacklist": {\n "tagbar": 1,\n "qf": 1,\n "notes": 1,\n "markdown": 1,\n "netrw": 1,\n "unite": 1,\n "text": 1,\n "vimwiki": 1,\n "pandoc": 1,\n "infolog": 1,\n "mail": 1\n },\n "auto_start_csharp_server": 1,\n "aut o_stop_csharp_server": 1,\n "use_ultisnips_completer": 1,\n "csharp_server_port": 0,\n "hmac_secret": "",\n "server_keep_logfiles": 0,\n "gocode_binary_path": "",\n "godef_binary_p ath": "",\n "rust_src_path": "",\n "racerd_binary_path": "",\n "python_binarypath": ""\n}\n' ########## json ############## {u'a\x00u\x00t\x00o\x00\x00s\x00t\x00a\x00r\x00t\x00\x00c\x00': 1, u'a\x00u\x00t\x00o\x00\x00s\x00t\x00o\x00p\x00\x00c\x00s': 1, u'a\x00u\x00t\x00o\x00\x00t\x00': 1, u'c\x00o\x00l\x00l\x00e\x00c\x00t\x00\x00i\x00d\x00e\x00n\x00t\x00i\x00f\x00i\x00e\x00r': 0, u'c\x00o\x00l\x00l\x00e\x00c\x00t\x00\x00i\x00d\x00e\x00n\x00t\x00i\x00f\x00i\x00e\x00r\x00s\x00\x00f\x00r\x00o': 0, u'c\x00o\x00m\x00p\x00l\x00e\x00t\x00e\x00\x00i': 1, u'c\x00o\x00m\x00p\x00l\x00e\x00t\x00e\x00\x00i\x00': 0, u'c\x00o\x00n\x00f\x00i\x00r\x00m\x00\x00e\x00': 1, u'c\x00s\x00h\x00a\x00r\x00p\x00\x00s\x00e\x00': 0, u'e\x00x\x00t\x00r\x00a\x00\x00c\x00o\x00n\x00f': [], u'f\x00i\x00l\x00e\x00p\x00a\x00t\x00h\x00\x00c\x00o\x00m\x00p\x00l\x00e\x00t\x00i\x00o': 0, u'f\x00i\x00l\x00e\x00t\x00y\x00p\x00e\x00\x00': {u'i\x00n\x00f\x00o': 1, u'm\x00a\x00': 1, u'm\x00a\x00r\x00k\x00': 1, u'n\x00e\x00t': 1, u'n\x00o\x00t': 1, u'p\x00a\x00n\x00': 1, u'q\x00': 1, u't\x00a\x00g\x00': 1, u't\x00e\x00': 1, u'u\x00n\x00i': 1, u'v\x00i\x00m\x00w': 1}, u'f\x00i\x00l\x00e\x00t\x00y\x00p\x00e\x00\x00s\x00p\x00e\x00c\x00i\x00f\x00i\x00c\x00\x00c\x00o': {u'g\x00i\x00t\x00c\x00o': 1}, u'g\x00l\x00o\x00b\x00a\x00l\x00\x00y\x00c\x00m\x00': u'', u'g\x00o\x00c\x00o\x00d\x00e\x00\x00b\x00i\x00': u'', u'g\x00o\x00d\x00e\x00f\x00\x00b\x00i\x00n': u'', u'h\x00m\x00a\x00c\x00\x00s': u'', u'm\x00a\x00x\x00\x00d\x00i\x00a\x00g\x00n\x00o\x00s\x00t\x00i\x00': 30, u'm\x00a\x00x\x00\x00n\x00u\x00m\x00\x00i\x00d\x00e\x00n\x00t\x00i\x00f': 10, u'm\x00i\x00n\x00\x00n\x00u\x00m\x00\x00i\x00d\x00e\x00n\x00t\x00i\x00f\x00i\x00e\x00': 0, u'm\x00i\x00n\x00\x00n\x00u\x00m\x00\x00o\x00f\x00\x00c\x00h\x00a\x00r\x00s': 2, u'p\x00y\x00t\x00h\x00o\x00n\x00\x00b\x00i\x00': u'', u'r\x00a\x00c\x00e\x00r\x00d\x00\x00b\x00i\x00': u'', u'r\x00u\x00s\x00t\x00\x00s\x00r': u'', u's\x00e\x00e\x00d\x00\x00i\x00d\x00e\x00n\x00t\x00i\x00f\x00i\x00e\x00': 0, u's\x00e\x00m\x00a\x00n\x00t\x00i\x00c\x00': {}, u's\x00e\x00r\x00v\x00e\x00r\x00\x00k\x00e\x00e\x00': 0, u'u\x00s\x00e\x00\x00u\x00l\x00t\x00i\x00s\x00n\x00i\x00p': 1} Traceback (most recent call last): File "
", line 24, in File "/home/HeroWong/.vim/bundle/YouCompleteMe/autoload/../python/ycm/setup.py", line 49, in SetUpYCM base.LoadJsonDefaultsIntoVim() File "/home/HeroWong/.vim/bundle/YouCompleteMe/autoload/../python/ycm/base.py", line 58, in LoadJsonDefaultsIntoVim if not vimsupport.VariableExists( new_key ): File "/home/HeroWong/.vim/bundle/YouCompleteMe/autoload/../python/ycm/vimsupport.py", line 587, in VariableExists return GetBoolValue( "exists( '{0}' )".format( EscapeForVim( variable ) ) ) File "/home/HeroWong/.vim/bundle/YouCompleteMe/autoload/../python/ycm/vimsupport.py", line 599, in GetBoolValue return bool( int( vim.eval( variable ) ) ) TypeError: expected string without null bytes
I don't understand why json.loads
is inserting all these null characters \x00
in the result.
Using simplejson
instead of json
could help debug further the issue. Could you install it with pip (pip install simplejson
) then change the DefaultOptions
function to:
def DefaultOptions():
settings_path = os.path.join(
os.path.dirname( os.path.abspath( __file__ ) ), 'default_settings.json' )
import simplejson
options = simplejson.loads( ReadFile( settings_path )
options.pop( 'hmac_secret', None )
return options
and try again?
I try it again but still not working I need to encode the string to utf8 but other error ocurred
def DefaultOptions():
settings_path = os.path.join(
os.path.dirname( os.path.abspath( __file__ ) ), 'default_settings.json' )
import simplejson
options = simplejson.loads( ReadFile( settings_path ).encode('utf8') )
options.pop( 'hmac_secret', None )
return options
Traceback (most recent call last): File "/tools/lib/python2.7/runpy.py", line 174, in _run_module_as_main "main", fname, loader, pkg_name) File "/tools/lib/python2.7/runpy.py", line 72, in _run_code exec code in run_globals File "/home/HeroWong/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/main.py", line 197, in
Main() File "/home/HeroWong/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/main.py", line 157, in Main options, hmac_secret = SetupOptions( args.options_file ) File "/home/HeroWong/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/main.py", line 137, in SetupOptions hmac_secret = ToBytes( base64.b64decode( options[ 'hmac_secret' ] ) ) KeyError: u'hmac_secret'
so I remove _options.pop( 'hmacsecret', None )
def DefaultOptions():
settings_path = os.path.join(
os.path.dirname( os.path.abspath( __file__ ) ), 'default_settings.json' )
import simplejson
options = simplejson.loads( ReadFile( settings_path ).encode('utf8') )
#options.pop( 'hmac_secret', None )
return options
error in :YcmToggleLogs stderr
Traceback (most recent call last): File "/tools/lib/python2.7/runpy.py", line 174, in _run_module_as_main "main", fname, loader, pkg_name) File "/tools/lib/python2.7/runpy.py", line 72, in _run_code exec code in run_globals File "/home/HeroWong/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/main.py", line 197, in
Main() File "/home/HeroWong/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/main.py", line 157, in Main options, hmac_secret = SetupOptions( args.options_file ) File "/home/HeroWong/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/main.py", line 137, in SetupOptions hmac_secret = ToBytes( base64.b64decode( options[ 'hmac_secret' ] ) ) File "/tools/lib/python2.7/base64.py", line 75, in b64decode return binascii.a2b_base64(s) UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-12: ordinal not in range(128)
Maybe something wrong with my python env??
Did you build yourself Python? Could you try with system Python? And you forgot to mention your OS and your Vim version (vim --version
).
Sorry~I build python by myself I use CentOS 6.5 vim version
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Oct 25 2016 12:13:05) Included patches: 1-2 Huge version without GUI. Features included (+) or not (-): +acl +file_in_path +mouse_sgr +tag_old_static +arabic +find_in_path -mouse_sysmouse -tag_any_white +autocmd +float +mouse_urxvt -tcl -balloon_eval +folding +mouse_xterm +termguicolors -browse -footer +multi_byte +terminfo ++builtin_terms +fork() +multi_lang +termresponse +byte_offset +gettext -mzscheme +textobjects +channel -hangul_input +netbeans_intg +timers +cindent +iconv +num64 +title -clientserver +insert_expand +packages -toolbar -clipboard +job +path_extra +user_commands +cmdline_compl +jumplist -perl +vertsplit +cmdline_hist +keymap +persistent_undo +virtualedit +cmdline_info +lambda +postscript +visual +comments +langmap +printer +visualextra +conceal +libcall +profile +viminfo +cryptv +linebreak +python +vreplace +cscope +lispindent -python3 +wildignore +cursorbind +listcmds +quickfix +wildmenu +cursorshape +localmap +reltime +windows +dialog_con -lua +rightleft +writebackup +diff +menu -ruby -X11 +digraphs +mksession +scrollbind -xfontset -dnd +modify_fname +signs -xim -ebcdic +mouse +smartindent -xpm +emacs_tags -mouseshape +startuptime -xsmp +eval +mouse_dec +statusline -xterm_clipboard +ex_extra -mouse_gpm -sun_workshop -xterm_save +extra_search -mouse_jsbterm +syntax
+farsi +mouse_netterm +tag_binary
system vimrc file: "$VIM/vimrc" user vimrc file: "$HOME/.vimrc" 2nd user vimrc file: "~/.vim/vimrc" user exrc file: "$HOME/.exrc" defaults file: "$VIMRUNTIME/defaults.vim" fall-back for $VIM: "/tools/share/vim" Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -I/usr/local/include -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: gcc -L/usr/local/lib -Wl,--as-needed -o vim -lm -lnsl -lncursesw -ldl -L/tools/lib/python2.7/config/ -lpython2.7 -lpthread -ldl -lutil -lm -Xlinker -export-dynamic
It`s a long story you know ......... The default glibc version of CentOS6.5 is 2.12.x, which not supported by YCM, so I build a chaintools env with high version glibc (2.21.x) following the LFS . In other words I build almost everything , so far eveything runs well expect YCM..... Maybe something wrong with the python I built, I will revert the code and try again Thanks your helping @micbou
@yanyan33333 I would recommend http://linuxbrew.sh/ instead of doing it by hand, I use it for building YCM and other tools on a RHEL 6 without problems.
The default glibc version of CentOS6.5 is 2.12.x, which not supported by YCM, so I build a chaintools env with high version glibc (2.21.x) following the LFS .
Did you try with Devtoolset installed?
thank you @vheon I will try it later
not yet@micbou ,can it run on glibc 2.12.x after install by devtoolset?
The default glibc version of CentOS6.5 is 2.12.x, which not supported by YCM
If centos 6.5 is the same as RedHat 6.5. then YCM works fine. I use it every day...
@puremourning I believe that it works fine because you have the devtoolset-2 RHEL 6.5 without the devtoolset-2 is not compatible with the libclang binaries that we use on linux
devtoolset changes the libc version ._0 ? blinks I should look into that :).
I don't use the stock libclangs because of deus ex firewall, so you could be right. :p
Thanks guys I solved the problem. I run the booting script
python __main__.py --options_file ./default_settings.json
in ~/.vim/bundle/YouCompleteMe/thirdparty/ycmd/ycmd
The script runs successfully , it turns out that the python env is no problem
but the using vim I built depends on lower version of glibc(2.12.x),so I rebuild vim with the same glibc version(2.21.x) of python and YCM. Finally, YCM runs no problem
I think it`s some strange compat problems on different version of glibc
After all , thank you very much ^^
I installed YCM successfully ,but when I start vim the info show YouCompleteMe unavailable: No JSON object could be decoded My .vimrc setting
Maybe something wrong with .ycm_extra_conf.py? but I didn`t modify anything I read from vim :messages
the code is
but the file default_settings.json I found is JSON format