Skip to content

Issues with event function definition #2279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
GiuseppeIII opened this issue Aug 20, 2023 · 1 comment
Open

Issues with event function definition #2279

GiuseppeIII opened this issue Aug 20, 2023 · 1 comment

Comments

@GiuseppeIII
Copy link

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 (#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 #2252 (and #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: #2220)

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

@sumneko
Copy link
Collaborator

sumneko commented Aug 21, 2023

Please split into multiple issues, as some of these problems may be difficult to fix in the short term, while others can be fixed quickly. I would like to track them separately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants