nvim-tree / nvim-tree/nvim-tree.lua

Floating nvim-tree does not respect config on startup

Open
#2,749 17 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

awaiting feedback bug
Dominant language
Lua
Stars
8.6k
Forks
639
Avg merge
1d 14h
Merged PRs (30d)
2

Description

Description

When opening a folder with "nvim ." and while having nvim-tree configured to float in a window, nvim-tree opens full screen, not respecting open_win_config. Furthermore, trying to close the initial fullscreen nvim-tree with NvimTreeToggle produces an error:

Error executing Lua callback: ...cal/share/nvim/lazy/nvim-tree.lua/lua/nvim-tree/view.lua:225: Expected Lua number stack traceback: [C]: in function 'nvim_win_is_valid' ...cal/share/nvim/lazy/nvim-tree.lua/lua/nvim-tree/view.lua:225: in function 'close' ...cal/share/nvim/lazy/nvim-tree.lua/lua/nvim-tree/view.lua:235: in function 'close_this_tab_only' ...cal/share/nvim/lazy/nvim-tree.lua/lua/nvim-tree/view.lua:248: in function 'close' ...lazy/nvim-tree.lua/lua/nvim-tree/actions/tree/toggle.lua:45: in function 'toggle' ...share/nvim/lazy/nvim-tree.lua/lua/nvim-tree/commands.lua:36: in function <...share/nvim/lazy/nvim-tree.lua/lua/nvim-tree/commands.lua:35>

Neovim version
NVIM v0.9.5
Build type: Release
LuaJIT 2.1.1692716794
Operating system and version

Windows 11

Windows variant

WSL2 Ubuntu

nvim-tree version

#ddd1d6e, v1.3.0

Clean room replication
Install nvim-tree with Lazy, using the following configuration:

return {
	"nvim-tree/nvim-tree.lua",
	version = "*",
	lazy = false,
	dependencies = {
		"nvim-tree/nvim-web-devicons",
	},
	config = function()
		require("nvim-tree").setup({
			disable_netrw = true,
			hijack_netrw = false,
			view = {
				relativenumber = true,
				float = {
					enable = true,
					open_win_config = function()
						local screen_w = vim.opt.columns:get()
						local screen_h = vim.opt.lines:get() - vim.opt.cmdheight:get()
						local window_w = screen_w * 0.5
						local window_h = screen_h * 0.8
						local window_w_int = math.floor(window_w)
						local window_h_int = math.floor(window_h)
						local center_x = (screen_w - window_w) / 2
						local center_y = ((vim.opt.lines:get() - window_h) / 2) - vim.opt.cmdheight:get()
						return {
							title = " NvimTree ",
							title_pos = "center",
							border = "rounded",
							relative = "editor",
							row = center_y,
							col = center_x,
							width = window_w_int,
							height = window_h_int,
						}
					end,
				},
			},
		})
	end,
}
Steps to reproduce
  1. nvim .
  2. :NvimTreeToggle
Expected behavior

NvimTree should open in a floating window and close on NvimTreeToggle

Actual behavior

NvimTree opens full screen and :NvimTreeToggle produces error

Screenshot 2024-04-17 103007

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the startup flow with the configuration and steps in the issue. Read lua/nvim-tree/view.lua around close and the startup window creation path, then inspect lua/nvim-tree/actions/tree/toggle.lua and lua/nvim-tree/commands.lua. Done means nvim-tree opens in the configured floating window and NvimTreeToggle closes it without an error.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.