Skip to content

Commit

Permalink
fix: type annotations and type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
stevearc committed Aug 13, 2023
1 parent 81713b3 commit ffb5fd0
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lua/aerial/backends/lsp/callbacks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ end
---@param symbols table
---@param bufnr integer
---@param fix_start_col boolean
---@param client_name LSP client name
---@param client_name string LSP client name
local function process_symbols(symbols, bufnr, fix_start_col, client_name)
local include_kind = config.get_filter_kind_map(bufnr)
local max_line = vim.api.nvim_buf_line_count(bufnr)
Expand Down
2 changes: 2 additions & 0 deletions lua/aerial/backends/treesitter/extensions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ local _, utils = pcall(require, "nvim-treesitter.utils")
local helpers = require("aerial.backends.treesitter.helpers")
local M = {}

---@diagnostic disable deprecated

local get_node_text
if vim.treesitter.get_node_text then
-- Neovim 0.9
Expand Down
2 changes: 2 additions & 0 deletions lua/aerial/backends/treesitter/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ local config = require("aerial.config")
local helpers = require("aerial.backends.treesitter.helpers")
local util = require("aerial.backends.util")

---@diagnostic disable deprecated

---@type aerial.Backend
local M = {}

Expand Down
9 changes: 9 additions & 0 deletions lua/aerial/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,15 @@ M.setup = function(opts)
-- for backwards compatibility
for k, _ in pairs(default_options.lsp) do
if newconf[k] ~= nil then
vim.notify_once(
string.format(
"aerial.config.%s should be moved to aerial.config.lsp.%s (see :help aerial-options)\nThis shim will be removed on 2024-02-11",
k,
k
),
vim.log.levels.WARN
)
---@diagnostic disable-next-line assign-type-mismatch
newconf.lsp[k] = newconf[k]
newconf[k] = nil
end
Expand Down
6 changes: 5 additions & 1 deletion lua/aerial/data.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ local config = require("aerial.config")
---@field parent? aerial.Symbol
---@field selection_range? aerial.Range
---@field children? aerial.Symbol[]
---@field prev_sibling? aerial.Symbol
---@field next_sibling? aerial.Symbol
---@field id? string

---@class aerial.BufData
---@field bufnr integer
Expand All @@ -27,6 +30,7 @@ local config = require("aerial.config")
---@field collapsed table<string, boolean>
---@field collapse_level integer
---@field max_level integer
---@field manage_folds boolean
local BufData = {}

---@param bufnr integer
Expand Down Expand Up @@ -86,7 +90,7 @@ function BufData:set_collapsed(item, collapsed)
end

---@param item aerial.Symbol
---@return boolean
---@return boolean?
function BufData:is_collapsable(item)
return self.manage_folds or (item.children and not vim.tbl_isempty(item.children))
end
Expand Down
18 changes: 15 additions & 3 deletions lua/aerial/highlight.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,21 @@ M.get_highlight = function(symbol, is_icon, is_collapsed)
return string.format("Aerial%s%s", symbol.kind, is_icon and "Icon" or "")
end

local get_hl_by_name
if vim.fn.has("nvim-0.9") == 1 then
get_hl_by_name = function(name)
return vim.api.nvim_get_hl(0, { name = name, link = false })
end
else
get_hl_by_name = function(name)
---@diagnostic disable-next-line undefined-field
return vim.api.nvim_get_hl_by_name(name, true)
end
end

M.create_highlight_groups = function()
-- Use Normal colors for AerialNormal, while stripping bold/italic/etc
local normal_defn = vim.api.nvim_get_hl_by_name("Normal", true)
local normal_defn = get_hl_by_name("Normal")
-- The default text highlight
vim.api.nvim_set_hl(0, "AerialNormal", {
fg = normal_defn.foreground,
Expand All @@ -68,7 +80,7 @@ M.create_highlight_groups = function()
})

-- Set another group for NormalFloat, for use in the nav view
local normal_float_defn = vim.api.nvim_get_hl_by_name("NormalFloat", true)
local normal_float_defn = get_hl_by_name("NormalFloat")
-- Don't set the background for the float so that it blends nicely with the cursorline
vim.api.nvim_set_hl(0, "AerialNormalFloat", {
fg = normal_float_defn.foreground,
Expand All @@ -86,7 +98,7 @@ M.create_highlight_groups = function()
link("AerialProtected", "Comment")

-- Use Comment colors for AerialGuide, while stripping bold/italic/etc
local comment_defn = vim.api.nvim_get_hl_by_name("Comment", true)
local comment_defn = get_hl_by_name("Comment")
-- The guides when show_guide = true
vim.api.nvim_set_hl(0, "AerialGuide", {
fg = comment_defn.foreground,
Expand Down
2 changes: 2 additions & 0 deletions lua/aerial/init.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
local M = {}

---@diagnostic disable undefined-doc-param

local was_closed = nil

local function list_complete(choices)
Expand Down
2 changes: 1 addition & 1 deletion lua/aerial/keymap_util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ local M = {}
local function resolve(action_module, rhs)
if type(rhs) == "string" and vim.startswith(rhs, "actions.") then
local mod = require(action_module)
return resolve(action_module, mod[vim.split(rhs, ".", true)[2]])
return resolve(action_module, mod[vim.split(rhs, ".", { plain = true })[2]])
elseif type(rhs) == "table" then
local opts = vim.deepcopy(rhs)
opts.callback = nil
Expand Down
4 changes: 2 additions & 2 deletions lua/aerial/nav_view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,13 @@ local function get_all_siblings(symbol)
table.insert(ret, symbol)
local i = 1
local iter = symbol
while iter.prev_sibling do
while assert(iter).prev_sibling do
iter = iter.prev_sibling
i = i + 1
table.insert(ret, 1, iter)
end
iter = symbol
while iter.next_sibling do
while assert(iter).next_sibling do
iter = iter.next_sibling
table.insert(ret, iter)
end
Expand Down
2 changes: 1 addition & 1 deletion lua/aerial/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ M.throttle = function(func, opts)
if type(delay) == "function" then
delay = delay(unpack(args))
end
timer = vim.loop.new_timer()
timer = assert(vim.loop.new_timer())
timer:start(delay, 0, function()
timer:close()
timer = nil
Expand Down
2 changes: 1 addition & 1 deletion lua/lualine/components/aerial.lua
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function M:color_text(text, symbol, is_icon)
if not self.options.colored then
return text
end
local hl_group = require("aerial.highlight").get_highlight(symbol, is_icon)
local hl_group = require("aerial.highlight").get_highlight(symbol, is_icon, false)
if hl_group then
local lualine_hl_group = self.highlight_groups[hl_group]
if not lualine_hl_group then
Expand Down
4 changes: 2 additions & 2 deletions lua/telescope/_extensions/aerial.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ local function aerial_picker(opts)
local function make_display(entry)
local item = entry.value
local icon = config.get_icon(bufnr, item.kind)
local icon_hl = highlight.get_highlight(item, true) or "NONE"
local name_hl = highlight.get_highlight(item, false) or "NONE"
local icon_hl = highlight.get_highlight(item, true, false) or "NONE"
local name_hl = highlight.get_highlight(item, false, false) or "NONE"
local columns = {
{ icon, icon_hl },
{ entry.name, name_hl },
Expand Down

0 comments on commit ffb5fd0

Please sign in to comment.