LuaLS / LuaLS/lua-language-server

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

Open
#3,243 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Lua
Stars
4.4k
Forks
442
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the duplicate results with the two-file lib.lua and other.lua example, then compare it with the function lib.func() form. Start by tracing the language server's go-to-definition handling for table assignment syntax and use the supplied log file for context. Done means the assignment form returns one definition result at the function declaration.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.