summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorsumneko <sumneko@hotmail.com>2019-05-06 20:03:02 +0800
committersumneko <sumneko@hotmail.com>2019-05-06 20:03:02 +0800
commitaa17d5ab935f3963b6a24edb77860dc4f622e31c (patch)
treedb5c8686f0b39501418b033f236322eaa831f040 /server
parentce0e466279ccd237ec8b3df5e7ed9275b166e1c7 (diff)
downloadlua-language-server-aa17d5ab935f3963b6a24edb77860dc4f622e31c.zip
alias支持字面量
Diffstat (limited to 'server')
-rw-r--r--server/src/core/completion.lua4
-rw-r--r--server/src/emmy/alias.lua11
-rw-r--r--server/src/emmy/manager.lua10
-rw-r--r--server/test/completion/init.lua45
4 files changed, 68 insertions, 2 deletions
diff --git a/server/src/core/completion.lua b/server/src/core/completion.lua
index 83d740a3..7cddcaf5 100644
--- a/server/src/core/completion.lua
+++ b/server/src/core/completion.lua
@@ -512,7 +512,7 @@ end
local function searchEnumAsLib(vm, source, word, callback, pos, args, lib)
local select = #args + 1
for i, arg in ipairs(args) do
- if arg.start <= pos and arg.finish >= pos - 1 then
+ if arg.start <= pos and arg.finish >= pos then
select = i
break
end
@@ -555,7 +555,7 @@ end
local function searchEnumAsEmmyParams(vm, source, word, callback, pos, args, func)
local select = #args + 1
for i, arg in ipairs(args) do
- if arg.start <= pos and arg.finish >= pos - 1 then
+ if arg.start <= pos and arg.finish >= pos then
select = i
break
end
diff --git a/server/src/emmy/alias.lua b/server/src/emmy/alias.lua
index cec23b78..be47cb4f 100644
--- a/server/src/emmy/alias.lua
+++ b/server/src/emmy/alias.lua
@@ -21,11 +21,22 @@ function mt:bindType(type)
end
end
+function mt:addEnum(enum)
+ self._enum[#self._enum+1] = enum
+end
+
+function mt:eachEnum(callback)
+ for _, enum in ipairs(self._enum) do
+ callback(enum)
+ end
+end
+
return function (manager, source)
local self = setmetatable({
name = source[1][1],
source = source.id,
_manager = manager,
+ _enum = {},
}, mt)
return self
end
diff --git a/server/src/emmy/manager.lua b/server/src/emmy/manager.lua
index 85f25bd1..cce1e0e4 100644
--- a/server/src/emmy/manager.lua
+++ b/server/src/emmy/manager.lua
@@ -128,6 +128,9 @@ function mt:addAlias(source, typeObj)
aliasObj:bindType(typeObj)
local list = self:getClass(aliasName)
list[source.id] = aliasObj
+ for i = 3, #source do
+ aliasObj:addEnum(source[i][1])
+ end
return aliasObj
end
@@ -135,6 +138,13 @@ function mt:addParam(source, bind)
local paramObj = newParam(self, source)
if bind.type == 'emmy.type' then
paramObj:bindType(bind)
+ self:eachClass(bind:getName(), function (class)
+ if class.type == 'emmy.alias' then
+ class:eachEnum(function (enum)
+ paramObj:addEnum(enum)
+ end)
+ end
+ end)
elseif bind.type == 'emmy.generic' then
paramObj:bindGeneric(bind)
end
diff --git a/server/test/completion/init.lua b/server/test/completion/init.lua
index de924bd7..0d34a63b 100644
--- a/server/test/completion/init.lua
+++ b/server/test/completion/init.lua
@@ -1080,6 +1080,51 @@ f(1, $)
TEST [[
---@param x string | "'AAA'" | "'BBB'" | "'CCC'"
+function f(y, x)
+end
+
+f(1,$)
+]]
+{
+ {
+ label = "'AAA'",
+ kind = CompletionItemKind.EnumMember,
+ },
+ {
+ label = "'BBB'",
+ kind = CompletionItemKind.EnumMember,
+ },
+ {
+ label = "'CCC'",
+ kind = CompletionItemKind.EnumMember,
+ }
+}
+
+TEST [[
+---@param x string | "'AAA'" | "'BBB'" | "'CCC'"
+function f(x)
+end
+
+f($)
+]]
+{
+ {
+ label = "'AAA'",
+ kind = CompletionItemKind.EnumMember,
+ },
+ {
+ label = "'BBB'",
+ kind = CompletionItemKind.EnumMember,
+ },
+ {
+ label = "'CCC'",
+ kind = CompletionItemKind.EnumMember,
+ }
+}
+
+TEST [[
+---@alias Option string | "'AAA'" | "'BBB'" | "'CCC'"
+---@param x Option
function f(x)
end