languageserver icon indicating copy to clipboard operation
languageserver copied to clipboard

Problem with Chinese characters

Open longze360 opened this issue 2 years ago • 5 comments
trafficstars

I'm not sure whether this is a bug for REditorSupport/vscode-R, R languageserver packages, or miss settings in vscode.

Description of Problem:

When I wrote an R program that included Chinese characters, the Chinese characters were automatically transformed into unicode.

before:

library(openxlsx)
read.xlsx("中文.xlsx")

after:

library(openxlsx)
read.xlsx("<U+4E2D><U+6587>.xlsx")

Environment (please complete the following information):

OS: Windwos 10 VSCode Version: 1.76.0 R Version: 4.1.3 vscode-R version: v2.7.2

Other Settings:

R>Lsp:Enabled Enable the R language service to provide code analysis features completion,signature,hover,diagnostics,definition,etc.)

r$> sessionInfo() R version 4.1.3 (2022-03-10) Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044)

Matrix products: default

locale: [1] LC_COLLATE=Chinese (Simplified)_China.936 [2] LC_CTYPE=Chinese (Simplified)_China.936
[3] LC_MONETARY=Chinese (Simplified)_China.936 [4] LC_NUMERIC=C [5] LC_TIME=Chinese (Simplified)_China.936

attached base packages: [1] stats graphics grDevices utils
[5] datasets methods base

loaded via a namespace (and not attached):
[1] compiler_4.1.3 cli_3.6.0 [3] jsonlite_1.8.4 rlang_1.0.6

longze360 avatar Mar 08 '23 13:03 longze360

The problem has been resolved after the windows display language in Windows 10 was set to Chinese characters.

longze360 avatar Mar 08 '23 13:03 longze360

You might want to try "BETA: Use Unicode UTF-8 for worldwide language support" in the Windows locale settings. Not sure if it helps.

renkun-ken avatar Mar 08 '23 14:03 renkun-ken

You might want to try "BETA: Use Unicode UTF-8 for worldwide language support" in the Windows locale settings. Not sure if it helps.

Thank you for your suggesting. Unfortunately, I have already tried that and it did not solve the issue I was having. It might be due to the languageserver package which looks for the OS language settings before the system locale for the R session.

longze360 avatar Mar 09 '23 01:03 longze360

One solution to the problem was to place the Sys.setlocale settings before the langserver_library setting in the "Rprofile.site" or ".Rprofile" file.

local({  
	Sys.setlocale("LC_ALL","Chinese")	
	Sys.setenv(LANG = "zh_CN.UTF-8")
})

options(langserver_library = '...{path to languageserver}/languageserver')

longze360 avatar Mar 09 '23 14:03 longze360

Just want to clarify, the issue happened when you set the display language to English? How come you have locale "Chinese (Simplified)_China.936" in an English environment? Did you specify it in your R profile?

It was a well known issue on Windows. https://kevinushey.github.io/blog/2018/02/21/string-encoding-and-r/ not sure it is still the case.

Maybe it is styler to blame?

Randy

randy3k avatar Mar 10 '23 18:03 randy3k