Skip to content
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

nvim_win_get_config returns lua-special-tbl when called from Lua #27277

Closed
altermo opened this issue Jan 31, 2024 · 6 comments
Closed

nvim_win_get_config returns lua-special-tbl when called from Lua #27277

altermo opened this issue Jan 31, 2024 · 6 comments
Labels
api libnvim, Nvim RPC API bug issues reporting wrong behavior complexity:low Low-risk, self-contained. Do NOT ask "can I work on this", just read CONTRIBUTING.md lua stdlib
Milestone

Comments

@altermo
Copy link
Contributor

altermo commented Jan 31, 2024

Problem

Some functions, like nvim_win_get_config, have a lua-special-tbl float in the returned values, but what the user sees when inspecting it is a table with the keys true and false set to some numbers, which is confusing.

Expected behavior

A solution is to add a notice to the documentation of the functions that may have lua-special-tbl in the return value about how the return value may contain lua-special-tbl.

An alternative solution would be to make it so that inspecting a lua-special-tbl would not return the table with boolean keys, but either a string similar to vim.empty_dict(), or the table with the keys being vim.type_idx and vim.val_idx instead of true and false

@altermo altermo added the enhancement feature request label Jan 31, 2024
@altermo altermo changed the title Denote for the user that the value is a lua-special-tbl. Informe the user that the value is a lua-special-tbl. Jan 31, 2024
@justinmk
Copy link
Member

justinmk commented Jan 31, 2024

add a notice to the documentation of the functions that may have lua-special-tbl in the return value about how the return value may contain lua-special-tbl

That is all functions that can return a dict.

make it so that inspecting a lua-special-tbl would not return the table with boolean keys, but either a string similar to vim.empty_dict(), or the table with the keys being vim.type_idx and vim.val_idx instead of true and false

Do you mean vim.inspect()?

@altermo
Copy link
Contributor Author

altermo commented Jan 31, 2024

For the documentation, what I thought of was for those functions that would, if not for vim-script compatibility reasons, return a normal number/table, but because of vim-script compatibility, return a lua-special-tbl (or returns a table that contains a lua-special-tbl).

For the inspection, mostly yes: I would also want to include tostring, but I don't know how feasible it is to set metatable.__tostring for lua-special-tbl.

@bfredl
Copy link
Member

bfredl commented Jan 31, 2024

Some functions, like nvim_win_get_config, have a lua-special-tbl float in the returned values, but what the user sees when inspecting it is a table with the keys true and false set to some numbers, which is confusing.

Hmm in this particular case it is a bug. There is no "compat" going on here but vim.api.nvim_win_get_config() is a native API call. And as the type of row/col is an hard-coded Float, not a free Object, it should always be represented by a lua number (i e row=2 and row=2.0 is the same value already in the API layer)

Special dicts for numbers are only for cases where 2 as an int and 2.0 as a float are different as values, i e when representing foreign type systems.

@altermo
Copy link
Contributor Author

altermo commented Jan 31, 2024

The behavior of vim.api.nvim_win_get_config() returning lua-special-tbl being a bug was already brought up, and marked as intended behavior (#24430 (comment))

@bfredl
Copy link
Member

bfredl commented Jan 31, 2024

That reasoning is incorrect tho, for the reasons I already mentioned. The type of a float position was intentionally chosen to be a number, not a foreign object of an unknown type. Neither is a "special case" of the other, it is just two different code paths which has always existed (and we fixed bugs like this multiple times in the past)

@justinmk justinmk added bug issues reporting wrong behavior api libnvim, Nvim RPC API labels Feb 8, 2024
@justinmk justinmk changed the title Informe the user that the value is a lua-special-tbl. nvim_win_get_config returns lua-special-tbl when called from Lua Feb 8, 2024
@justinmk justinmk added the complexity:low Low-risk, self-contained. Do NOT ask "can I work on this", just read CONTRIBUTING.md label Feb 8, 2024
@justinmk justinmk modified the milestones: backlog, 0.11, 0.10 Feb 8, 2024
@zeertzjq
Copy link
Member

zeertzjq commented Feb 9, 2024

Fixed by #27284

@zeertzjq zeertzjq closed this as completed Feb 9, 2024
@zeertzjq zeertzjq modified the milestones: 0.11, 0.10 Feb 9, 2024
@zeertzjq zeertzjq removed enhancement feature request documentation labels Feb 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api libnvim, Nvim RPC API bug issues reporting wrong behavior complexity:low Low-risk, self-contained. Do NOT ask "can I work on this", just read CONTRIBUTING.md lua stdlib
Projects
None yet
Development

No branches or pull requests

4 participants