summaryrefslogtreecommitdiff
path: root/script/core
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-07-08 18:40:07 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-07-08 18:40:07 +0800
commit210288995298fae946468523f5cbcf7e2ed69d68 (patch)
treea95241b8d275bc19f75361452cbd779256961e43 /script/core
parentef87faf3cfca7654095b2c167e0faa20837b1080 (diff)
downloadlua-language-server-210288995298fae946468523f5cbcf7e2ed69d68.zip
显示十进制的数字
Diffstat (limited to 'script/core')
-rw-r--r--script/core/hover/hover.lua29
1 files changed, 28 insertions, 1 deletions
diff --git a/script/core/hover/hover.lua b/script/core/hover/hover.lua
index 7e837698..8bc6f506 100644
--- a/script/core/hover/hover.lua
+++ b/script/core/hover/hover.lua
@@ -315,7 +315,7 @@ end
local function hoverAsString(source)
local str = source[1]
if type(str) ~= 'string' then
- return ''
+ return nil
end
local len = #str
local charLen = utf8.len(str, 1, -1, true)
@@ -351,6 +351,30 @@ local function hoverAsString(source)
}
end
+local function formatNumber(n)
+ local str = ('%.10f'):format(n)
+ str = str:gsub('%.?0*$', '')
+ return str
+end
+
+local function hoverAsNumber(source)
+ local num = source[1]
+ if type(num) ~= 'number' then
+ return nil
+ end
+ local raw = source[2]
+ if not raw:find '[^%-%d%.]' then
+ return nil
+ end
+ return {
+ description = formatNumber(num),
+ range = {
+ start = source.start,
+ finish = source.finish,
+ },
+ }
+end
+
return function (source, lsp, select)
if not source then
return nil
@@ -370,5 +394,8 @@ return function (source, lsp, select)
if source.type == 'string' then
return hoverAsString(source)
end
+ if source.type == 'number' then
+ return hoverAsNumber(source)
+ end
return nil
end