From 7891bd1f332b6cff17524b97084d1c05144bbf02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Fri, 22 Oct 2021 11:42:13 +0800 Subject: fix #752 --- changelog.md | 1 + script/encoder/init.lua | 24 ++++++++++++++++++++++++ script/encoding/init.lua | 24 ------------------------ script/files.lua | 4 ++-- script/library.lua | 4 ++++ 5 files changed, 31 insertions(+), 26 deletions(-) create mode 100644 script/encoder/init.lua delete mode 100644 script/encoding/init.lua diff --git a/changelog.md b/changelog.md index 796cc74c..1e6a646c 100644 --- a/changelog.md +++ b/changelog.md @@ -3,6 +3,7 @@ ## 2.4.6 * `FIX` [#744](https://github.com/sumneko/lua-language-server/issues/744) * `FIX` [#748](https://github.com/sumneko/lua-language-server/issues/748) +* `FIX` [#752](https://github.com/sumneko/lua-language-server/issues/752) ## 2.4.5 `2021-10-18` diff --git a/script/encoder/init.lua b/script/encoder/init.lua new file mode 100644 index 00000000..a8f9a8ac --- /dev/null +++ b/script/encoder/init.lua @@ -0,0 +1,24 @@ +local platform = require 'bee.platform' +local unicode + +if platform.OS == 'Windows' then + unicode = require 'bee.unicode' +end + +local m = {} + +function m.ansi2utf8(text) + if not unicode then + return text + end + return unicode.a2u(text) +end + +function m.utf82ansi(text) + if not unicode then + return text + end + return unicode.u2a(text) +end + +return m diff --git a/script/encoding/init.lua b/script/encoding/init.lua deleted file mode 100644 index a8f9a8ac..00000000 --- a/script/encoding/init.lua +++ /dev/null @@ -1,24 +0,0 @@ -local platform = require 'bee.platform' -local unicode - -if platform.OS == 'Windows' then - unicode = require 'bee.unicode' -end - -local m = {} - -function m.ansi2utf8(text) - if not unicode then - return text - end - return unicode.a2u(text) -end - -function m.utf82ansi(text) - if not unicode then - return text - end - return unicode.u2a(text) -end - -return m diff --git a/script/files.lua b/script/files.lua index 155a6336..dac23b86 100644 --- a/script/files.lua +++ b/script/files.lua @@ -10,7 +10,7 @@ local util = require 'utility' local guide = require 'parser.guide' local smerger = require 'string-merger' local progress = require "progress" -local encoding = require 'encoding' +local encoder = require 'encoder' ---@class files local m = {} @@ -141,7 +141,7 @@ function m.setText(uri, text, isTrust, instance) end if not isTrust then if config.get 'Lua.runtime.fileEncoding' == 'ansi' then - text = encoding.ansi2utf8(text) + text = encoder.ansi2utf8(text) end end if file.originText == text then diff --git a/script/library.lua b/script/library.lua index 1b074242..ba7dc657 100644 --- a/script/library.lua +++ b/script/library.lua @@ -10,6 +10,7 @@ local define = require "proto.define" local files = require 'files' local await = require 'await' local timer = require 'timer' +local encoder = require 'encoder' local m = {} @@ -235,6 +236,9 @@ local function initBuiltIn() local metaDoc = compileSingleMetaDoc(fsu.loadFile(libPath), metaLang, status) if metaDoc then local outPath = metaPath / libName + if encoding == 'ansi' then + metaDoc = encoder.utf82ansi(metaDoc) + end out:saveFile(libName, metaDoc) m.metaPaths[#m.metaPaths+1] = outPath:string() end -- cgit v1.2.3