Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased
<!-- Add all new changes here. They will be moved under a version at release -->
* `FIX` `need-check-nil` diagnostic is no longer reported on safe navigation access (e.g. `x?.field`, `f?.()`, `t?.[key]`), since the optional access itself already handles the nil check. Note that a non-safe access chained after a safe one (e.g. `x.upper()?.field`) still reports, because the safe access only protects its own result.
* `FIX` Go to definition on a table field assigned an anonymous function (e.g. `A.c = function() end`) now returns a single definition at the field name, instead of two candidates (the field name and the function value) [#2451](https://github.com/LuaLS/lua-language-server/issues/2451)

## 3.19.1
`2026-08-14`
Expand Down
19 changes: 19 additions & 0 deletions script/core/definition.lua
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,25 @@ return function (uri, offset)
return nil
end

-- Drop a redundant function-value target when the owning assignment's name node is also a target.
-- Collapses `A.c = function() end` to a single definition at the name `c`.
local targetMark = {}
for _, res in ipairs(results) do
targetMark[res.target] = true
end
for i = #results, 1, -1 do
local target = results[i].target
if target.type == 'function' then
local parent = target.parent
if parent and guide.isAssign(parent) then
local owner = parent.field or parent.method or parent.index or parent.variable or parent
if targetMark[owner] then
table.remove(results, i)
end
end
end
end

sortResults(results)
jumpSource(results)

Expand Down
12 changes: 12 additions & 0 deletions test/definition/field.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,15 @@ local t = X

print(t.x.<?y?>)
]]

TEST [[
A = {}
A.<!c!> = function() end
A.<?c?>()
]]

TEST [[
local A = {}
A.<!c!> = function() end
A.<?c?>()
]]
2 changes: 1 addition & 1 deletion test/definition/function.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ end
]]

TEST [[
local <!f!> = <!function () end!>
local <!f!> = function () end
<?f?>()
]]
Loading