LuaLS / LuaLS/lua-language-server

View definition of overloaded value via __index of metatable doesn't seem right

Open
#2,380 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Lua
Stars
4.4k
Forks
442
PR merge metrics
No merged PRs in 30d

Description

How are you using the lua-language-server?

Visual Studio Code Extension (sumneko.lua)

Which OS are you using?

Windows

What is the issue affecting?

Hover

Expected Behaviour
local a = {k = 'v1'}
local b = setmetatable({}, {__index = a})
b.k = 'v2'

View definition of a.k:

local a = {k = 'v1'}
Actual Behaviour

image
View definition of a.k:
image

Reproduction steps

Press F12 while selecting the k of the first line of the code below:

local a = {k = 'v1'}
local b = setmetatable({}, {__index = a})
b.k = 'v2'
Additional Notes

Chinese colloquial description:

如上所述,当我试图浏览 a.k 的定义时,同时弹出了 a.k 与 b.k 的定义。这显然是不对的:表 b 元表的__index 为 a,因此 b.k 只是继承了 a.k,其定义与 a.k 的定义并无关联,不应显示到 a.k 上。

当借助__index 实现的继承较多时,定义就失去了它应有的作用,非常凌乱。

我正在为一款游戏的 mod 开发 LLS 的 Addon 与 Plugin,因此我愿意提供我力所能及的帮助。如果已有重复的 issue,恳请谅解!

Log File

file_c%3A_LLS-issue.log
I suppose this may not be helpful. But just upload it.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the definition behavior in the VS Code extension using the three-line Lua snippet and compare F12 results for the two k references. Trace the definition-resolution path for table fields and __index handling; done means selecting a.k shows only the a.k definition rather than also showing b.k.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.