Skip to content

Commit

Permalink
改用更好的判断方式
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed Jun 11, 2024
1 parent 3101cfb commit 6b0c482
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 8 deletions.
10 changes: 2 additions & 8 deletions script/core/completion/completion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
45 changes: 45 additions & 0 deletions test/completion/common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}

0 comments on commit 6b0c482

Please sign in to comment.