summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-07-02 14:12:58 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-07-02 14:12:58 +0800
commit97da24513806acf4c4bf125fbd1c1fafb598ed75 (patch)
tree3c74131b378071e06594fa2d530579574c3043a5
parentea3ad89fb19967e7d268111002e63e730744c790 (diff)
downloadlua-language-server-97da24513806acf4c4bf125fbd1c1fafb598ed75.zip
#186 只有当存在转义符时才显示字符串内容
-rw-r--r--script/core/hover/hover.lua39
1 files changed, 16 insertions, 23 deletions
diff --git a/script/core/hover/hover.lua b/script/core/hover/hover.lua
index c7f10eb5..073886ad 100644
--- a/script/core/hover/hover.lua
+++ b/script/core/hover/hover.lua
@@ -318,36 +318,29 @@ local function hoverAsString(source)
end
local len = #str
local charLen = utf8.len(str, 1, -1, true)
- -- TODO 翻译
+ local lines = {}
if len == charLen then
- return {
- description = ([[
-%s
-
-------------------
-```txt
-%s
-```]]):format(lang.script('HOVER_STRING_BYTES', len), str),
- range = {
- start = source.start,
- finish = source.finish,
- },
- }
+ lines[#lines+1] = lang.script('HOVER_STRING_BYTES', len)
else
- return {
- description = ([[
-%s
+ lines[#lines+1] = lang.script('HOVER_STRING_CHARACTERS', len, charLen)
+ end
+ -- 内部包含转义符?
+ local rawLen = source.finish - source.start - 2 * #source[2]
+ if rawLen > #str then
+ lines[#lines+1] = ([[
------------------
```txt
%s
-```]]):format(lang.script('HOVER_STRING_CHARACTERS', len, charLen), str),
- range = {
- start = source.start,
- finish = source.finish,
- },
- }
+```]]):format(str)
end
+ return {
+ description = table.concat(lines, '\n'),
+ range = {
+ start = source.start,
+ finish = source.finish,
+ },
+ }
end
return function (source, lsp, select)