summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-08-27 21:36:43 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-08-27 21:36:43 +0800
commitf3ef253b0c5ced3727e96df88fa16886f03325ec (patch)
treedd416f67f75b00e85a7acb515efecfcfde419e30 /server
parent7d041b4d7507190141eaac05501d479b77aa8771 (diff)
downloadlua-language-server-f3ef253b0c5ced3727e96df88fa16886f03325ec.zip
调用片段支持枚举
Diffstat (limited to 'server')
-rw-r--r--server/src/core/completion.lua14
-rw-r--r--server/src/core/hover/emmy_function.lua8
-rw-r--r--server/src/core/hover/function.lua9
-rw-r--r--server/src/core/hover/lib_function.lua8
-rw-r--r--server/test/crossfile/hover.lua2
5 files changed, 31 insertions, 10 deletions
diff --git a/server/src/core/completion.lua b/server/src/core/completion.lua
index d47f768f..d5078a07 100644
--- a/server/src/core/completion.lua
+++ b/server/src/core/completion.lua
@@ -153,10 +153,16 @@ local function getKind(cata, value)
return nil
end
-local function buildSnipArgs(args)
+local function buildSnipArgs(args, enums)
local t = {}
- for i, name in ipairs(args) do
- t[i] = ('${%d:%s}'):format(i, name)
+ for i, arg in ipairs(args) do
+ local name = arg:match '^[^:]+'
+ local enum = enums and enums[name]
+ if enum and #enum > 0 then
+ t[i] = ('${%d|%s|}'):format(i, table.concat(enum, ','))
+ else
+ t[i] = ('${%d:%s}'):format(i, arg)
+ end
end
return table.concat(t, ', ')
end
@@ -183,7 +189,7 @@ local function getFunctionSnip(name, value)
if not hover.args then
return ('%s()'):format(name)
end
- return ('%s(%s)'):format(name, buildSnipArgs(hover.args))
+ return ('%s(%s)'):format(name, buildSnipArgs(hover.args, hover.rawEnum))
end
local function getValueData(cata, name, value, pos, source)
diff --git a/server/src/core/hover/emmy_function.lua b/server/src/core/hover/emmy_function.lua
index e38e54a4..36fd4e90 100644
--- a/server/src/core/hover/emmy_function.lua
+++ b/server/src/core/hover/emmy_function.lua
@@ -89,6 +89,7 @@ local function buildEnum(lib)
::NEXT_ENUM::
end
local strs = {}
+ local raw = {}
for name, enums in pairs(container) do
local tp
if type(enums.type) == 'table' then
@@ -96,6 +97,7 @@ local function buildEnum(lib)
else
tp = enums.type
end
+ raw[name] = {}
strs[#strs+1] = ('\n%s: %s'):format(name, tp or 'any')
for _, enum in ipairs(enums) do
if enum.default then
@@ -108,18 +110,19 @@ local function buildEnum(lib)
else
strs[#strs+1] = ('%q'):format(enum.enum)
end
+ raw[name][#raw[name]+1] = strs[#strs]
if enum.description then
strs[#strs+1] = ' -- ' .. enum.description
end
end
end
- return table.concat(strs)
+ return table.concat(strs), raw
end
return function (name, emmy, object, select)
local argStr, argLabel, args = buildEmmyArgs(emmy, object, select)
local returns = buildEmmyReturns(emmy)
- local enum = buildEnum(emmy)
+ local enum, rawEnum = buildEnum(emmy)
local tip = emmy.description
local headLen = #('function %s('):format(name)
local title = ('function %s(%s)%s'):format(name, argStr, returns)
@@ -131,6 +134,7 @@ return function (name, emmy, object, select)
label = title,
description = tip,
enum = enum,
+ rawEnum = rawEnum,
argLabel = argLabel,
args = args,
}
diff --git a/server/src/core/hover/function.lua b/server/src/core/hover/function.lua
index eab1ff59..6f8f325c 100644
--- a/server/src/core/hover/function.lua
+++ b/server/src/core/hover/function.lua
@@ -159,8 +159,11 @@ local function buildEnum(func)
return nil
end
local strs = {}
+ local raw = {}
for _, param in ipairs(params) do
local first = true
+ local name = param:getName()
+ raw[name] = {}
param:eachEnum(function (enum)
if first then
first = false
@@ -174,12 +177,13 @@ local function buildEnum(func)
if enum.comment then
strs[#strs+1] = ' -- ' .. enum.comment
end
+ raw[name][#raw[name]+1] = enum[1]
end)
end
if #strs == 0 then
return nil
end
- return table.concat(strs)
+ return table.concat(strs), raw
end
local function getComment(func)
@@ -219,7 +223,7 @@ end
return function (name, func, object, select)
local argStr, argLabel, args = buildValueArgs(func, object, select)
local returns = buildValueReturns(func)
- local enum = buildEnum(func)
+ local enum, rawEnum = buildEnum(func)
local comment = getComment(func)
local overloads = getOverLoads(name, func, object, select)
local headLen = #('function %s('):format(name)
@@ -232,6 +236,7 @@ return function (name, func, object, select)
label = title,
description = comment,
enum = enum,
+ rawEnum = rawEnum,
argLabel = argLabel,
overloads = overloads,
args = args,
diff --git a/server/src/core/hover/lib_function.lua b/server/src/core/hover/lib_function.lua
index 75e70064..57ba1417 100644
--- a/server/src/core/hover/lib_function.lua
+++ b/server/src/core/hover/lib_function.lua
@@ -149,6 +149,7 @@ local function buildEnum(lib)
::NEXT_ENUM::
end
local strs = {}
+ local raw = {}
for name, enums in pairs(container) do
local tp
if type(enums.type) == 'table' then
@@ -157,6 +158,7 @@ local function buildEnum(lib)
tp = enums.type
end
strs[#strs+1] = ('\n%s: %s'):format(name, tp or 'any')
+ raw[name] = {}
for _, enum in ipairs(enums) do
if enum.default then
strs[#strs+1] = '\n -> '
@@ -168,12 +170,13 @@ local function buildEnum(lib)
else
strs[#strs+1] = tostring(enum.enum)
end
+ raw[name][#raw[name]+1] = strs[#strs]
if enum.description then
strs[#strs+1] = ' -- ' .. enum.description
end
end
end
- return table.concat(strs)
+ return table.concat(strs), raw
end
local function buildDoc(lib)
@@ -198,7 +201,7 @@ end
return function (name, lib, object, select)
local argStr, argLabel, args = buildLibArgs(lib, object, select)
local returns = buildLibReturns(lib)
- local enum = buildEnum(lib)
+ local enum, rawEnum = buildEnum(lib)
local tip = lib.description
local doc = buildDoc(lib)
local headLen = #('function %s('):format(name)
@@ -211,6 +214,7 @@ return function (name, lib, object, select)
label = title,
description = tip,
enum = enum,
+ rawEnum = rawEnum,
argLabel = argLabel,
doc = doc,
args = args,
diff --git a/server/test/crossfile/hover.lua b/server/test/crossfile/hover.lua
index 971b37c2..1d4328e1 100644
--- a/server/test/crossfile/hover.lua
+++ b/server/test/crossfile/hover.lua
@@ -285,6 +285,7 @@ TEST {
label = 'function f(x: string)',
name = 'f',
args = EXISTS,
+ rawEnum = EXISTS,
enum = [[
x: string
@@ -312,6 +313,7 @@ TEST {
label = 'function f(x: option)',
name = 'f',
args = EXISTS,
+ rawEnum = EXISTS,
enum = [[
x: option