diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-10-22 16:11:07 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-10-22 16:11:07 +0800 |
commit | bd4031bc7dd9e87d007ed5dfedae48a0313a91ff (patch) | |
tree | 8de36b3e4f443ce94636d7114b9a1de033ac6421 /script/core | |
parent | bc7233545056f7bcfc2b50ba476099fa191701de (diff) | |
download | lua-language-server-bd4031bc7dd9e87d007ed5dfedae48a0313a91ff.zip |
修正非法 unicode 字符的计算问题
Diffstat (limited to 'script/core')
-rw-r--r-- | script/core/hover/hover.lua | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/script/core/hover/hover.lua b/script/core/hover/hover.lua index 76505ca4..7b99f8c0 100644 --- a/script/core/hover/hover.lua +++ b/script/core/hover/hover.lua @@ -7,6 +7,14 @@ local lang = require 'language' local config = require 'config' local uric = require 'uri' +local function utf8Len(str, start, finish) + local len, pos = utf8.len(str, start, finish, true) + if len then + return len + end + return 1 + utf8Len(str, start, pos-1) + utf8Len(str, pos+1, finish) +end + local OriginTypes = { ['any'] = true, ['nil'] = true, @@ -322,7 +330,7 @@ local function hoverAsString(source) return nil end local len = #str - local charLen = utf8.len(str, 1, -1, true) + local charLen = utf8Len(str, 1, -1) local lines = {} if len == charLen then lines[#lines+1] = lang.script('HOVER_STRING_BYTES', len) |