Skip to content

error opening file when window.width is not lua number and neo-tree is only opened window #789

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

Closed
williamhCode opened this issue Mar 8, 2023 · 2 comments · Fixed by #790

Comments

@williamhCode
Copy link
Contributor

When I set window.width to a string or a function, neo-tree throws an error when trying to open a file when neo-tree is the only window open.

It works fine when I have neo-tree open and another window open, only when neo-tree is the only buffer open, it breaks.

Example setup:

require("neo-tree").setup({
  window = {
    width = "30%"
  }
})

Error code:

E5108: Error executing lua: ...cal/share/nvim/lazy/neo-tree.nvim/lua/neo-tree/utils.lua:508: Expected lua number
stack traceback:
        [C]: in function 'nvim_win_set_width'
        ...cal/share/nvim/lazy/neo-tree.nvim/lua/neo-tree/utils.lua:508: in function 'open_file'
        ...y/neo-tree.nvim/lua/neo-tree/sources/common/commands.lua:561: in function 'open'
        ...y/neo-tree.nvim/lua/neo-tree/sources/common/commands.lua:592: in function 'open_with_cmd'
        ...y/neo-tree.nvim/lua/neo-tree/sources/common/commands.lua:601: in function 'open'
        ...o-tree.nvim/lua/neo-tree/sources/filesystem/commands.lua:184: in function 'func'
        ...are/nvim/lazy/neo-tree.nvim/lua/neo-tree/ui/renderer.lua:782: in function <...are/nvim/lazy/neo-tree.nvim/lua/neo-tree/ui/renderer.lua:780>

From my understanding of the code, I'm guessing it works normally because neo-tree uses nui to open the split, and nui accepts percentages and functions. However, when opening a file when neo-tree is the only window, vim.api.nvim_win_set_width is called and window.width is passed without any extra processing.

Perhaps the code similar to calc_container_width could be used, as container width support strings and functions already.

@williamhCode
Copy link
Contributor Author

williamhCode commented Mar 8, 2023

I made a quick fix here, lmk if I should make a PR.

@cseickel
Copy link
Contributor

cseickel commented Mar 8, 2023

I made a quick fix here, lmk if I should make a PR.

Yes please!

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

Successfully merging a pull request may close this issue.

2 participants