LuaLS / LuaLS/lua-language-server
Duplicate "go to definition" results when using table assignment syntax in a module
还没有人认领这个 Issue。
- 主要语言
- Lua
- 星标
- 4.4k
- 派生
- 442
- PR 合并指标
- 30 天内没有已合并 PR
描述
### How are you using the lua-language-server?
Kakoune
### Which OS are you using?
MacOS
### What is the issue affecting?
Other
### Expected Behaviour
When a module is written by assigning functions to table members with the following syntax:
```lua
local lib={}
lib.func = function()
-- ...
end
return lib
```
Performing a "Go to definition" on this function from another file that `require`s the module should go to the function defintion.
### Actual Behaviour
Instead when doing a "Go to defintion", there are 2 results, and the user must choose one. They both point to the same line, one points to the table member's name and the other to the start of the `function` declaration.
### Reproduction steps
1. Create a project with two files, `lib.lua` and `other.lua`, and populate them as follows:
`lib.lua`:
```lua
local lib={}
lib.func = function() end
return lib
```
`other.lua`:
```lua
local lib = require('lib')
lib.func()
```
2. From `other.lua`, perform a "Go to definition" on `func`. Note that it has two results that must be chosen, one will take you to the table member's name, and the other will take you to the start of the function declaration.
3. Change `lib.lua` to:
```lua
local lib={}
function lib.func() end
return lib
```
4. From `other.lua`, perform a "Go to definition" on `func`. It takes you directly to the start of the function declaration (which is also the table member's name).
### Additional Notes
I know that the `function lib.func()` syntax is preferred, but this is an issue for me when using libraries that use the `lib.func = function()` syntax. I wasn't able to find any discussions of this issue, but it seems likely that others have run into it, so I am wondering if there is a solution that I just haven't found.
### Log File
[file_Users_evanjohnson_sandbox_lua-lsp-test.log](https://github.com/user-attachments/files/21456083/file_Users_evanjohnson_sandbox_lua-lsp-test.log)
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
使用包含两个文件 lib.lua 和 other.lua 的示例重现重复结果,然后将其与 function lib.func() 形式进行比较。首先跟踪语言服务器对表赋值语法的 go-to-definition 处理,并使用提供的日志文件作为上下文。赋值形式在函数声明处返回一个定义结果时,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- lua
- 领域
- devtools
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100