Skip to content

Commit

Permalink
chore: resolve lua language server warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
mehalter committed Dec 20, 2023
1 parent 3f634a9 commit 5747ce6
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 15 deletions.
7 changes: 3 additions & 4 deletions lua/astroui/status/component.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ local extend_tbl = astro.extend_tbl
local is_available = astro.is_available

local ui = require "astroui"
local config = ui.config.status
local config = assert(ui.config.status)
local get_icon = ui.get_icon
local condition = require "astroui.status.condition"
local hl = require "astroui.status.hl"
Expand Down Expand Up @@ -411,9 +411,8 @@ function M.signcolumn(opts)
name = "sign_click",
callback = function(...)
local args = status_utils.statuscolumn_clickargs(...)
if args.sign and args.sign.name and config.sign_handlers[args.sign.name] then
config.sign_handlers[args.sign.name](args)
end
local handler = vim.tbl_get(config, "sign_handlers", vim.tbl_get(args, "sign", "name"))
if handler then handler(args) end
end,
},
}, opts)
Expand Down
8 changes: 5 additions & 3 deletions lua/astroui/status/condition.lua
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ end
-- @usage local heirline_component = { provider = "Example Provider", condition = require("astroui.status").condition.has_filetype }
function M.has_filetype(bufnr)
if type(bufnr) == "table" then bufnr = bufnr.bufnr end
return vim.bo[bufnr or 0].filetype and vim.bo[bufnr or 0].filetype ~= ""
local filetype = vim.bo[bufnr or 0].filetype
return filetype and filetype ~= ""
end

--- A condition function if a buffer is a file
Expand Down Expand Up @@ -161,9 +162,10 @@ function M.aerial_available() return package.loaded["aerial"] end
function M.lsp_attached(bufnr)
if type(bufnr) == "table" then bufnr = bufnr.bufnr end
return (
package.loaded["astrolsp"]
-- HACK: Check for lsp utilities loaded first, get_active_clients seems to have a bug if called too early (tokyonight colorscheme seems to be a good way to expose this for some reason)
-- HACK: Check for lsp utilities loaded first, get_active_clients seems to have a bug if called too early (tokyonight colorscheme seems to be a good way to expose this for some reason)
package.loaded["astrolsp"]
-- TODO: remove get_active_clients when dropping support for Neovim 0.9
---@diagnostic disable-next-line: deprecated
and next((vim.lsp.get_clients or vim.lsp.get_active_clients) { bufnr = bufnr or 0 }) ~= nil
) or (package.loaded["conform"] and next(require("conform").list_formatters(bufnr)) ~= nil)
end
Expand Down
4 changes: 2 additions & 2 deletions lua/astroui/status/heirline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ M.make_buflist = function(component)
condition = function(self) return self._show_picker end,
update = false,
init = function(self)
if not (self.label and self._picker_labels[self.label]) then
if not vim.tbl_get(self._picker_labels, self.label) then
local bufname = provider.filename()(self)
local label = bufname:sub(1, 1)
local i = 2
Expand Down Expand Up @@ -98,7 +98,7 @@ function M.buffer_picker(callback)
if prev_showtabline ~= 2 then vim.opt.showtabline = 2 end
vim.cmd.redrawtabline()
---@diagnostic disable-next-line: undefined-field
local buflist = tabline and tabline._buflist and tabline._buflist[1]
local buflist = vim.tbl_get(tabline, "_buflist", 1)
if buflist then
buflist._picker_labels = {}
buflist._show_picker = true
Expand Down
3 changes: 2 additions & 1 deletion lua/astroui/status/hl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
---@class astroui.status.hl
local M = {}

local config = require("astroui").config.status
local config = assert(require("astroui").config.status)

--- Get the highlight background color of the lualine theme for the current colorscheme
---@param mode string the neovim mode to get the color of
Expand All @@ -34,6 +34,7 @@ function M.mode() return { bg = M.mode_bg() } end
function M.mode_bg() return config.modes[vim.fn.mode()][2] end

--- Get the foreground color group for the current filetype
---@param self { bufnr: integer }? # component state that may hold the buffer number
---@return table # the highlight group for the current filetype foreground
-- @usage local heirline_component = { provider = require("astroui.status").provider.fileicon(), hl = require("astroui.status").hl.filetype_color },
function M.filetype_color(self)
Expand Down
4 changes: 2 additions & 2 deletions lua/astroui/status/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ local M = {}

local astro = require "astrocore"
local ui = require "astroui"
local config = ui.config.status
local config = assert(ui.config.status)
local get_icon = ui.get_icon
local extend_tbl = astro.extend_tbl

Expand Down Expand Up @@ -50,7 +50,7 @@ function M.breadcrumbs(opts)
minwid = status_utils.encode_pos(d.lnum, d.col, self.winnr),
callback = function(_, minwid)
local lnum, col, winnr = status_utils.decode_pos(minwid)
vim.api.nvim_win_set_cursor(vim.fn.win_getid(winnr), { lnum, col })
vim.api.nvim_win_set_cursor(assert(vim.fn.win_getid(winnr)), { lnum, col })
end,
name = "heirline_breadcrumbs",
},
Expand Down
3 changes: 2 additions & 1 deletion lua/astroui/status/provider.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ local is_available = astro.is_available
local luv = vim.uv or vim.loop -- TODO: REMOVE WHEN DROPPING SUPPORT FOR Neovim v0.9

local ui = require "astroui"
local config = ui.config.status
local config = assert(ui.config.status)
local get_icon = ui.get_icon
local condition = require "astroui.status.condition"
local status_utils = require "astroui.status.utils"
Expand Down Expand Up @@ -495,6 +495,7 @@ function M.lsp_client_names(opts)
local bufnr = self and self.bufnr or 0
local buf_client_names = {}
-- TODO: remove get_active_clients when dropping support for Neovim 0.9
---@diagnostic disable-next-line: deprecated
for _, client in pairs((vim.lsp.get_clients or vim.lsp.get_active_clients) { bufnr = bufnr }) do
if client.name == "null-ls" and opts.integrations.null_ls then
local null_ls_sources = {}
Expand Down
4 changes: 2 additions & 2 deletions lua/astroui/status/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ local M = {}

local astro = require "astrocore"
local ui = require "astroui"
local config = ui.config.status
local config = assert(ui.config.status)
local get_icon = ui.get_icon
local extend_tbl = astro.extend_tbl

Expand Down Expand Up @@ -201,7 +201,7 @@ function M.statuscolumn_clickargs(self, minwid, clicks, button, mods)
if args.char == " " then args.char = vim.fn.screenstring(args.mousepos.screenrow, args.mousepos.screencol - 1) end
args.sign = self.signs[args.char]
if not args.sign then -- update signs if not found on first click
for _, sign_def in ipairs(vim.fn.sign_getdefined()) do
for _, sign_def in ipairs(assert(vim.fn.sign_getdefined())) do
if sign_def.text then self.signs[sign_def.text:gsub("%s", "")] = sign_def end
end
args.sign = self.signs[args.char]
Expand Down

0 comments on commit 5747ce6

Please sign in to comment.