LuaLS / LuaLS/lua-language-server

Duplicate "go to definition" results when using table assignment syntax in a module

Đang mở
#3,243 1 bình luận 1 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?

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:

local lib={}

lib.func = function()
  -- ...
end

return lib

Performing a "Go to definition" on this function from another file that requires 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.

Image
Reproduction steps
  1. Create a project with two files, lib.lua and other.lua, and populate them as follows:

lib.lua:

local lib={}

lib.func = function() end

return lib

other.lua:

local lib = require('lib')

lib.func()
  1. 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.

  2. Change lib.lua to:

local lib={}

function lib.func() end

return lib
  1. 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

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

Tái hiện các kết quả trùng lặp bằng ví dụ gồm hai tệp lib.lua và other.lua, sau đó so sánh với dạng function lib.func(). Trước tiên, hãy lần theo cách language server xử lý go-to-definition đối với cú pháp gán bảng và sử dụng tệp log được cung cấp để làm ngữ cảnh. Được coi là hoàn tất khi dạng gán trả về đúng một kết quả định nghĩa tại phần khai báo hàm.

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
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
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
45/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.