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

Setting a float value in a table in a table using vim.api.nvim_win_set_var results in the inner table have values as a table with true and false as the indexes #28738

Closed
EpicBirb opened this issue May 13, 2024 · 3 comments
Labels
closed:wontfix current behavior is by design, and change is not desired

Comments

@EpicBirb
Copy link

EpicBirb commented May 13, 2024

Problem

image
Here we have a table that has the following values

{
 origin = {
  x = 50.5,
  y = 6.20
 }
}

This is assigned to the current window using vim.api.nvim_win_set_var. However, after fetching the value again with the respective command:
image

Results in this:
image

Steps to reproduce

  1. Open up neovim using nvim --clean
  2. On the command line, run :lua vim.api.nvim_win_set_var(vim.fn.win_getid(), "test", {origin={x = 50.5, y = 60.023}})
  3. Then run :lua vim.print(vim.api.nvim_win_get_var(vim.fn.win_getid(), "test"))

Expected behavior

I expect that the value I have assigned to the window be returned in the same way I had assigned it

Neovim version (nvim -v)

NVIM v0.9.5

Vim (not Nvim) behaves the same?

not tested

Operating system/version

Windows 10 22H2

Terminal name/version

Windows Terminal 1.19.11213.0

$TERM environment variable

none (ran using echo $Env:TERM)

Installation

repo using the zip file

@EpicBirb EpicBirb added the bug issues reporting wrong behavior label May 13, 2024
@github-actions github-actions bot added the api libnvim, Nvim RPC API label May 13, 2024
@zeertzjq
Copy link
Member

zeertzjq commented May 13, 2024

This behavior is necessary to distinguish a Float from a Number. In Lua these are the same type, while in RPC API and Vimscript they are different. See :h lua-special-tbl

                                                              *lua-special-tbl*
4. Table with `vim.type_idx` key may be a dictionary, a list or floating-point
   value:
   - `{[vim.type_idx]=vim.types.float, [vim.val_idx]=1}` is converted to
     a floating-point 1.0. Note that by default integral Lua numbers are
     converted to |Number|s, non-integral are converted to |Float|s. This
     variant allows integral |Float|s.
   - `{[vim.type_idx]=vim.types.dictionary}` is converted to an empty
     dictionary, `{[vim.type_idx]=vim.types.dictionary, [42]=1, a=2}` is
     converted to a dictionary `{'a': 42}`: non-string keys are ignored.
     Without `vim.type_idx` key tables with keys not fitting in 1., 2. or 3.
     are errors.
   - `{[vim.type_idx]=vim.types.array}` is converted to an empty list. As well
     as `{[vim.type_idx]=vim.types.array, [42]=1}`: integral keys that do not
     form a 1-step sequence from 1 to N are ignored, as well as all
     non-integral keys.

@zeertzjq zeertzjq closed this as not planned Won't fix, can't repro, duplicate, stale May 13, 2024
@zeertzjq zeertzjq added closed:wontfix current behavior is by design, and change is not desired and removed bug issues reporting wrong behavior api libnvim, Nvim RPC API labels May 13, 2024
@wookayin
Copy link
Member

wookayin commented May 13, 2024

Question: I recall #24430 had the similar issue before. If nvim 0.10 has changed (fixed) the behavior on nvim_win_{get,set}_config (see #27284), nvim_win_{get,set}_var should deserve the same fix, or shoudn't it? If not, what's special about nvim_win_{get,set}_config?

@zeertzjq
Copy link
Member

row and col in nvim_win_get_config can only be Float. Vimscript variables can be either Integer or Float.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed:wontfix current behavior is by design, and change is not desired
Projects
None yet
Development

No branches or pull requests

3 participants