summaryrefslogtreecommitdiff
path: root/script/core
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-07-01 14:01:32 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-07-01 14:01:32 +0800
commit85e12909c541c00b5947db5f91dbbba903d8339c (patch)
treed17dea4b9d9f25e7c826e4372067027d855ea574 /script/core
parent3c6093968f6b9c73628763b646d97a8870ffeb12 (diff)
downloadlua-language-server-85e12909c541c00b5947db5f91dbbba903d8339c.zip
字符串详情
Diffstat (limited to 'script/core')
-rw-r--r--script/core/hover/hover.lua42
1 files changed, 42 insertions, 0 deletions
diff --git a/script/core/hover/hover.lua b/script/core/hover/hover.lua
index 1e8cf4d1..fdf9d26f 100644
--- a/script/core/hover/hover.lua
+++ b/script/core/hover/hover.lua
@@ -310,6 +310,45 @@ local function hoverAsTargetUri(source, lsp)
}
end
+local function hoverAsString(source)
+ local str = source[1]
+ if type(str) ~= 'string' then
+ return ''
+ end
+ local len = #str
+ local charLen = utf8.len(str, 1, -1, true)
+ -- TODO 翻译
+ if len == charLen then
+ return {
+ description = ([[
+%d 个字节
+
+------------------
+```txt
+%s
+```]]):format(len, str),
+ range = {
+ start = source.start,
+ finish = source.finish,
+ },
+ }
+ else
+ return {
+ description = ([[
+%d 个字节,%d 个字符
+
+------------------
+```txt
+%s
+```]]):format(len, charLen, str),
+ range = {
+ start = source.start,
+ finish = source.finish,
+ },
+ }
+ end
+end
+
return function (source, lsp, select)
if not source then
return nil
@@ -326,5 +365,8 @@ return function (source, lsp, select)
return hoverAsValue(source, lsp, select)
end
end
+ if source.type == 'string' then
+ return hoverAsString(source)
+ end
return nil
end