LuaLS / LuaLS/lua-language-server
Two definitions for local function variables
還沒有人認領這個 Issue。
- 主要語言
- Lua
- 星號
- 4.4k
- 分支
- 442
- PR 合併指標
- 30 天內沒有已合併 PR
描述
### How are you using the lua-language-server?
NeoVim
### Which OS are you using?
Linux
### What is the issue affecting?
Other
### Expected Behaviour
Using vim.lsp.buf.definition() to go to the definition of a local function variable (assigned with the `=` operator), should give only a single definition at the local variable name.
### Actual Behaviour
Using vim.lsp.buf.definition() to go to the definition of a local function variable (assigned with the `=` operator), gives two definitions on the same line. One is located at the variable name and the other is located at the beginning of the function key word.
### Reproduction steps
1. Create a lua file with the following content:
```lua
local m = function() print "hello world" end
m()
```
2. Move the cursor on the `m()` function call
3. Execute the neovim command `:lua vim.lsp.buf.definition()`
### Additional Notes
_No response_
### Log File
```
[DEBUG][2023-12-16 17:31:59] .../lua/vim/lsp.lua:1391 "LSP[lua_ls]" "client.request" 1 "textDocument/definition" { position = { character = 0, line = 2 }, textDocument = { uri = "file:///home/tobias/.config/nvim/test.lua" }} 147
[DEBUG][2023-12-16 17:31:59] .../vim/lsp/rpc.lua:284 "rpc.send" { id = 1559, jsonrpc = "2.0", method = "textDocument/definition", params = { position = { character = 0, line = 2 }, textDocument = { uri = "file:///home/tobias/.config/nvim/test.lua" } }}
[DEBUG][2023-12-16 17:31:59] .../vim/lsp/rpc.lua:387 "rpc.receive" { id = 1559, jsonrpc = "2.0", result = { { originSelectionRange = { ["end"] = { character = 1, line = 2 }, start = { character = 0, line = 2 } }, targetRange = { ["end"] = { character = 7, line = 0 }, start = { character = 6, line = 0 } }, targetSelectionRange = { ["end"] = { character = 7, line = 0 }, start = { character = 6, line = 0 } }, targetUri = "file:///home/tobias/.config/nvim/test.lua" }, { originSelectionRange = { ["end"] = { character = 1, line = 2 }, start = { character = 0, line = 2 } }, targetRange = { ["end"] = { character = 44, line = 0 }, start = { character = 10, line = 0 } }, targetSelectionRange = { ["end"] = { character = 44, line = 0 }, start = { character = 10, line = 0 } }, targetUri = "file:///home/tobias/.config/nvim/test.lua" } }}
[DEBUG][2023-12-16 17:32:02] .../lua/vim/lsp.lua:1391 "LSP[lua_ls]" "client.request" 1 "textDocument/codeLens" { textDocument = { uri = "file:///home/tobias/.config/nvim/test.lua" }} 147
[DEBUG][2023-12-16 17:32:02] .../vim/lsp/rpc.lua:284 "rpc.send" { id = 1560, jsonrpc = "2.0", method = "textDocument/codeLens", params = { textDocument = { uri = "file:///home/tobias/.config/nvim/test.lua" } }}
[DEBUG][2023-12-16 17:32:02] .../vim/lsp/rpc.lua:387 "rpc.receive" { id = 1560, jsonrpc = "2.0"}
[DEBUG][2023-12-16 17:32:02] .../lua/vim/lsp.lua:1391 "LSP[lua_ls]" "client.request" 1 "textDocument/documentHighlight" { position = { character = 0, line = 2 }, textDocument = { uri = "file:///home/tobias/.config/nvim/test.lua" }} 147
[DEBUG][2023-12-16 17:32:02] .../vim/lsp/rpc.lua:284 "rpc.send" { id = 1561, jsonrpc = "2.0", method = "textDocument/documentHighlight", params = { position = { character = 0, line = 2 }, textDocument = { uri = "file:///home/tobias/.config/nvim/test.lua" } }}
[DEBUG][2023-12-16 17:32:02] .../vim/lsp/rpc.lua:387 "rpc.receive" { id = 1561, jsonrpc = "2.0", result = { { kind = 3, range = { ["end"] = { character = 7, line = 0 }, start = { character = 6, line = 0 } } }, { kind = 2, range = { ["end"] = { character = 1, line = 2 }, start = { character = 0, line = 2 } } } }}
[TRACE][2023-12-16 17:32:02] ...lsp/handlers.lua:618 "default_handler" "textDocument/documentHighlight" { ctx = '{\n bufnr = 147,\n client_id = 1,\n method = "textDocument/documentHighlight",\n params = {\n position = {\n character = 0,\n line = 2\n },\n textDocument = {\n uri = "file:///home/tobias/.config/nvim/test.lua"\n }\n }\n}', result = { { kind = 3, range = { ["end"] = { character = 7, line = 0 }, start = { character = 6, line = 0 } } }, { kind = 2, range = { ["end"] = { character = 1, line = 2 }, start = { character = 0, line = 2 } } } }}
```
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從 textDocument/definition 入口開始,使用 Neovim 的 vim.lsp.buf.definition() 和 issue 中的 Lua 程式碼片段重現該報告。追蹤區域函式指派為何會同時產生變數名稱和關鍵字 function 的範圍;完成標準是請求只回傳區域變數定義。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- lua, neovim
- 領域
- devtools
- Issue 類型
- 缺陷
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 活躍度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 58/100