-
Notifications
You must be signed in to change notification settings - Fork 185
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
callbacks for signal_start and signal_start_oneshot should receive a number #711
Comments
Numbers were used when signals were added to an old luvit version. After luv was split into its own project, signals were reintroduced using uppercase strings. This implementation was eventually changed to using lowercase strings and moved to a dedicated constants file where it remains, along with other constants that are handled as lowercase strings. This was all 10+ years ago and before I joined, so I can't speak for those who made the change, but luv generally uses strings instead of numbers where possible. I assume that this is for consistency with Lua's recommendation to use strings for options.
In any case, the return type is documented as a string, so we could not easily change this if we wanted. I think that we can do better to document string constants that are accepted and expected, though. I do agree that the existence of numbers in the |
A simple backwards compatible solution would be to pass a second parameter to the callback that contains the integer representation. |
OK, this makes sense in a way. The change to lowercase is still strange considering what There seem to be three representations in the current API:
It seems like relaxing them all to accept either an integer or a string could be done in a backwards-compatible way. My opinion is that this is preferable to defining a second constants table + converters, but it doesn't exclude doing that as well. I suggest that the parameter be called |
I'm not sure I understand what you're proposing. There's no way to infer what type the callback is expecting, and EDIT: Maybe you mean something like "if the signal is passed to the function as an integer, then the callback should be called with an integer"? But that would still be a breaking change, and it can't apply to To give you an idea of the change I had in mind, for the callbacks, the backwards compatible approach would be something like: For
For
It's a bit unfortunate that these parameters would have to be in a different order between |
I confused myself a bit but yes, something like that is what I had in mind, and the same for strings. But if it doesn't work for |
Changing to We probably should document that the value can technically be We can document the list of supported strings similarly to how we document FS modes. Since signals appear in multiple places, we can add a new section dedicated to constants to avoid duplication, and we can point the FS modes and other constants to there. |
Adding the new parameters is also fine, if that helps things. The order difference is indeed unfortunate, though. |
With #713, we now have documented the behavior encountered in this issue. As you can see by this change, there are places other than signals where the library optionally accepts lowercase strings or integer constants, but only returns lowercase strings. You may also find other places that only accept lowercase strings, or integer constants, but not both. When I get a chance, I'll make a list of all of these encounters, then we can think about how we can maximize UX without complicating library behavior. After documenting things, my belief at this point is that accepting multiple input types is already complicated enough, and providing multiple output types would be impractical in certain cases, but I'm open minded. |
Thanks, the list should help quite a lot and I think the simple examples are nice too. I'll do my best to keep an eye on the constants -> strings mapping in that file in case I notice any changes that update the constants table but miss the docs. These changes should propagate to
I'm sympathetic to this concern, I wasn't aware of the lua string recommendation when creating the issue and that has softened my opinion. I'm happy for this to be closed in favour of more targeted future UX proposals. |
Unless there is a strong reason for the current behavior, I propose that the callback which is given as the third argument to
signal_start
andsignal_start_oneshot
should receive/propagate the signal as a number. Currently, the signal is propagated as a lowercase string. This is confusing for several reasons:int
, see heresignum
, implying a numeric representationuv.constants.SIGINT
, and other signals, is an integerThis example demonstrates the confusion for a NeoVim user. Sure, the outputs of
vim.system
have no obligation to be consistent with luv, and vice versa, but it would make things simpler for us. Requires NeoVim 0.10 for thevim.uv
namespace. Note also thatvim.system
doesn't allow SIGINT hooks (only atimeout
one) so this use case is more than hypothetical.The text was updated successfully, but these errors were encountered: