summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2024-06-11 21:05:43 +0800
committer最萌小汐 <sumneko@hotmail.com>2024-06-11 21:05:43 +0800
commit6b0c48293cfbaebb375975897b59f67e1fa1df31 (patch)
treec2a8dab5324b8212e21b1ad763fba932e3ff3078
parent3101cfb948694389cf1cc9cdbba99267f6290508 (diff)
downloadlua-language-server-6b0c48293cfbaebb375975897b59f67e1fa1df31.zip
改用更好的判断方式
-rw-r--r--script/core/completion/completion.lua10
-rw-r--r--test/completion/common.lua45
2 files changed, 47 insertions, 8 deletions
diff --git a/script/core/completion/completion.lua b/script/core/completion/completion.lua
index cff9c385..3a76472a 100644
--- a/script/core/completion/completion.lua
+++ b/script/core/completion/completion.lua
@@ -1588,18 +1588,12 @@ end
local function findCall(state, position)
local call
guide.eachSourceContain(state.ast, position, function (src)
- if src.type == 'call' then
- if not call or call.start < src.start then
+ if src.type == 'call' and src.node.finish <= position then
+ if not call or call.start < src.start then
call = src
end
end
end)
- if not call then
- return nil
- end
- if call.node.finish > position then
- return nil
- end
return call
end
diff --git a/test/completion/common.lua b/test/completion/common.lua
index fc2183d7..ec2372a0 100644
--- a/test/completion/common.lua
+++ b/test/completion/common.lua
@@ -4489,3 +4489,48 @@ local m
m:self(<??>):optional()
]]
(nil)
+
+TEST [[
+---@enum(key) enum
+local t = {
+ a = 1,
+ b = 2,
+ c = 3,
+}
+
+---@class A
+local M
+
+---@return A
+function M.create()
+ return M
+end
+
+---@param optional enum
+---@return self
+function M:optional(optional)
+ return self
+end
+
+---@return A
+function M:self()
+ return self
+end
+
+
+M.create():optional(<??>):self()
+]]
+{
+ {
+ label = '"a"',
+ kind = define.CompletionItemKind.EnumMember,
+ },
+ {
+ label = '"b"',
+ kind = define.CompletionItemKind.EnumMember,
+ },
+ {
+ label = '"c"',
+ kind = define.CompletionItemKind.EnumMember,
+ },
+}