Skip to content

Hover returns nothing for a field accessed through a union type (T?, T|nil, A|B) on main #1321

Open

Description

@mareklangiewicz

Repro

---@class P
---@field x boolean doc of P.x

---@class Q
---@field y boolean doc of Q.y

---@type P
local plain = {}
---@type P?
local opt = {}
---@type P|nil
local pnil = {}
---@type P|Q
local pq = {}
---@alias PQ P|Q
---@type PQ
local alias = {}
print(plain.x, opt.x, pnil.x, pq.x, pq.y, alias.x)

Hover each field access on the last line:

access lua-language-server emmylua 0.25.1 emmylua main (56267ea)
plain.x ✅ type + doc of P.x ✅ ✅
opt.x (P?) ✅ ✅ ❌ no hover at all
pnil.x (P|nil) ✅ ✅ ❌ no hover at all
pq.x (P|Q) ✅ ✅ ❌ no hover at all
pq.y (P|Q) ✅ ✅ ❌ no hover at all
alias.x (---@alias PQ P|Q) ✅ ✅ ✅

On main, the hover request returns an empty result for these accesses: no type line and no description.
The same union written through an ---@alias works.

Impact

Optional types are everywhere. The same happens with an optional parameter: inside
---@param opts? P / local function f(opts), hovering opts.x shows nothing on main, while 0.25.1
shows doc of P.x.

Written with help from Claude Code.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions