LuaLS / LuaLS/lua-language-server

Issues with event function definition

Ouverte
#2,279 1 commentaire 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

When trying to create an event rpc function I ran into several type issue.

---@enum EventAudienceEnum
EventAudienceEnum = {
	ALL = "ALL",
	ALL_BUT_SELF = "ALL_BUT_SELF",
	SELF = "SELF",
	SELECT = "SELECT",
	SERVER = "SERVER",
	OWNER = "OWNER",
}

---@class EventAudienceSelect
---@field [0] EventAudienceEnum.SELECT
---@field peer_ids string | string[]

---@class EventAudienceOwner
---@field [0] EventAudienceEnum.OWNER
---@field unit string


---@alias EventAudience
---| EventAudienceEnum.ALL  # comment
---| EventAudienceEnum.ALL_BUT_SELF  # comment
---| EventAudienceEnum.SELF  # comment
---| EventAudienceEnum.SERVER  # comment
---| EventAudienceSelect # comment
---| EventAudienceOwner  # comment

--- Send event
---@param audience EventAudience who to send the event to
---@param event string event to call
---@param ... any params to pass to the event
function Events.send_event(audience, event, ...)
end

Issue 1: Can't use specific enums as types (https://github.com/LuaLS/lua-language-server/issues/2274)
Issue 2: You do not get the missing field diagnostic on 'dictionary', or 'table-literal' types
Ex:

---@param audience { [0]: "SELECT", ["peer_ids"]: string | string[] } who to send event to
---@param event string event to call
---@param ... any params to pass to the event
function Events.send_event(audience, event, ...)
end

Events.send_event({
}, "test", "test")

and

---@param audience { [0]: "SELECT", peer_ids: string | string[] } who to send event to
---@param event string event to call
---@param ... any params to pass to the event
function Events.send_event(audience, event, ...)
end

Events.send_event({
}, "test", "test")

gives no errors

Issue 3: Alias comments only show stuff for strings or numbers

Screenshot_4

I would have expected the alias comment here to also say

 | EventAudienceSelect 
 | EventAudienceOwner

Issue 4: There is no missing-param diagnostic for 'number' fields:

Events.send_event({peer_ids = {}}, "test", "test")

I would have expected an error here:

Screenshot_5

but none is given

Issue 5: There is no type-checking on 'number' fields of classes, unless you explicitly call out the number. For example there is no error here:

Screenshot_6

even though there is an error here:

Screenshot_7

Issue 6: There are issues with the missing field diagnostic and unions. For example I get an error that I need to define peer_ids here:
Screenshot_8

when I would expect it to work as EventAudienceOwener has no peer_ids. I expect this is related to https://github.com/LuaLS/lua-language-server/issues/2252 (and https://github.com/LuaLS/lua-language-server/issues/2102)

Until unions are properly implemented, it would nice to be able to disable the missing-field-diagnostic at the table level instead of at the usage level. (Something like suggested here: https://github.com/LuaLS/lua-language-server/issues/2220)

Sorry this was a little long, let me know if you want me to seperate this out into seperate issues 👍

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

Commencez par reproduire les six exemples de vérification de types et de diagnostic de l’issue #2279, puis comparez le comportement avec celui des issues associées #2274, #2252, #2102 et #2220. La tâche serait considérée comme terminée lorsqu’un périmètre clarifié et un comportement vérifié seraient établis pour les cas sélectionnés de enum, missing-field, alias-comment, numeric-field et union.

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é
5/5
Temps estimé
Plus d'une semaine
Activité
À l'abandon
Clarté
À clarifier
Accessibilité débutants
25/100

Recevez les nouvelles issues par e-mail

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