Skip to content

Commit

Permalink
fix: remove deprecated functions + some annotation fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rebelot committed May 20, 2024
1 parent 170e1b1 commit 2423ce2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 32 deletions.
11 changes: 6 additions & 5 deletions lua/heirline/statusline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ local default_restrict = {
---@field cterm? HeirlineCtermStyle The special style for cterm
---@field force? boolean Control whether the parent's hl fields will override child's hl

---@alias HeirlineOnClickCallback fun(self: StatusLine, minwid: integer, nclicks: integer, button: "l"|"m"|"r", mods: string)
---@alias HeirlineOnClickCallback string|fun(self: StatusLine, minwid: integer, nclicks: integer, button: "l"|"m"|"r", mods: string)
---@class HeirlineOnClick
---@field callback? string|HeirlineOnClickCallback
---@field name? string|fun():string
---@field callback string|HeirlineOnClickCallback
---@field name string|fun(self?: StatusLine):string
---@field update? boolean
---@field minwid? number|fun():integer
---@field minwid? number|fun(self: StatusLine):integer

---@class StatusLine
---@field condition? fun(self: StatusLine): any
Expand Down Expand Up @@ -128,7 +128,7 @@ function StatusLine:new(child, index)

local restrict = tbl_extend("force", default_restrict, self.restrict or {})
setmetatable(new, self)
self.__index = function(t, v)
self.__index = function(_, v)
if not restrict[v] then
return self[v]
end
Expand Down Expand Up @@ -613,4 +613,5 @@ function StatusLine:expand_or_contract_flexible_components(full_width, out)
end
end
end

return StatusLine
33 changes: 6 additions & 27 deletions lua/heirline/utils.lua
Original file line number Diff line number Diff line change
@@ -1,40 +1,17 @@
local M = {}
local nvim_eval_statusline = vim.api.nvim_eval_statusline
local nvim_buf_get_option = vim.api.nvim_buf_get_option
local nvim_get_option_value = vim.api.nvim_buf_get_option_value
local nvim_list_bufs = vim.api.nvim_list_bufs
local nvim_buf_is_valid = vim.api.nvim_buf_is_valid
local tbl_contains = vim.tbl_contains
local tbl_keys = vim.tbl_keys
local tbl_filter = vim.tbl_filter

local function get_highlight_deprecated(name)
local hl = vim.api.nvim_get_hl_by_name(name, vim.o.termguicolors)
if vim.o.termguicolors then
hl.fg = hl.foreground
hl.bg = hl.background
hl.sp = hl.special
hl.foreground = nil
hl.background = nil
hl.special = nil
else
hl.ctermfg = hl.foreground
hl.ctermbg = hl.background
hl.foreground = nil
hl.background = nil
hl.special = nil
end
return hl
end

local function get_highlight(name)
---@type fun(name: string): table
function M.get_highlight(name)
return vim.api.nvim_get_hl(0, { name = name, link = false })
end

---Get highlight properties for a given highlight name
---@type fun(name: string): table
M.get_highlight = vim.fn.exists("*nvim_get_hl") == 1 and get_highlight or get_highlight_deprecated


---Copy the given component, merging its fields with `with`
---@param block table
---@param with? table
Expand Down Expand Up @@ -143,7 +120,7 @@ end

local function get_bufs()
return tbl_filter(function(bufnr)
return nvim_buf_get_option(bufnr, "buflisted")
return nvim_get_option_value("buflisted", { buf = bufnr })
end, nvim_list_bufs())
end

Expand Down Expand Up @@ -271,6 +248,8 @@ function M.make_buflist(buffer_component, left_trunc, right_trunc, buf_func, buf
return nvim_buf_is_valid(bufnr)
end, buf_func())
local visible_buffers = bufs_in_tab()
self.buffers = bufs
self.visible_buffers = visible_buffers

for i, bufnr in ipairs(bufs) do
local child = self[i]
Expand Down

0 comments on commit 2423ce2

Please sign in to comment.