LuaLS / LuaLS/lua-language-server
Duplicate "go to definition" results when using table assignment syntax in a module
まだ誰も着手していません。
- 主要言語
- 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 にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
2つのファイル lib.lua と other.lua を使った例で重複する結果を再現し、その後 function lib.func() 形式と比較します。まず、テーブル代入構文に対する language server の go-to-definition 処理を追跡し、提供されたログファイルをコンテキストとして使用してください。代入形式が関数宣言に対して1つの定義結果を返せば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- lua
- 領域
- devtools
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 45/100