fix(lint): make neovim 0.11 typecheck happy (#1844)
This commit is contained in:
2
.github/workflows/lua.yaml
vendored
2
.github/workflows/lua.yaml
vendored
@@ -58,7 +58,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
nvim_version: [ "v0.10.4" ]
|
nvim_version: [ stable ]
|
||||||
luals_version: [ 3.13.6 ]
|
luals_version: [ 3.13.6 ]
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Code
|
- name: Checkout Code
|
||||||
|
|||||||
@@ -432,7 +432,6 @@ function M.setup()
|
|||||||
})
|
})
|
||||||
|
|
||||||
api.nvim_set_decoration_provider(NAMESPACE, {
|
api.nvim_set_decoration_provider(NAMESPACE, {
|
||||||
on_buf = function(_, bufnr, _) return Utils.is_valid_buf(bufnr) end,
|
|
||||||
on_win = function(_, _, bufnr, _, _)
|
on_win = function(_, _, bufnr, _, _)
|
||||||
if visited_buffers[bufnr] then M.process(bufnr) end
|
if visited_buffers[bufnr] then M.process(bufnr) end
|
||||||
end,
|
end,
|
||||||
|
|||||||
@@ -162,7 +162,7 @@ setmetatable(M, {
|
|||||||
---@param rgb_24bit number 24-bit RGB value
|
---@param rgb_24bit number 24-bit RGB value
|
||||||
---@return {r: integer, g: integer, b: integer} with keys 'r', 'g', 'b' in [0,255]
|
---@return {r: integer, g: integer, b: integer} with keys 'r', 'g', 'b' in [0,255]
|
||||||
function H.decode_24bit_rgb(rgb_24bit)
|
function H.decode_24bit_rgb(rgb_24bit)
|
||||||
vim.validate({ rgb_24bit = { rgb_24bit, "n", true } })
|
vim.validate({ rgb_24bit = { rgb_24bit, "number", true } })
|
||||||
local r = band(rshift(rgb_24bit, 16), 255)
|
local r = band(rshift(rgb_24bit, 16), 255)
|
||||||
local g = band(rshift(rgb_24bit, 8), 255)
|
local g = band(rshift(rgb_24bit, 8), 255)
|
||||||
local b = band(rgb_24bit, 255)
|
local b = band(rgb_24bit, 255)
|
||||||
|
|||||||
@@ -2919,10 +2919,13 @@ function Sidebar:create_input_container(opts)
|
|||||||
callback = function() end,
|
callback = function() end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
local hint_ns_id = api.nvim_create_namespace("avante_hint")
|
||||||
|
|
||||||
-- Close the floating window
|
-- Close the floating window
|
||||||
local function close_hint()
|
local function close_hint()
|
||||||
if hint_window and api.nvim_win_is_valid(hint_window) then
|
if hint_window and api.nvim_win_is_valid(hint_window) then
|
||||||
local buf = api.nvim_win_get_buf(hint_window)
|
local buf = api.nvim_win_get_buf(hint_window)
|
||||||
|
if hint_ns_id then api.nvim_buf_clear_namespace(buf, hint_ns_id, 0, -1) end
|
||||||
api.nvim_win_close(hint_window, true)
|
api.nvim_win_close(hint_window, true)
|
||||||
api.nvim_buf_delete(buf, { force = true })
|
api.nvim_buf_delete(buf, { force = true })
|
||||||
hint_window = nil
|
hint_window = nil
|
||||||
@@ -2946,7 +2949,7 @@ function Sidebar:create_input_container(opts)
|
|||||||
local function show()
|
local function show()
|
||||||
local buf = api.nvim_create_buf(false, true)
|
local buf = api.nvim_create_buf(false, true)
|
||||||
api.nvim_buf_set_lines(buf, 0, -1, false, { hint_text })
|
api.nvim_buf_set_lines(buf, 0, -1, false, { hint_text })
|
||||||
api.nvim_buf_add_highlight(buf, 0, "AvantePopupHint", 0, 0, -1)
|
api.nvim_buf_set_extmark(buf, hint_ns_id, 0, 0, { hl_group = "AvantePopupHint", end_col = #hint_text })
|
||||||
|
|
||||||
-- Get the current window size
|
-- Get the current window size
|
||||||
local win_width = api.nvim_win_get_width(self.input_container.winid)
|
local win_width = api.nvim_win_get_width(self.input_container.winid)
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ local SUGGESTION_NS = api.nvim_create_namespace("avante_suggestion")
|
|||||||
---@field augroup integer
|
---@field augroup integer
|
||||||
---@field ignore_patterns table
|
---@field ignore_patterns table
|
||||||
---@field negate_patterns table
|
---@field negate_patterns table
|
||||||
---@field _timer? table
|
---@field _timer? integer
|
||||||
---@field _contexts table
|
---@field _contexts table
|
||||||
---@field is_on_throttle boolean
|
---@field is_on_throttle boolean
|
||||||
local Suggestion = {}
|
local Suggestion = {}
|
||||||
@@ -302,7 +302,14 @@ function Suggestion:show()
|
|||||||
for i = start_row, end_row do
|
for i = start_row, end_row do
|
||||||
if i == start_row and start_row == cursor_row and virt_text_win_col > 0 then goto continue end
|
if i == start_row and start_row == cursor_row and virt_text_win_col > 0 then goto continue end
|
||||||
Utils.debug("add highlight", i - 1)
|
Utils.debug("add highlight", i - 1)
|
||||||
api.nvim_buf_add_highlight(bufnr, SUGGESTION_NS, Highlights.TO_BE_DELETED, i - 1, 0, -1)
|
local old_line = current_lines[i]
|
||||||
|
api.nvim_buf_set_extmark(
|
||||||
|
bufnr,
|
||||||
|
SUGGESTION_NS,
|
||||||
|
i - 1,
|
||||||
|
0,
|
||||||
|
{ hl_group = Highlights.TO_BE_DELETED, end_row = i - 1, end_col = #old_line }
|
||||||
|
)
|
||||||
::continue::
|
::continue::
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ local Config = require("avante.config")
|
|||||||
---@field _group number | nil
|
---@field _group number | nil
|
||||||
---@field _popup NuiPopup | nil
|
---@field _popup NuiPopup | nil
|
||||||
---@field _prev_winid number | nil
|
---@field _prev_winid number | nil
|
||||||
|
---@field _ns_id number | nil
|
||||||
local M = {}
|
local M = {}
|
||||||
M.__index = M
|
M.__index = M
|
||||||
|
|
||||||
@@ -27,6 +28,7 @@ function M:new(message, callback, opts)
|
|||||||
this.callback = callback
|
this.callback = callback
|
||||||
this._container_winid = opts.container_winid or vim.api.nvim_get_current_win()
|
this._container_winid = opts.container_winid or vim.api.nvim_get_current_win()
|
||||||
this._focus = opts.focus
|
this._focus = opts.focus
|
||||||
|
this._ns_id = vim.api.nvim_create_namespace("avante_confirm")
|
||||||
return this
|
return this
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -144,8 +146,8 @@ function M:open()
|
|||||||
vim.api.nvim_buf_set_lines(popup.bufnr, 0, -1, false, content)
|
vim.api.nvim_buf_set_lines(popup.bufnr, 0, -1, false, content)
|
||||||
Utils.lock_buf(popup.bufnr)
|
Utils.lock_buf(popup.bufnr)
|
||||||
|
|
||||||
buttons_line:set_highlights(0, popup.bufnr, buttons_line_num, buttons_start_col)
|
buttons_line:set_highlights(self._ns_id, popup.bufnr, buttons_line_num, buttons_start_col)
|
||||||
keybindings_line:set_highlights(0, popup.bufnr, keybindings_line_num)
|
keybindings_line:set_highlights(self._ns_id, popup.bufnr, keybindings_line_num)
|
||||||
focus_button()
|
focus_button()
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -359,6 +361,7 @@ function M:close()
|
|||||||
self._popup = nil
|
self._popup = nil
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
if self._ns_id then vim.api.nvim_del_namespace(self._ns_id) end
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,9 @@ function M:set_highlights(ns_id, bufnr, line, offset)
|
|||||||
local text = section[1]
|
local text = section[1]
|
||||||
local highlight = section[2]
|
local highlight = section[2]
|
||||||
if type(highlight) == "function" then highlight = highlight() end
|
if type(highlight) == "function" then highlight = highlight() end
|
||||||
if highlight then vim.api.nvim_buf_add_highlight(bufnr, ns_id, highlight, line, col_start, col_start + #text) end
|
if highlight then
|
||||||
|
vim.highlight.range(bufnr, ns_id, highlight, { line, col_start }, { line, col_start + #text })
|
||||||
|
end
|
||||||
col_start = col_start + #text
|
col_start = col_start + #text
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ local Utils = require("avante.utils")
|
|||||||
---@field spinner_timer uv_timer_t | nil
|
---@field spinner_timer uv_timer_t | nil
|
||||||
---@field spinner_active boolean
|
---@field spinner_active boolean
|
||||||
---@field default_value string | nil
|
---@field default_value string | nil
|
||||||
|
---@field popup_hint_id integer | nil
|
||||||
local PromptInput = {}
|
local PromptInput = {}
|
||||||
PromptInput.__index = PromptInput
|
PromptInput.__index = PromptInput
|
||||||
|
|
||||||
@@ -87,6 +88,7 @@ function PromptInput:new(opts)
|
|||||||
obj.spinner_index = 1
|
obj.spinner_index = 1
|
||||||
obj.spinner_timer = nil
|
obj.spinner_timer = nil
|
||||||
obj.spinner_active = false
|
obj.spinner_active = false
|
||||||
|
obj.popup_hint_id = vim.api.nvim_create_namespace("avante_prompt_input_hint")
|
||||||
return obj
|
return obj
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -184,7 +186,12 @@ function PromptInput:show_shortcuts_hints()
|
|||||||
|
|
||||||
local buf = api.nvim_create_buf(false, true)
|
local buf = api.nvim_create_buf(false, true)
|
||||||
api.nvim_buf_set_lines(buf, 0, -1, false, { display_text })
|
api.nvim_buf_set_lines(buf, 0, -1, false, { display_text })
|
||||||
vim.api.nvim_buf_add_highlight(buf, 0, "AvantePopupHint", 0, 0, -1)
|
api.nvim_buf_set_extmark(buf, self.popup_hint_id, 0, 0, {
|
||||||
|
end_row = 0,
|
||||||
|
end_col = #display_text,
|
||||||
|
hl_group = "AvantePopupHint",
|
||||||
|
priority = 100,
|
||||||
|
})
|
||||||
|
|
||||||
local width = fn.strdisplaywidth(display_text)
|
local width = fn.strdisplaywidth(display_text)
|
||||||
|
|
||||||
@@ -208,6 +215,7 @@ end
|
|||||||
function PromptInput:close_shortcuts_hints()
|
function PromptInput:close_shortcuts_hints()
|
||||||
if self.shortcuts_hints_winid and api.nvim_win_is_valid(self.shortcuts_hints_winid) then
|
if self.shortcuts_hints_winid and api.nvim_win_is_valid(self.shortcuts_hints_winid) then
|
||||||
local buf = api.nvim_win_get_buf(self.shortcuts_hints_winid)
|
local buf = api.nvim_win_get_buf(self.shortcuts_hints_winid)
|
||||||
|
if self.popup_hint_id then api.nvim_buf_clear_namespace(buf, self.popup_hint_id, 0, -1) end
|
||||||
api.nvim_win_close(self.shortcuts_hints_winid, true)
|
api.nvim_win_close(self.shortcuts_hints_winid, true)
|
||||||
api.nvim_buf_delete(buf, { force = true })
|
api.nvim_buf_delete(buf, { force = true })
|
||||||
self.shortcuts_hints_winid = nil
|
self.shortcuts_hints_winid = nil
|
||||||
|
|||||||
@@ -82,7 +82,13 @@ function M.read_definitions(bufnr, symbol_name, show_line_numbers, on_complete)
|
|||||||
---@type avante.lsp.Definition[]
|
---@type avante.lsp.Definition[]
|
||||||
local res = {}
|
local res = {}
|
||||||
for _, result in ipairs(results) do
|
for _, result in ipairs(results) do
|
||||||
|
if result.err then
|
||||||
|
on_complete(nil, result.err.message)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
---@diagnostic disable-next-line: undefined-field
|
||||||
if result.error then
|
if result.error then
|
||||||
|
---@diagnostic disable-next-line: undefined-field
|
||||||
on_complete(nil, result.error.message)
|
on_complete(nil, result.error.message)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user