From c72ec4e93a463fea2d826f0fbac7aede460a045f Mon Sep 17 00:00:00 2001 From: sumneko Date: Mon, 27 May 2019 10:22:46 +0800 Subject: =?UTF-8?q?=E6=B5=AE=E7=82=B9=E6=95=B0=E4=BF=9D=E7=95=9910?= =?UTF-8?q?=E4=BD=8D=E5=B0=8F=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/core/hover/hover.lua | 14 +++++++++++--- 1 file 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 -- cgit v1.2.3