Skip to content

Commit

Permalink
fix(integration): check nvim-tree.api.tree.winid before registering c…
Browse files Browse the repository at this point in the history
…allback
  • Loading branch information
j-hui committed Feb 5, 2024
1 parent bb9fd5c commit a672b34
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions lua/fidget/integration/nvim-tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ require("fidget.options").declare(M, "integration.nvim-tree", M.options, functio
end

local ok, api = pcall(function() return require("nvim-tree.api") end)
if not ok then
if not ok or not api.tree.winid then
-- NOTE: api.tree.winid doesn't exist on some older versions of nvim-tree.
-- We need it to figure out the size of the nvim-tree window, so if it does
-- not exist, there's no point in installing any nvim-tree event callbacks.
return
end

Expand All @@ -32,18 +35,11 @@ require("fidget.options").declare(M, "integration.nvim-tree", M.options, functio

local function resize()
if win.options.relative == "editor" then
-- Winid can be nil
local winid_fn = api.tree.winid

-- Check if winid_function is not nil before calling it
if winid_fn then
local winid = winid_fn()
local col = vim.api.nvim_win_get_position(winid)[2]

if col > 1 then
local width = vim.api.nvim_win_get_width(winid)
win.set_x_offset(width)
end
local winid = api.tree.winid()
local col = vim.api.nvim_win_get_position(winid)[2]
if col > 1 then
local width = vim.api.nvim_win_get_width(winid)
win.set_x_offset(width)
end
end
end
Expand Down

0 comments on commit a672b34

Please sign in to comment.