summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server/src/matcher/completion.lua21
-rw-r--r--server/test/completion/init.lua17
2 files changed, 32 insertions, 6 deletions
diff --git a/server/src/matcher/completion.lua b/server/src/matcher/completion.lua
index 0ef3317e..d280cb53 100644
--- a/server/src/matcher/completion.lua
+++ b/server/src/matcher/completion.lua
@@ -115,7 +115,7 @@ local function searchLocals(vm, pos, name, callback)
end
local function searchFields(name, parent, callback)
- if not parent then
+ if not parent or not parent.value or not parent.value.child then
return
end
for key, field in pairs(parent.value.child) do
@@ -163,8 +163,23 @@ end
local function getDetail(var)
local tp = type(var.value.value)
- if tp == 'boolean' or tp == 'number' or tp == 'integer' or tp == 'string' then
- return ('%s = %q'):format(var.key, var.value.value)
+ if tp == 'boolean' then
+ return ('= %q'):format(var.value.value)
+ elseif tp == 'number' then
+ if math.type(var.value.value) == 'integer' then
+ return ('= %q'):format(var.value.value)
+ else
+ local str = ('= %.10f'):format(var.value.value)
+ local dot = str:find('.', 1, true)
+ local suffix = str:find('[0]+$', dot+2)
+ if suffix then
+ return str:sub(1, suffix-1)
+ else
+ return str
+ end
+ end
+ elseif tp == 'string' then
+ return ('= %q'):format(var.value.value)
end
return nil
end
diff --git a/server/test/completion/init.lua b/server/test/completion/init.lua
index c666dd5d..cf827f40 100644
--- a/server/test/completion/init.lua
+++ b/server/test/completion/init.lua
@@ -155,7 +155,7 @@ t.a@
{
label = 'abc',
kind = CompletionItemKind.Enum,
- detail = 'abc = 1',
+ detail = '= 1',
}
}
@@ -167,7 +167,19 @@ z@
{
label = 'zabc',
kind = CompletionItemKind.Variable,
- detail = 'zabc = 1',
+ detail = '= 1',
+ }
+}
+
+TEST [[
+local zabc = 1.0
+z@
+]]
+{
+ {
+ label = 'zabc',
+ kind = CompletionItemKind.Variable,
+ detail = '= 1.0',
}
}
@@ -211,4 +223,3 @@ t.@
kind = CompletionItemKind.Field,
},
}
-