Skip to content

Commit 241a2bd

Browse files
committed
fix(definition): canonicalize function definition
1 parent 759e8fb commit 241a2bd

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

script/core/definition.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,20 @@ return function (uri, offset)
157157
checkSee(source, results)
158158

159159
local defs = vm.getDefs(source)
160+
local result_set = {}
161+
for _, src in ipairs(defs) do
162+
result_set[src] = true
163+
end
160164

161165
for _, src in ipairs(defs) do
166+
-- If the node is a child of the same line, canonicalize the definition to the parent node.
167+
if result_set[src.parent] then
168+
local parent_line = math.floor(src.parent.start / 10000)
169+
local src_line = math.floor(src.start / 10000)
170+
if parent_line == src_line then
171+
goto CONTINUE
172+
end
173+
end
162174
if src.type == 'global' then
163175
goto CONTINUE
164176
end

test/definition/function.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ end
2424
]]
2525

2626
TEST [[
27-
local <!f!> = <!function () end!>
27+
local <!f!> = function () end
28+
<!f!> = function () end
29+
<!f!> = function () end
2830
<?f?>()
2931
]]

0 commit comments

Comments
 (0)