LuaLS / LuaLS/lua-language-server

Annotations in inline comments do not recognize others on the same line

Ouverte
#3,350 0 commentaires 0 réactions 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?

Visual Studio Code Extension (sumneko.lua)

### Which OS are you using?

Linux

### What is the issue affecting?

Annotations, Type Checking

### Expected Behaviour

Placing multiple annotations in inline comments like so works fine: the generics are interpreted correctly.
```lua
--[[@generic C]]
--[[@param any C]]
--[[@return C]]
local function exampleGeneric(any) return any end
```
So one would expect grouping them together on the same line (like this) would also work:
```lua
--[[@generic C]] --[[@param any C]] --[[@return C]]
local function exampleGeneric(any) return any end
```

### Actual Behaviour

In the previous example, the generic seems to be defined, but doesn't carry over properly to the other two annotations. Similarly, adding a line break between the first and second annotation like this
```lua
--[[@generic C]]
--[[@param any C]] --[[@return C]]
local function exampleGeneric(any) return any end
```
allows the generic to be recognized by the second annotation, but not the third. This behavior is also visible in other annotations that require others to be nearby, such as with classes and fields, and aliases.

### Reproduction steps

1. Open VSCode
2. Paste either of the following examples into an empty lua file:
```lua
--[[@class amazingClass]] --[[@field field1 string]] --[[@field field2 number]]
```
```lua
--[[@generic C]] --[[@param any C]] --[[@return C]]
local function exampleGeneric(any) return any end
```

### Additional Notes

While I realize there is little practical use for some of these cases, such as the class definition (as it starts to take up a lot of horizontal space really quickly when defining new fields), this is especially useful when creating a plugin that allows for inline annotation definitions like the following:
```lua
local width: integer, height: integer = screen.width, screen.height
local logo: love.Image = textures["logo.png"]
```
which generates inline comments like so in order to preserve syntax coloring, as well as line numbers during runtime:
```lua
local width --[[@type integer ]], height --[[@type integer ]] = screen.width, screen.height
local logo --[[@type love.Image ]] = textures["logo.png"]
```

### Log File

_No response_

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 le problème dans VSCode en utilisant les exemples d’annotations Lua inline du rapport, puis comparez les annotations réparties sur plusieurs lignes avec plusieurs annotations sur une seule ligne. Suivez la manière dont le language server associe les annotations liées, telles que les génériques, les paramètres, les valeurs de retour, les classes, les champs et les alias ; le travail est terminé lorsque les annotations placées sur une même ligne sont interprétées de manière cohérente avec celles placées sur des lignes séparées.

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é
4/5
Temps estimé
3-5 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.