Skip to content

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

@williamhCode

Description

@williamhCode

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions