LuaLS / LuaLS/lua-language-server

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

Ouverte
#3,243 1 commentaire 1 réaction 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Langage dominant
Lua
Étoiles
4.4k
Forks
442
Métriques de merge des PR
Aucune PR mergée en 30 j

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:

```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.

Image

### 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)

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Reproduisez les résultats en double avec l’exemple utilisant les deux fichiers lib.lua et other.lua, puis comparez-le avec la forme function lib.func(). Commencez par suivre la gestion de go-to-definition du serveur de langage pour la syntaxe d’affectation de table et utilisez le fichier journal fourni comme contexte. Le travail est considéré comme terminé lorsque la forme d’affectation renvoie un seul résultat de définition au niveau de la déclaration de la fonction.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
lua
Domaine
devtools
Type d'issue
Bug
Difficulté
3/5
Temps estimé
1-2 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
45/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.