LuaLS / LuaLS/lua-language-server

Two definitions for local function variables

Đang mở
#2,451 6 bình luận 8 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Ngôn ngữ chính
Lua
Star
4.4k
Fork
442
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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:
local m = function() print "hello world" end

m()
  1. Move the cursor on the m() function call
  2. 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"  }}	<function 1>	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"  }}	<function 1>	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"  }}	<function 1>	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        }      }    } }}

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu tại điểm vào textDocument/definition và tái hiện báo cáo bằng đoạn mã Lua trong issue, sử dụng vim.lsp.buf.definition() của Neovim. Truy vết lý do phép gán hàm cục bộ tạo ra cả phạm vi của tên biến và từ khóa function; hoàn thành khi request chỉ trả về định nghĩa biến cục bộ.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
lua, neovim
Lĩnh vực
devtools
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Ít trao đổi
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
58/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.