From 1e6f9a2e52b67f8760045bafe8236a429d9599c1 Mon Sep 17 00:00:00 2001 From: zbirenbaum Date: Mon, 3 Jan 2022 15:50:00 -0500 Subject: [PATCH] fix errors thrown by neovim no longer allowing implicit conversions of nil to 0 in api function calls. See neovim/neovim#16745 for details on why this is now an error --- lua/core/utils.lua | 3 ++- lua/plugins/configs/statusline.lua | 18 +++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/lua/core/utils.lua b/lua/core/utils.lua index e795021..15c4c66 100644 --- a/lua/core/utils.lua +++ b/lua/core/utils.lua @@ -22,6 +22,7 @@ M.close_buffer = function(force) local function switch_buffer(windows, buf) local cur_win = vim.fn.winnr() for _, winid in ipairs(windows) do + winid = tonumber(winid) or 0 vim.cmd(string.format("%d wincmd w", vim.fn.win_id2win(winid))) vim.cmd(string.format("buffer %d", buf)) end @@ -121,7 +122,7 @@ M.hide_statusline = function() local hidden = require("core.utils").load_config().plugins.options.statusline.hidden local shown = require("core.utils").load_config().plugins.options.statusline.shown local api = vim.api - local buftype = api.nvim_buf_get_option("%", "ft") + local buftype = api.nvim_buf_get_option(0, "ft") -- shown table from config has the highest priority if vim.tbl_contains(shown, buftype) then diff --git a/lua/plugins/configs/statusline.lua b/lua/plugins/configs/statusline.lua index c8ae753..7a8aaa2 100644 --- a/lua/plugins/configs/statusline.lua +++ b/lua/plugins/configs/statusline.lua @@ -88,7 +88,7 @@ components.active[1][2] = { return " " .. icon .. " " .. filename .. " " end, enabled = shortline or function(winid) - return vim.api.nvim_win_get_width(winid) > 70 + return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 70 end, hl = { fg = colors.white, @@ -105,7 +105,7 @@ components.active[1][3] = { end, enabled = shortline or function(winid) - return vim.api.nvim_win_get_width(winid) > 80 + return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 80 end, hl = { @@ -218,7 +218,7 @@ components.active[2][1] = { return "" end, enabled = shortline or function(winid) - return vim.api.nvim_win_get_width(winid) > 80 + return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 80 end, hl = { fg = colors.green }, } @@ -232,7 +232,7 @@ components.active[3][1] = { end end, enabled = shortline or function(winid) - return vim.api.nvim_win_get_width(winid) > 70 + return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 70 end, hl = { fg = colors.grey_fg2, bg = colors.statusline_bg }, } @@ -240,7 +240,7 @@ components.active[3][1] = { components.active[3][2] = { provider = "git_branch", enabled = shortline or function(winid) - return vim.api.nvim_win_get_width(winid) > 70 + return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 70 end, hl = { fg = colors.grey_fg2, @@ -317,7 +317,7 @@ components.active[3][6] = { components.active[3][7] = { provider = statusline_style.left, enabled = shortline or function(winid) - return vim.api.nvim_win_get_width(winid) > 90 + return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 90 end, hl = { fg = colors.grey, @@ -328,7 +328,7 @@ components.active[3][7] = { components.active[3][8] = { provider = statusline_style.left, enabled = shortline or function(winid) - return vim.api.nvim_win_get_width(winid) > 90 + return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 90 end, hl = { fg = colors.green, @@ -339,7 +339,7 @@ components.active[3][8] = { components.active[3][9] = { provider = statusline_style.position_icon, enabled = shortline or function(winid) - return vim.api.nvim_win_get_width(winid) > 90 + return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 90 end, hl = { fg = colors.black, @@ -362,7 +362,7 @@ components.active[3][10] = { end, enabled = shortline or function(winid) - return vim.api.nvim_win_get_width(winid) > 90 + return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 90 end, hl = {