Refresh generated neovim config
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
local require = require("noice.util.lazy")
|
||||
|
||||
local Manager = require("noice.message.manager")
|
||||
local Config = require("noice.config")
|
||||
local Manager = require("noice.message.manager")
|
||||
|
||||
---@type NoiceFilter
|
||||
local nothing = { ["not"] = {} }
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
local require = require("noice.util.lazy")
|
||||
|
||||
local View = require("noice.view")
|
||||
local Manager = require("noice.message.manager")
|
||||
local Config = require("noice.config")
|
||||
local Util = require("noice.util")
|
||||
local Manager = require("noice.message.manager")
|
||||
local Message = require("noice.message")
|
||||
local Router = require("noice.message.router")
|
||||
local Util = require("noice.util")
|
||||
local View = require("noice.view")
|
||||
|
||||
---@class NoiceCommand: NoiceRouteConfig
|
||||
---@field filter_opts NoiceMessageOpts
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
local require = require("noice.util.lazy")
|
||||
|
||||
local Util = require("noice.util")
|
||||
local Config = require("noice.config")
|
||||
local Util = require("noice.util")
|
||||
|
||||
---@class NoicePreset: NoiceConfig
|
||||
---@field enabled? boolean
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
local require = require("noice.util.lazy")
|
||||
|
||||
local Util = require("noice.util")
|
||||
local Config = require("noice.config")
|
||||
local Util = require("noice.util")
|
||||
|
||||
local M = {}
|
||||
|
||||
@ -241,7 +241,7 @@ M.defaults = {
|
||||
zindex = 210,
|
||||
format = { "{confirm}" },
|
||||
position = {
|
||||
row = "50%",
|
||||
row = 3,
|
||||
col = "50%",
|
||||
},
|
||||
size = "auto",
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
local require = require("noice.util.lazy")
|
||||
|
||||
local Util = require("noice.util")
|
||||
local Config = require("noice.config")
|
||||
local Lsp = require("noice.lsp")
|
||||
local Treesitter = require("noice.text.treesitter")
|
||||
local Util = require("noice.util")
|
||||
|
||||
local start = vim.health.start or vim.health.report_start
|
||||
local ok = vim.health.ok or vim.health.report_ok
|
||||
@ -227,7 +227,6 @@ function M.get_source(fn)
|
||||
end
|
||||
return ret
|
||||
end
|
||||
M.check({ checkhealth = false })
|
||||
|
||||
M.checker = Util.interval(1000, function()
|
||||
if Config.is_running() then
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
local require = require("noice.util.lazy")
|
||||
|
||||
local Health = require("noice.health")
|
||||
local Api = require("noice.api")
|
||||
local Config = require("noice.config")
|
||||
local Health = require("noice.health")
|
||||
|
||||
local M = {}
|
||||
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
local require = require("noice.util.lazy")
|
||||
|
||||
local Manager = require("noice.message.manager")
|
||||
local Util = require("noice.util")
|
||||
local Message = require("noice.message")
|
||||
local Util = require("noice.util")
|
||||
|
||||
local M = {}
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
local require = require("noice.util.lazy")
|
||||
local Util = require("noice.util")
|
||||
local require = require("noice.util.lazy")
|
||||
|
||||
local Markdown = require("noice.text.markdown")
|
||||
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
local require = require("noice.util.lazy")
|
||||
|
||||
local Config = require("noice.config")
|
||||
local Docs = require("noice.lsp.docs")
|
||||
local Format = require("noice.lsp.format")
|
||||
local Util = require("noice.util")
|
||||
local Docs = require("noice.lsp.docs")
|
||||
local Config = require("noice.config")
|
||||
|
||||
local M = {}
|
||||
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
local require = require("noice.util.lazy")
|
||||
local Markdown = require("noice.text.markdown")
|
||||
local require = require("noice.util.lazy")
|
||||
|
||||
local Config = require("noice.config")
|
||||
local Format = require("noice.lsp.format")
|
||||
local Message = require("noice.message")
|
||||
local Hacks = require("noice.util.hacks")
|
||||
local Message = require("noice.message")
|
||||
|
||||
local M = {}
|
||||
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
local require = require("noice.util.lazy")
|
||||
|
||||
local Message = require("noice.message")
|
||||
local Manager = require("noice.message.manager")
|
||||
local Router = require("noice.message.router")
|
||||
local Format = require("noice.text.format")
|
||||
local Config = require("noice.config")
|
||||
local Format = require("noice.text.format")
|
||||
local Manager = require("noice.message.manager")
|
||||
local Message = require("noice.message")
|
||||
local Router = require("noice.message.router")
|
||||
local Util = require("noice.util")
|
||||
|
||||
local M = {}
|
||||
@ -16,7 +16,7 @@ M._running = false
|
||||
---@param data {client_id: integer, params: lsp.ProgressParams}
|
||||
function M.progress(data)
|
||||
local client_id = data.client_id
|
||||
local params = data.params or data.result -- TODO: Remove data.result after nvim 0.10 release
|
||||
local params = data.params or data.result -- TODO: Remove data.result after nvim 0.10 release
|
||||
local id = client_id .. "." .. params.token
|
||||
|
||||
local message = M._progress[id]
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
local require = require("noice.util.lazy")
|
||||
|
||||
local NoiceText = require("noice.text")
|
||||
local Config = require("noice.config")
|
||||
local Docs = require("noice.lsp.docs")
|
||||
local Format = require("noice.lsp.format")
|
||||
local Markdown = require("noice.text.markdown")
|
||||
local Config = require("noice.config")
|
||||
local NoiceText = require("noice.text")
|
||||
local Util = require("noice.util")
|
||||
local Docs = require("noice.lsp.docs")
|
||||
|
||||
---@class SignatureInformation
|
||||
---@field label string
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
local require = require("noice.util.lazy")
|
||||
|
||||
local Util = require("noice.util")
|
||||
local Manager = require("noice.message.manager")
|
||||
local Util = require("noice.util")
|
||||
|
||||
local M = {}
|
||||
|
||||
|
||||
@ -18,10 +18,19 @@ local _id = 0
|
||||
---@field cmdline? NoiceCmdline
|
||||
---@field _debug? boolean
|
||||
---@field opts table<string, any>
|
||||
---@field _buf_messages table<integer, table<number, true>>
|
||||
---@overload fun(event: NoiceEvent, kind?: NoiceKind, content?: NoiceContent|NoiceContent[]): NoiceMessage
|
||||
---@diagnostic disable-next-line: undefined-field
|
||||
local Message = Block:extend("NoiceBlock")
|
||||
|
||||
Message._buf_messages = {}
|
||||
vim.api.nvim_create_autocmd("BufDelete", {
|
||||
group = vim.api.nvim_create_augroup("noice.message", { clear = true }),
|
||||
callback = function(args)
|
||||
Message._buf_messages[args.buf] = nil
|
||||
end,
|
||||
})
|
||||
|
||||
---@param event NoiceEvent
|
||||
---@param kind? NoiceKind
|
||||
---@param content? NoiceContent|NoiceContent[]
|
||||
@ -74,9 +83,7 @@ end
|
||||
function Message:on_remove()
|
||||
for _, buf in ipairs(vim.api.nvim_list_bufs()) do
|
||||
if self:on_buf(buf) then
|
||||
vim.b[buf].messages = vim.tbl_filter(function(b)
|
||||
return b ~= buf
|
||||
end, vim.b[buf].messages)
|
||||
self._buf_messages[buf][self.id] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -86,13 +93,13 @@ function Message:on_win(win)
|
||||
end
|
||||
|
||||
function Message:on_buf(buf)
|
||||
return vim.b[buf].messages and vim.tbl_contains(vim.b[buf].messages, self.id)
|
||||
return self._buf_messages[buf] and not not self._buf_messages[buf][self.id]
|
||||
end
|
||||
|
||||
function Message:_add_buf(buf)
|
||||
local bufs = vim.b[buf].messages or {}
|
||||
table.insert(bufs, self.id)
|
||||
vim.b[buf].messages = bufs
|
||||
local msgs = self._buf_messages[buf] or {}
|
||||
msgs[self.id] = true
|
||||
self._buf_messages[buf] = msgs
|
||||
end
|
||||
|
||||
---@param bufnr number buffer number
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
local require = require("noice.util.lazy")
|
||||
|
||||
local Config = require("noice.config")
|
||||
local Manager = require("noice.message.manager")
|
||||
local Util = require("noice.util")
|
||||
local View = require("noice.view")
|
||||
local Manager = require("noice.message.manager")
|
||||
|
||||
---@class NoiceRoute
|
||||
---@field view NoiceView
|
||||
@ -107,18 +107,6 @@ function M.setup()
|
||||
end
|
||||
end
|
||||
|
||||
function M.check_redraw()
|
||||
if Util.is_blocking() and M._need_redraw then
|
||||
-- don't do full redraw during search
|
||||
if not (Util.is_search() and require("noice.ui.cmdline").real_cursor) then
|
||||
-- NOTE: set to false before actually calling redraw to prevent a loop with ui
|
||||
M._need_redraw = false
|
||||
Util.redraw()
|
||||
end
|
||||
require("noice.ui.cmdline").fix_cursor()
|
||||
end
|
||||
end
|
||||
|
||||
function M.view_stats()
|
||||
local views = M.get_views()
|
||||
---@type table<string,number>
|
||||
@ -168,7 +156,6 @@ function M.update()
|
||||
|
||||
-- only update on changes
|
||||
if M._tick == Manager.tick() then
|
||||
M.check_redraw()
|
||||
return
|
||||
end
|
||||
|
||||
@ -239,7 +226,6 @@ function M.update()
|
||||
M._need_redraw = true
|
||||
end
|
||||
|
||||
M.check_redraw()
|
||||
M._updating = false
|
||||
end
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
local require = require("noice.util.lazy")
|
||||
|
||||
local Message = require("noice.message")
|
||||
local Manager = require("noice.message.manager")
|
||||
local Message = require("noice.message")
|
||||
local Router = require("noice.message.router")
|
||||
local Util = require("noice.util")
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
local require = require("noice.util.lazy")
|
||||
|
||||
local Util = require("noice.util")
|
||||
local NoiceText = require("noice.text")
|
||||
local Util = require("noice.util")
|
||||
|
||||
local M = {}
|
||||
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
local require = require("noice.util.lazy")
|
||||
|
||||
local Util = require("noice.util")
|
||||
local Config = require("noice.config")
|
||||
local FormatConfig = require("noice.config.format")
|
||||
local Formatters = require("noice.text.format.formatters")
|
||||
local NuiText = require("nui.text")
|
||||
local Util = require("noice.util")
|
||||
|
||||
local M = {}
|
||||
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
local require = require("noice.util.lazy")
|
||||
|
||||
local NuiText = require("nui.text")
|
||||
local Treesitter = require("noice.text.treesitter")
|
||||
local Syntax = require("noice.text.syntax")
|
||||
local Markdown = require("noice.text.markdown")
|
||||
local NuiText = require("nui.text")
|
||||
local Syntax = require("noice.text.syntax")
|
||||
local Treesitter = require("noice.text.treesitter")
|
||||
|
||||
---@class NoiceExtmark
|
||||
---@field col? number
|
||||
@ -113,7 +113,7 @@ function NoiceText:highlight(bufnr, ns_id, linenr, byte_start)
|
||||
end
|
||||
|
||||
if self.enabled ~= false then
|
||||
NoiceText.super.highlight(self, bufnr, ns_id, linenr, byte_start)
|
||||
pcall(NoiceText.super.highlight, self, bufnr, ns_id, linenr, byte_start)
|
||||
end
|
||||
|
||||
if self.on_render then
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
local require = require("noice.util.lazy")
|
||||
|
||||
local NoiceText = require("noice.text")
|
||||
local Config = require("noice.config")
|
||||
local NoiceText = require("noice.text")
|
||||
|
||||
---@alias MarkdownBlock {line:string}
|
||||
---@alias MarkdownCodeBlock {code:string[], lang:string}
|
||||
|
||||
@ -1,5 +1,9 @@
|
||||
local M = {}
|
||||
|
||||
local function fix(str)
|
||||
return str:gsub("[^%w_%.%-]+", "_")
|
||||
end
|
||||
|
||||
--- Highlights a region of the buffer with a given language
|
||||
---@param buf buffer buffer to highlight. Defaults to the current buffer if 0
|
||||
---@param ns number namespace for the highlights
|
||||
@ -7,6 +11,7 @@ local M = {}
|
||||
---@param lang string treesitter language
|
||||
function M.highlight(buf, ns, range, lang)
|
||||
vim.api.nvim_buf_call(buf, function()
|
||||
lang = fix(lang)
|
||||
local group = "@" .. lang:upper()
|
||||
|
||||
-- HACK: reset current_syntax, since some syntax files like markdown won't load if it is already set
|
||||
|
||||
@ -34,6 +34,7 @@
|
||||
---@field border? _.NuiBorder
|
||||
---@field anchor? NuiAnchor|"auto"
|
||||
---@field focusable boolean
|
||||
---@field scrollbar? boolean
|
||||
---@field zindex? number
|
||||
|
||||
---@class NuiPopupOptions: NuiBaseOptions,_.NuiPopupOptions
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
local require = require("noice.util.lazy")
|
||||
|
||||
local Message = require("noice.message")
|
||||
local Manager = require("noice.message.manager")
|
||||
local Config = require("noice.config")
|
||||
local NoiceText = require("noice.text")
|
||||
local Hacks = require("noice.util.hacks")
|
||||
local Manager = require("noice.message.manager")
|
||||
local Message = require("noice.message")
|
||||
local NoiceText = require("noice.text")
|
||||
local Object = require("nui.object")
|
||||
|
||||
local M = {}
|
||||
@ -35,7 +35,7 @@ M.real_cursor = vim.api.nvim__redraw ~= nil
|
||||
---@field prompt string
|
||||
---@field indent number
|
||||
---@field level number
|
||||
---@field block table
|
||||
---@field block? table
|
||||
|
||||
---@class CmdlineFormat
|
||||
---@field name string
|
||||
@ -229,27 +229,24 @@ end
|
||||
M.position = nil
|
||||
|
||||
function M.fix_cursor()
|
||||
if not M.position then
|
||||
local win = M.win()
|
||||
if not win or not M.real_cursor then
|
||||
return
|
||||
end
|
||||
local win = M.position.win
|
||||
local cursor = M.position.cursor
|
||||
if vim.api.nvim_win_is_valid(win) then
|
||||
local height = vim.api.nvim_buf_line_count(M.position.buf)
|
||||
vim.api.nvim_win_set_cursor(win, { height, cursor })
|
||||
local cursor = { vim.api.nvim_buf_line_count(M.position.buf), M.position.cursor }
|
||||
vim.api.nvim_win_set_cursor(win, cursor)
|
||||
local leftcol = math.max(cursor[2] - vim.api.nvim_win_get_width(win) + 1, 0)
|
||||
local view = vim.api.nvim_win_call(win, vim.fn.winsaveview)
|
||||
if view.leftcol ~= leftcol then
|
||||
vim.api.nvim_win_call(win, function()
|
||||
local width = vim.api.nvim_win_get_width(win)
|
||||
local leftcol = math.max(cursor - width + 1, 0)
|
||||
vim.fn.winrestview({ leftcol = leftcol })
|
||||
end)
|
||||
if M.real_cursor then
|
||||
vim.cmd.redrawstatus()
|
||||
vim.api.nvim__redraw({
|
||||
cursor = true,
|
||||
win = win,
|
||||
})
|
||||
end
|
||||
end
|
||||
vim.api.nvim__redraw({ cursor = true, win = win })
|
||||
end
|
||||
|
||||
function M.win()
|
||||
return M.position and M.position.win and vim.api.nvim_win_is_valid(M.position.win) and M.position.win or nil
|
||||
end
|
||||
|
||||
---@param buf number
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
local require = require("noice.util.lazy")
|
||||
|
||||
local Config = require("noice.config")
|
||||
local Util = require("noice.util")
|
||||
local Router = require("noice.message.router")
|
||||
local Manager = require("noice.message.manager")
|
||||
local Router = require("noice.message.router")
|
||||
local Util = require("noice.util")
|
||||
|
||||
---@alias NoiceEvent MsgEvent|CmdlineEvent|NotifyEvent|LspEvent
|
||||
---@alias NoiceKind MsgKind|NotifyLevel|LspKind
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
local require = require("noice.util.lazy")
|
||||
|
||||
local Cmdline = require("noice.ui.cmdline")
|
||||
local Hacks = require("noice.util.hacks")
|
||||
local Manager = require("noice.message.manager")
|
||||
local Message = require("noice.message")
|
||||
local Hacks = require("noice.util.hacks")
|
||||
local State = require("noice.ui.state")
|
||||
local Cmdline = require("noice.ui.cmdline")
|
||||
|
||||
local M = {}
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
local require = require("noice.util.lazy")
|
||||
|
||||
local Util = require("noice.util")
|
||||
local Config = require("noice.config")
|
||||
local Util = require("noice.util")
|
||||
|
||||
local M = {}
|
||||
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
local require = require("noice.util.lazy")
|
||||
|
||||
local Util = require("noice.util")
|
||||
local Config = require("noice.config")
|
||||
local Menu = require("nui.menu")
|
||||
local Api = require("noice.api")
|
||||
local Config = require("noice.config")
|
||||
local Highlights = require("noice.config.highlights")
|
||||
local Menu = require("nui.menu")
|
||||
local NuiLine = require("nui.line")
|
||||
local Scrollbar = require("noice.view.scrollbar")
|
||||
local Highlights = require("noice.config.highlights")
|
||||
local Util = require("noice.util")
|
||||
|
||||
local M = {}
|
||||
---@type NuiMenu|NuiTree
|
||||
@ -206,12 +206,11 @@ function M.show(state)
|
||||
M.create(items, opts)
|
||||
end
|
||||
|
||||
M.on_select(state, false)
|
||||
-- redraw is needed when in blocking mode
|
||||
if Util.is_blocking() then
|
||||
Util.redraw()
|
||||
end
|
||||
|
||||
M.on_select(state)
|
||||
end
|
||||
|
||||
---@param opts _.NuiPopupOptions
|
||||
@ -225,12 +224,15 @@ function M.create(items, opts)
|
||||
if M.menu.border then
|
||||
Util.tag(M.menu.border.bufnr, "popupmenu.border")
|
||||
end
|
||||
vim.wo[M.menu.winid].cursorline = false
|
||||
|
||||
M.scroll = Scrollbar({
|
||||
winnr = M.menu.winid,
|
||||
padding = Util.nui.normalize_padding(opts.border),
|
||||
})
|
||||
M.scroll:mount()
|
||||
if opts.scrollbar ~= false then
|
||||
M.scroll = Scrollbar({
|
||||
winnr = M.menu.winid,
|
||||
padding = Util.nui.normalize_padding(opts.border),
|
||||
})
|
||||
M.scroll:mount()
|
||||
end
|
||||
end
|
||||
|
||||
---@param state Popupmenu
|
||||
@ -239,10 +241,19 @@ function M.on_show(state)
|
||||
end
|
||||
|
||||
---@param state Popupmenu
|
||||
function M.on_select(state)
|
||||
if M.menu and state.selected ~= -1 then
|
||||
vim.api.nvim_win_set_cursor(M.menu.winid, { state.selected + 1, 0 })
|
||||
vim.api.nvim_exec_autocmds("WinScrolled", { modeline = false })
|
||||
---@param redraw? boolean
|
||||
function M.on_select(state, redraw)
|
||||
if M.menu then
|
||||
if state.selected == -1 then
|
||||
vim.wo[M.menu.winid].cursorline = false
|
||||
else
|
||||
vim.wo[M.menu.winid].cursorline = true
|
||||
vim.api.nvim_win_set_cursor(M.menu.winid, { state.selected + 1, 0 })
|
||||
vim.api.nvim_exec_autocmds("WinScrolled", { modeline = false })
|
||||
if redraw ~= false and Util.is_blocking() then
|
||||
Util.redraw()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
local require = require("noice.util.lazy")
|
||||
|
||||
local Util = require("noice.util")
|
||||
local Router = require("noice.message.router")
|
||||
local Api = require("noice.api")
|
||||
local Cmdline = require("noice.ui.cmdline")
|
||||
local Util = require("noice.util")
|
||||
local uv = vim.uv or vim.loop
|
||||
|
||||
-- HACK: a bunch of hacks to make Noice behave
|
||||
local M = {}
|
||||
@ -17,11 +17,9 @@ end
|
||||
|
||||
function M.enable()
|
||||
M.reset_augroup()
|
||||
M.fix_input()
|
||||
M.fix_redraw()
|
||||
M.fix_cmp()
|
||||
M.fix_vim_sleuth()
|
||||
-- M.fix_cmdpreview()
|
||||
M.fix_redraw()
|
||||
|
||||
-- Hacks for Neovim < 0.10
|
||||
if vim.fn.has("nvim-0.10") == 0 then
|
||||
@ -29,6 +27,28 @@ function M.enable()
|
||||
end
|
||||
end
|
||||
|
||||
function M.fix_redraw()
|
||||
local timer = uv.new_timer()
|
||||
timer:start(
|
||||
0,
|
||||
30,
|
||||
vim.schedule_wrap(function()
|
||||
if not Util.is_search() then
|
||||
if vim.api.nvim__redraw then
|
||||
vim.api.nvim__redraw({ flush = true, cursor = true })
|
||||
else
|
||||
vim.cmd.redraw()
|
||||
end
|
||||
end
|
||||
Cmdline.fix_cursor()
|
||||
end)
|
||||
)
|
||||
table.insert(M._disable, function()
|
||||
timer:stop()
|
||||
timer:close()
|
||||
end)
|
||||
end
|
||||
|
||||
function M.fix_vim_sleuth()
|
||||
vim.g.sleuth_noice_heuristics = 0
|
||||
end
|
||||
@ -57,15 +77,6 @@ function M.fix_nohlsearch()
|
||||
M.fix_nohlsearch()
|
||||
end
|
||||
|
||||
---@see https://github.com/neovim/neovim/issues/20793
|
||||
function M.draw_cursor()
|
||||
if vim.api.nvim__redraw then
|
||||
vim.api.nvim__redraw({ cursor = true })
|
||||
else
|
||||
require("noice.util.ffi").setcursor_mayforce(true)
|
||||
end
|
||||
end
|
||||
|
||||
---@see https://github.com/neovim/neovim/issues/17810
|
||||
function M.fix_incsearch()
|
||||
---@type integer|nil
|
||||
@ -92,123 +103,6 @@ function M.fix_incsearch()
|
||||
})
|
||||
end
|
||||
|
||||
-- we need to intercept redraw so we can safely ignore message triggered by redraw
|
||||
-- This wraps vim.cmd, nvim_cmd, nvim_command and nvim_exec
|
||||
---@see https://github.com/neovim/neovim/issues/20416
|
||||
M.inside_redraw = false
|
||||
function M.fix_redraw()
|
||||
local nvim_cmd = vim.api.nvim_cmd
|
||||
|
||||
local function wrap(fn, ...)
|
||||
local inside_redraw = M.inside_redraw
|
||||
|
||||
M.inside_redraw = true
|
||||
|
||||
---@type boolean, any
|
||||
local ok, ret = pcall(fn, ...)
|
||||
|
||||
-- check if the ui needs updating
|
||||
Util.try(Router.update)
|
||||
|
||||
if not inside_redraw then
|
||||
M.inside_redraw = false
|
||||
end
|
||||
|
||||
if ok then
|
||||
return ret
|
||||
end
|
||||
error(ret)
|
||||
end
|
||||
|
||||
vim.api.nvim_cmd = function(cmd, ...)
|
||||
if type(cmd) == "table" and cmd.cmd and cmd.cmd == "redraw" then
|
||||
return wrap(nvim_cmd, cmd, ...)
|
||||
else
|
||||
return nvim_cmd(cmd, ...)
|
||||
end
|
||||
end
|
||||
|
||||
local nvim_command = vim.api.nvim_command
|
||||
vim.api.nvim_command = function(cmd, ...)
|
||||
if cmd == "redraw" then
|
||||
return wrap(nvim_command, cmd, ...)
|
||||
else
|
||||
return nvim_command(cmd, ...)
|
||||
end
|
||||
end
|
||||
|
||||
local nvim_exec = vim.api.nvim_exec
|
||||
vim.api.nvim_exec = function(cmd, ...)
|
||||
if type(cmd) == "string" and cmd:find("redraw") then
|
||||
-- WARN: this will potentially lose messages before or after the redraw ex command
|
||||
-- example: echo "foo" | redraw | echo "bar"
|
||||
-- the 'foo' message will be lost
|
||||
return wrap(nvim_exec, cmd, ...)
|
||||
else
|
||||
return nvim_exec(cmd, ...)
|
||||
end
|
||||
end
|
||||
|
||||
table.insert(M._disable, function()
|
||||
vim.api.nvim_cmd = nvim_cmd
|
||||
vim.api.nvim_command = nvim_command
|
||||
vim.api.nvim_exec = nvim_exec
|
||||
end)
|
||||
end
|
||||
|
||||
---@see https://github.com/neovim/neovim/issues/20311
|
||||
M.before_input = false
|
||||
function M.fix_input()
|
||||
local function wrap(fn, skip)
|
||||
return function(...)
|
||||
if skip and skip(...) then
|
||||
return fn(...)
|
||||
end
|
||||
|
||||
-- make sure the cursor is drawn before blocking
|
||||
M.draw_cursor()
|
||||
|
||||
local Manager = require("noice.message.manager")
|
||||
|
||||
-- do any updates now before blocking
|
||||
M.before_input = true
|
||||
Router.update()
|
||||
|
||||
---@type boolean, any
|
||||
local ok, ret = pcall(fn, ...)
|
||||
|
||||
-- clear any message right after input
|
||||
Manager.clear({ event = "msg_show", kind = { "echo", "echomsg", "" } })
|
||||
|
||||
M.before_input = false
|
||||
if ok then
|
||||
return ret
|
||||
end
|
||||
error(ret)
|
||||
end
|
||||
end
|
||||
|
||||
local function skip(expr)
|
||||
return expr ~= nil
|
||||
end
|
||||
local getchar = vim.fn.getchar
|
||||
local getcharstr = vim.fn.getcharstr
|
||||
local inputlist = vim.fn.inputlist
|
||||
-- local confirm = vim.fn.confirm
|
||||
|
||||
vim.fn.getchar = wrap(vim.fn.getchar, skip)
|
||||
vim.fn.getcharstr = wrap(vim.fn.getcharstr, skip)
|
||||
vim.fn.inputlist = wrap(vim.fn.inputlist, nil)
|
||||
-- vim.fn.confirm = wrap(vim.fn.confirm, nil)
|
||||
|
||||
table.insert(M._disable, function()
|
||||
vim.fn.getchar = getchar
|
||||
vim.fn.getcharstr = getcharstr
|
||||
vim.fn.inputlist = inputlist
|
||||
-- vim.fn.confirm = confirm
|
||||
end)
|
||||
end
|
||||
|
||||
-- Fixes cmp cmdline position
|
||||
function M.fix_cmp()
|
||||
M.on_module("cmp.utils.api", function(api)
|
||||
@ -242,19 +136,8 @@ function M.fix_cmp()
|
||||
end)
|
||||
end
|
||||
|
||||
function M.fix_cmdpreview()
|
||||
vim.api.nvim_create_autocmd("CmdlineChanged", {
|
||||
group = M.group,
|
||||
callback = function()
|
||||
local ffi = require("noice.util.ffi")
|
||||
ffi.cmdpreview = false
|
||||
vim.cmd([[redraw]])
|
||||
Util.try(require("noice.message.router").update)
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
M.SPECIAL = "Þ"
|
||||
---@deprecated
|
||||
function M.cmdline_force_redraw()
|
||||
if vim.fn.has("nvim-0.11") == 1 then
|
||||
-- no longer needed on nightly
|
||||
@ -270,6 +153,7 @@ end
|
||||
|
||||
---@type string?
|
||||
M._guicursor = nil
|
||||
---@deprecated
|
||||
function M.hide_cursor()
|
||||
if M._guicursor == nil then
|
||||
M._guicursor = vim.go.guicursor
|
||||
@ -283,6 +167,7 @@ function M.hide_cursor()
|
||||
M._disable.guicursor = M.show_cursor
|
||||
end
|
||||
|
||||
---@deprecated
|
||||
function M.show_cursor()
|
||||
if M._guicursor then
|
||||
if not Util.is_exiting() then
|
||||
@ -299,22 +184,18 @@ function M.show_cursor()
|
||||
end
|
||||
end
|
||||
|
||||
---@param modname string
|
||||
---@param fn fun(mod)
|
||||
function M.on_module(module, fn)
|
||||
if package.loaded[module] then
|
||||
return fn(package.loaded[module])
|
||||
function M.on_module(modname, fn)
|
||||
if type(package.loaded[modname]) == "table" then
|
||||
return fn(package.loaded[modname])
|
||||
end
|
||||
|
||||
package.preload[module] = function()
|
||||
package.preload[module] = nil
|
||||
for _, loader in pairs(package.loaders) do
|
||||
local ret = loader(module)
|
||||
if type(ret) == "function" then
|
||||
local mod = ret()
|
||||
fn(mod)
|
||||
return mod
|
||||
end
|
||||
end
|
||||
package.preload[modname] = function()
|
||||
package.preload[modname] = nil
|
||||
package.loaded[modname] = nil
|
||||
local mod = require(modname)
|
||||
fn(mod)
|
||||
return mod
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
local require = require("noice.util.lazy")
|
||||
|
||||
local Hacks = require("noice.util.hacks")
|
||||
local Config = require("noice.config")
|
||||
local Hacks = require("noice.util.hacks")
|
||||
|
||||
local M = {}
|
||||
|
||||
@ -244,8 +244,6 @@ function M.is_blocking(opts)
|
||||
|
||||
local reason = opts.blocking and mode.blocking and "blocking"
|
||||
or opts.mode and blocking_mode and ("mode:" .. mode.mode)
|
||||
or opts.input and Hacks.before_input and "input"
|
||||
or opts.redraw and Hacks.inside_redraw and "redraw"
|
||||
or #require("noice.ui.cmdline").cmdlines > 0 and "cmdline"
|
||||
or nil
|
||||
return reason ~= nil, reason
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
local require = require("noice.util.lazy")
|
||||
|
||||
local View = require("noice.view")
|
||||
local NuiView = require("noice.view.nui")
|
||||
local Util = require("noice.util")
|
||||
local View = require("noice.view")
|
||||
|
||||
---@class NoiceMiniOptions
|
||||
---@field timeout integer
|
||||
@ -13,7 +13,7 @@ local defaults = { timeout = 5000 }
|
||||
---@field active table<number, NoiceMessage>
|
||||
---@field super NoiceView
|
||||
---@field view? NuiView
|
||||
---@field timers table<number, vim.loop.Timer>
|
||||
---@field timers table<number, uv_timer_t>
|
||||
---@diagnostic disable-next-line: undefined-field
|
||||
local MiniView = View:extend("MiniView")
|
||||
|
||||
@ -26,11 +26,12 @@ function MiniView:init(opts)
|
||||
view_opts.type = "popup"
|
||||
view_opts.format = { "{message}" }
|
||||
view_opts.timeout = nil
|
||||
view_opts.scrollbar = false
|
||||
self.view = NuiView(view_opts)
|
||||
end
|
||||
|
||||
function MiniView:update_options()
|
||||
self._opts = vim.tbl_deep_extend("force", defaults, self._opts)
|
||||
self._opts = vim.tbl_deep_extend("force", defaults, self._opts) --[[@as NoiceViewOptions]]
|
||||
if self.view then
|
||||
self.view:update_options()
|
||||
end
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
local require = require("noice.util.lazy")
|
||||
|
||||
local Util = require("noice.util")
|
||||
local View = require("noice.view")
|
||||
local Manager = require("noice.message.manager")
|
||||
local NuiText = require("nui.text")
|
||||
local Util = require("noice.util")
|
||||
local View = require("noice.view")
|
||||
|
||||
---@class NoiceNotifyOptions
|
||||
---@field title string
|
||||
@ -126,7 +126,6 @@ function NotifyView:_notify(msg)
|
||||
|
||||
local opts = {
|
||||
title = msg.title or self._opts.title,
|
||||
animate = not Util.is_blocking(),
|
||||
timeout = self._opts.timeout,
|
||||
replace = self._opts.replace and self.notif,
|
||||
keep = function()
|
||||
|
||||
@ -2,9 +2,10 @@ local require = require("noice.util.lazy")
|
||||
|
||||
local Config = require("noice.config")
|
||||
local ConfigViews = require("noice.config.views")
|
||||
local Util = require("noice.util")
|
||||
local Object = require("nui.object")
|
||||
local Format = require("noice.text.format")
|
||||
local Message = require("noice.message")
|
||||
local Object = require("nui.object")
|
||||
local Util = require("noice.util")
|
||||
|
||||
---@class NoiceViewBaseOptions
|
||||
---@field buf_options? table<string,any>
|
||||
@ -255,7 +256,7 @@ function View:render(buf, opts)
|
||||
end
|
||||
|
||||
vim.api.nvim_buf_clear_namespace(buf, Config.ns, linenr - 1, -1)
|
||||
vim.b[buf].messages = {}
|
||||
Message._buf_messages[buf] = {}
|
||||
|
||||
---@type number?
|
||||
local win = vim.fn.bufwinid(buf)
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
local require = require("noice.util.lazy")
|
||||
|
||||
local View = require("noice.view")
|
||||
local Util = require("noice.util")
|
||||
local Scrollbar = require("noice.view.scrollbar")
|
||||
local Util = require("noice.util")
|
||||
local View = require("noice.view")
|
||||
|
||||
local uv = vim.uv or vim.loop
|
||||
|
||||
@ -290,8 +290,11 @@ function NuiView:show()
|
||||
end
|
||||
|
||||
if self._scroll then
|
||||
self._scroll.winnr = self._nui.winid
|
||||
self._scroll:show()
|
||||
if self._scroll.winnr ~= self._nui.winid then
|
||||
self._scroll.winnr = self._nui.winid
|
||||
self._scroll:mount()
|
||||
end
|
||||
self._scroll:update()
|
||||
end
|
||||
self:fix_border()
|
||||
self:autohide()
|
||||
|
||||
@ -39,7 +39,12 @@ function Scrollbar:init(opts)
|
||||
end
|
||||
|
||||
function Scrollbar:mount()
|
||||
self.autocmd_id = vim.api.nvim_create_autocmd({ "WinScrolled", "CursorMoved" }, {
|
||||
if self.autocmd_id then
|
||||
vim.api.nvim_del_autocmd(self.autocmd_id)
|
||||
self.autocmd_id = nil
|
||||
end
|
||||
self.autocmd_id = vim.api.nvim_create_autocmd("WinScrolled", {
|
||||
pattern = tostring(self.winnr),
|
||||
callback = function()
|
||||
self:update()
|
||||
end,
|
||||
@ -158,7 +163,7 @@ function Scrollbar:_open_win(opts)
|
||||
noautocmd = true,
|
||||
}),
|
||||
}
|
||||
vim.api.nvim_win_set_option(ret.winnr, "winhighlight", "Normal:" .. opts.normal)
|
||||
vim.api.nvim_set_option_value("winhighlight", "Normal:" .. opts.normal, { win = ret.winnr })
|
||||
return ret
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user