gaalcaras / ncm-R

R autocompletion for Neovim and vim 8 :memo: :bar_chart: :zap:
GNU General Public License v3.0
118 stars 10 forks source link

Could not load completion data: 'gbk' codec can't decode byte 0x99 in positon.. #8

Closed ShuguangSun closed 6 years ago

ShuguangSun commented 6 years ago

System: Windows in Chinese (gbk/cp936) Vim: Vim 8 Python: 3.6.3 (will it be supposed to utf8 as default?)

Nvim-R and ncm-R are used. When I type in the R script files, it raise the error message: Could not load completion data: 'gbk' codec can't decode byte 0x99 in positon.. It has been set:

set fileencodings=utf-8,cp936,big5,euc-jp,euc-kr,latin1,ucs-bom

In .Rprofile : options(encoding = "UTF-8") I don't know why the gbk codec comes.

gaalcaras commented 6 years ago

Thanks for your feedback.

Someone else already reported this bug, but it seems it didn't prevent completion from working. Do you just get the warning or is completion broken as well?

I'm working on a fix right now, I'll updated you when I release it.

gaalcaras commented 6 years ago

Okay, I've released a fix on the unicode-fix branch, this how you would install it with vim-plug:

Plug 'gaalcaras/ncm-R', {'branch': 'unicode-fix'}

If you still get an error message and if completion doesn't work, please check the encodings of files in your g:rplugin_compldir directory. My guess is at least one of them is not using correct UTF-8.

ShuguangSun commented 6 years ago

You are right. Some of the files in g:rplugin_compldir are not UTF-8.

gaalcaras commented 6 years ago

All right. Can you please answer the following questions? That would be helpful to write a patch, I'd like to improve the way ncm-R loads completion data:

ShuguangSun commented 6 years ago

It is from Nvim-R: https://github.com/jalvesaq/Nvim-R/issues/276#issuecomment-361588169

gaalcaras commented 6 years ago

Okay, thank you! I see the problem is already solved in Nvim-R, so I'm closing this issue.

ShuguangSun commented 6 years ago

Just for document. In window, the function open will decide the encoding according to the system local (in my case gbk). Even if the file is encoded using utf-8, python open will try to decode it with gbk. It is the error message comes.

In python 3, "encoding='utf-8' in open function can help. However it has side effect and requires all omnils encoded using 'utf-8'.

open(pkg_desc, encoding='utf-8', mode = 'r')
gaalcaras commented 6 years ago

Exactly, that's what https://github.com/gaalcaras/ncm-R/commit/ff3297b8b134847db5107e48c4b75f56ee89ec1e did 😉