diff options
author | sumneko <sumneko@hotmail.com> | 2019-05-27 10:22:46 +0800 |
---|---|---|
committer | sumneko <sumneko@hotmail.com> | 2019-05-27 10:22:46 +0800 |
commit | c72ec4e93a463fea2d826f0fbac7aede460a045f (patch) | |
tree | 986eaf8dc2e9e209bc37e333b1437eecbca136bb | |
parent | 85328f177a6783fab57283b28a0ce9ff0f32402f (diff) | |
download | lua-language-server-c72ec4e93a463fea2d826f0fbac7aede460a045f.zip |
浮点数保留10位小数
-rw-r--r-- | server/src/core/hover/hover.lua | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/server/src/core/hover/hover.lua b/server/src/core/hover/hover.lua index c067899e..d8694766 100644 --- a/server/src/core/hover/hover.lua +++ b/server/src/core/hover/hover.lua @@ -17,6 +17,14 @@ local OriginTypes = { ['function'] = true, } +local function formatLiteral(v) + if math.type(v) == 'float' then + return ('%.10f'):format(v):gsub('[0]*$', ''):gsub('%.$', '.0') + else + return ('%q'):format(v) + end +end + local function findClass(value) -- 检查是否有emmy local emmy = value:getEmmy() @@ -101,7 +109,7 @@ local function unpackTable(value) or vType == 'number' or vType == 'string' then - lines[#lines+1] = ('%s: %s = %q'):format(key, child:getType(), child:getLiteral()) + lines[#lines+1] = ('%s: %s = %s'):format(key, child:getType(), formatLiteral(child:getLiteral())) else lines[#lines+1] = ('%s: %s'):format(key, child:getType()) end @@ -155,10 +163,10 @@ local function getValueHover(source, name, value, lib) local tip local literal if lib then - literal = lib.code or (lib.value and ('%q'):format(lib.value)) + literal = lib.code or (lib.value and formatLiteral(lib.value)) tip = lib.description else - literal = value:getLiteral() and ('%q'):format(value:getLiteral()) + literal = value:getLiteral() and formatLiteral(value:getLiteral()) end local tp |