1

Refresh generated neovim config

This commit is contained in:
2024-07-14 21:12:36 +02:00
parent f215ce2ab5
commit 00464e0e65
731 changed files with 6780 additions and 31110 deletions

View File

@ -58,6 +58,18 @@ function M.setup()
telescope = function()
require("telescope").extensions.noice.noice({})
end,
fzf = function()
require("noice.integrations.fzf").open({})
end,
pick = function()
if pcall(_G.require, "telescope.config") then
require("telescope").extensions.noice.noice({})
elseif pcall(_G.require, "fzf-lua") then
require("noice.integrations.fzf").open({})
else
Util.error("No picker available")
end
end,
stats = function()
Manager.add(Util.stats.message())
end,

View File

@ -20,9 +20,13 @@ function M.setup()
local hl_group_border = "CmdlinePopupBorder" .. kind_cc
Highlights.add(hl_group_border, "NoiceCmdlinePopupBorder")
local hl_group_title = "CmdlinePopupTitle" .. kind_cc
Highlights.add(hl_group_title, "Noice" .. hl_group_border)
format = vim.tbl_deep_extend("force", {
name = name,
conceal = format.conceal ~= false,
kind = kind,
kind = name,
icon_hl_group = "Noice" .. hl_group_icon,
view = Config.options.cmdline.view,
lang = format.lang or format.ft,
@ -36,6 +40,7 @@ function M.setup()
win_options = {
winhighlight = {
FloatBorder = "Noice" .. hl_group_border,
FloatTitle = "Noice" .. hl_group_title,
},
},
},
@ -45,7 +50,7 @@ function M.setup()
table.insert(Config.options.routes, {
view = format.view,
opts = format.opts,
filter = { event = "cmdline", kind = format.kind },
filter = { event = "cmdline", kind = name },
})
end
end

View File

@ -30,6 +30,22 @@ M.builtin = {
"\n",
"{message}",
},
fzf = {
"{level} ",
"{date} ",
"{title} ",
"{message}",
},
fzf_preview = {
"{level} ",
"{date} ",
"{event}",
{ "{kind}", before = { ".", hl_group = "NoiceFormatKind" } },
"\n",
"{title}\n",
"\n",
"{message}",
},
lsp_progress = {
{
"{progress} ",

View File

@ -1,3 +1,4 @@
---@diagnostic disable: missing-fields
local require = require("noice.util.lazy")
local Routes = require("noice.config.routes")
@ -27,7 +28,7 @@ function M.defaults()
lua = { pattern = { "^:%s*lua%s+", "^:%s*lua%s*=%s*", "^:%s*=%s*" }, icon = "", lang = "lua" },
help = { pattern = "^:%s*he?l?p?%s+", icon = "" },
calculator = { pattern = "^=", icon = "", lang = "vimnormal" },
input = {}, -- Used by input()
input = { view = "cmdline_input", icon = "󰥻 " }, -- Used by input()
-- lua = false, -- to disable a format, set to `false`
},
},
@ -186,12 +187,6 @@ function M.defaults()
health = {
checker = true, -- Disable if you don't want health checks to run
},
smart_move = {
-- noice tries to move out of the way of existing floating windows.
enabled = true, -- you can disable this behaviour here
-- add any filetypes here, that shouldn't trigger smart move.
excluded_filetypes = { "cmp_menu", "cmp_docs", "notify" },
},
---@type NoicePresets
presets = {
-- you can enable a preset by setting it to true, or a table that will override the preset config

View File

@ -225,6 +225,13 @@ M.defaults = {
cursorline = false,
},
},
cmdline_input = {
view = "cmdline_popup",
border = {
style = "rounded",
padding = { 0, 1 },
},
},
confirm = {
backend = "popup",
relative = "editor",

View File

@ -53,6 +53,14 @@ function M.cmd(name)
end
function M.enable()
vim.api.nvim_create_autocmd("VimLeavePre", {
group = vim.api.nvim_create_augroup("NoiceVimLeavePre", { clear = true }),
callback = function()
if Config.is_running() then
pcall(M.disable)
end
end,
})
Config._running = true
if Config.options.notify.enabled then
require("noice.source.notify").enable()

View File

@ -29,12 +29,8 @@ function M.format_markdown(contents)
table.insert(parts, ("```\n%s\n```"):format(content.value))
elseif Util.islist(content) then
vim.list_extend(parts, M.format_markdown(content))
elseif type(content) == "table" and next(content) == nil then
goto continue
else
error("Unknown markup " .. vim.inspect(content))
end
::continue::
-- ignore other types of content (invalid content)
end
return vim.split(table.concat(parts, "\n"), "\n")

View File

@ -9,6 +9,7 @@ local _id = 0
---@field super NoiceBlock
---@field id number
---@field event NoiceEvent
---@field title? string
---@field ctime number
---@field mtime number
---@field tick number

View File

@ -109,9 +109,13 @@ end
function M.check_redraw()
if Util.is_blocking() and M._need_redraw then
-- NOTE: set to false before actually calling redraw to prevent a loop with ui
M._need_redraw = false
Util.redraw()
-- 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

View File

@ -17,6 +17,7 @@ local Markdown = require("noice.text.markdown")
---@class NoiceText: NuiText
---@field super NuiText
---@field enabled? boolean
---@field on_render? fun(text: NoiceText, buf:number, line: number, byte:number, col:number)
---@overload fun(content:string, highlight?:string|NoiceExtmark):NoiceText
---@diagnostic disable-next-line: undefined-field
@ -111,7 +112,9 @@ function NoiceText:highlight(bufnr, ns_id, linenr, byte_start)
extmark.col = nil
end
NoiceText.super.highlight(self, bufnr, ns_id, linenr, byte_start)
if self.enabled ~= false then
NoiceText.super.highlight(self, bufnr, ns_id, linenr, byte_start)
end
if self.on_render then
self.on_render(self, bufnr, linenr, byte_start_orig, col_start)

View File

@ -24,6 +24,7 @@ M.events = {
---@type NoiceCmdline?
M.active = nil
M.real_cursor = vim.api.nvim__redraw ~= nil
---@alias NoiceCmdlineFormatter fun(cmdline: NoiceCmdline): {icon?:string, offset?:number, view?:NoiceViewOptions}
@ -37,6 +38,7 @@ M.active = nil
---@field block table
---@class CmdlineFormat
---@field name string
---@field kind string
---@field pattern? string|string[]
---@field view string
@ -112,19 +114,28 @@ end
function Cmdline:format(message, text_only)
local format = self:get_format()
message.fix_cr = false
message.title = nil
if format.icon then
local use_input = self.state.prompt ~= ""
and format.view == "cmdline_input"
and #self.state.prompt <= 60
and not self.state.prompt:find("\n")
if format.icon and (format.name ~= "input" or use_input) then
message:append(NoiceText.virtual_text(format.icon, format.icon_hl_group))
message:append(" ")
end
if not text_only then
message.kind = format.kind
message.kind = format.name
end
-- FIXME: prompt
if self.state.prompt ~= "" then
message:append(self.state.prompt, "NoiceCmdlinePrompt")
if use_input then
message.title = " " .. self.state.prompt:gsub("%s*:%s*$", "") .. " "
else
message:append(self.state.prompt, "NoiceCmdlinePrompt")
end
end
if not format.conceal then
@ -142,6 +153,7 @@ function Cmdline:format(message, text_only)
if not text_only then
local cursor = NoiceText.cursor(-self:length() + self.state.pos)
cursor.on_render = M.on_render
cursor.enabled = not M.real_cursor
message:append(cursor)
end
end
@ -211,10 +223,35 @@ end
---@class CmdlinePosition
---@field win number Window containing the cmdline
---@field buf number Buffer containing the cmdline
---@field cursor number
---@field bufpos {row:number, col:number} (1-0)-indexed position of the cmdline in the buffer
---@field screenpos {row:number, col:number} (1-0)-indexed screen position of the cmdline
M.position = nil
function M.fix_cursor()
if not M.position 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 })
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
end
---@param buf number
---@param line number
---@param byte number
@ -227,19 +264,10 @@ function M.on_render(_, buf, line, byte)
local cmdline_start = byte - (M.last():length() - M.last().offset)
local cursor = byte - M.last():length() + M.last().state.pos
vim.schedule(function()
if vim.api.nvim_win_is_valid(win) then
vim.api.nvim_win_set_cursor(win, { 1, cursor })
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)
end
end)
local pos = vim.fn.screenpos(win, line, cmdline_start)
M.position = {
cursor = cursor,
buf = buf,
win = win,
bufpos = {
@ -251,6 +279,7 @@ function M.on_render(_, buf, line, byte)
col = pos.col - 1,
},
}
pcall(M.fix_cursor)
end
end
@ -265,11 +294,15 @@ function M.update()
if cmdline then
cmdline:format(M.message)
Hacks.hide_cursor()
if not M.real_cursor then
Hacks.hide_cursor()
end
Manager.add(M.message)
else
Manager.remove(M.message)
Hacks.show_cursor()
if not M.real_cursor then
Hacks.show_cursor()
end
end
end

View File

@ -153,6 +153,10 @@ function M.on_confirm(event, kind, content)
if State.skip(event, kind, content) then
return
end
local prev = Manager.get({ event = event, kind = kind }, { history = true })[1]
if prev then
Manager.remove(prev)
end
local message = Message(event, kind, content)
if not message:content():find("%s+$") then
message:append(" ")

View File

@ -256,6 +256,10 @@ end
M.SPECIAL = "Þ"
function M.cmdline_force_redraw()
if vim.fn.has("nvim-0.11") == 1 then
-- no longer needed on nightly
return
end
if not require("noice.util.ffi").cmdpreview then
return
end

View File

@ -217,6 +217,14 @@ function M._diff(a, b)
return false
end
function M.is_search()
local cmdline = require("noice.ui.cmdline")
local c = cmdline.active
if c and (c.state.firstc == "/" or c.state.firstc == "?") then
return true
end
end
---@param opts? {blocking:boolean, mode:boolean, input:boolean, redraw:boolean}
function M.is_blocking(opts)
opts = vim.tbl_deep_extend("force", {

View File

@ -236,17 +236,17 @@ function M.anchor(width, height)
end
function M.scroll(win, delta)
local info = vim.fn.getwininfo(win)[1] or {}
local top = info.topline or 1
local buf = vim.api.nvim_win_get_buf(win)
Util.wo(win, { scrolloff = 0 })
local view = vim.api.nvim_win_call(win, vim.fn.winsaveview)
local height = vim.api.nvim_win_get_height(win)
local top = view.topline
top = top + delta
top = math.max(top, 1)
top = math.min(top, M.win_buf_height(win) - info.height + 1)
top = math.min(top, M.win_buf_height(win) - height + 1)
vim.defer_fn(function()
vim.api.nvim_buf_call(buf, function()
vim.api.nvim_command("noautocmd silent! normal! " .. top .. "zt")
vim.api.nvim_exec_autocmds("WinScrolled", { modeline = false })
vim.api.nvim_win_call(win, function()
vim.fn.winrestview({ topline = top, lnum = top })
end)
end, 0)
end

View File

@ -31,6 +31,9 @@ end
function MiniView:update_options()
self._opts = vim.tbl_deep_extend("force", defaults, self._opts)
if self.view then
self.view:update_options()
end
end
---@param message NoiceMessage

View File

@ -3,21 +3,22 @@ local require = require("noice.util.lazy")
local View = require("noice.view")
local Util = require("noice.util")
local Scrollbar = require("noice.view.scrollbar")
local Config = require("noice.config")
local uv = vim.uv or vim.loop
---@class NuiView: NoiceView
---@field _nui? NuiPopup|NuiSplit
---@field _loading? boolean
---@field super NoiceView
---@field _hider fun()
---@field _timeout_timer vim.loop.Timer
---@field _timeout_timer uv_timer_t
---@field _scroll NoiceScrollbar
---@diagnostic disable-next-line: undefined-field
local NuiView = View:extend("NuiView")
function NuiView:init(opts)
NuiView.super.init(self, opts)
self._timer = vim.loop.new_timer()
self._timer = uv.new_timer()
end
function NuiView:autohide()
@ -47,7 +48,19 @@ function NuiView:update_options()
},
}, self._opts, self:get_layout())
local title = {} ---@type string[]
for _, m in ipairs(self._messages) do
if m.title then
title[#title + 1] = m.title
end
end
self._opts = Util.nui.normalize(self._opts)
if #title > 0 then
self._opts.border = self._opts.border or {}
self._opts.border.text = self._opts.border.text or {}
self._opts.border.text.top = table.concat(title, " | ")
end
if self._opts.anchor == "auto" then
if self._opts.type == "popup" and self._opts.size then
local width = self._opts.size.width
@ -69,55 +82,6 @@ function NuiView:update_options()
end
end
-- Check if other floating windows are overlapping and move out of the way
function NuiView:smart_move()
if not Config.options.smart_move.enabled then
return
end
if not (self._opts.type == "popup" and self._opts.relative and self._opts.relative.type == "editor") then
return
end
if not (self._nui.winid and vim.api.nvim_win_is_valid(self._nui.winid)) then
return
end
if not (self._nui.border.winid and vim.api.nvim_win_is_valid(self._nui.border.winid)) then
return
end
local nui_win = self._nui.border._.type == "complex" and self._nui.border.winid or self._nui.winid
local wins = vim.tbl_filter(function(win)
local ft = vim.bo[vim.api.nvim_win_get_buf(win)].filetype
return win ~= self._nui.winid
and ft ~= "noice"
and not vim.tbl_contains(Config.options.smart_move.excluded_filetypes, ft)
and not (self._nui.border and self._nui.border.winid == win)
and vim.api.nvim_win_is_valid(win)
and vim.api.nvim_win_get_config(win).relative == "editor"
and Util.nui.overlap(nui_win, win) > 0.3
end, vim.api.nvim_list_wins())
if #wins > 0 then
-- local info = vim.tbl_map(function(win)
-- local buf = vim.api.nvim_win_get_buf(win)
-- return {
-- win = win,
-- buftype = vim.bo[buf].buftype,
-- ft = vim.bo[buf].filetype,
-- syntax = vim.bo[buf].syntax,
-- text = table.concat(vim.api.nvim_buf_get_lines(buf, 0, -1, false), "\n"),
-- name = vim.api.nvim_buf_get_name(buf),
-- -- config = vim.api.nvim_win_get_config(win),
-- area = Util.nui.overlap(nui_win, win),
-- }
-- end, wins)
-- dumpp(info)
local layout = self:get_layout()
layout.position.row = 2
self._nui:update_layout(layout)
end
end
function NuiView:create()
if self._loading then
return
@ -323,7 +287,6 @@ function NuiView:show()
if not self._visible then
self:set_win_options(self._nui.winid)
self:update_layout()
self:smart_move()
end
if self._scroll then

View File

@ -124,7 +124,9 @@ function Scrollbar:update()
local thumb_height = math.floor(dim.height * dim.height / buf_height + 0.5)
thumb_height = math.max(1, thumb_height)
local pct = vim.api.nvim_win_get_cursor(self.winnr)[1] / buf_height
local view = vim.api.nvim_win_call(self.winnr, vim.fn.winsaveview)
local pct = math.min(view.topline / (buf_height - dim.height + 1), 1)
local thumb_offset = math.floor(pct * (dim.height - thumb_height) + 0.5)

View File

@ -7,6 +7,8 @@ local pickers = require("telescope.pickers")
local finders = require("telescope.finders")
local conf = require("telescope.config").values
local previewers = require("telescope.previewers")
local actions = require("telescope.actions")
local action_state = require("telescope.actions.state")
local M = {}
@ -59,6 +61,45 @@ function M.previewer()
})
end
function M.mappings()
return function(prompt_bufnr, map)
actions.select_default:replace(function()
actions.close(prompt_bufnr)
local selection = action_state.get_selected_entry()
if selection == nil then return end
local buf = vim.api.nvim_create_buf(false, true)
vim.api.nvim_buf_set_keymap(buf, 'n', 'q', ':q<CR>', { silent = true })
local message = Format.format(selection.message, "telescope_preview")
message:render(buf, Config.ns)
local lines = vim.opt.lines:get()
local cols = vim.opt.columns:get()
local width = math.ceil(cols * 0.8)
local height = math.ceil(lines * 0.8 - 4)
local left = math.ceil((cols - width) * 0.5)
local top = math.ceil((lines - height) * 0.5)
local win = vim.api.nvim_open_win(buf, true, {
relative = "editor",
style = "minimal",
width = width,
height = height,
col = left,
row = top,
border = "rounded",
})
vim.api.nvim_win_set_option(win, "wrap", true)
vim.api.nvim_buf_set_option(buf, 'modifiable', false)
end)
return true
end
end
function M.telescope(opts)
pickers
.new(opts, {
@ -67,6 +108,7 @@ function M.telescope(opts)
finder = M.finder(),
sorter = conf.generic_sorter(opts),
previewer = M.previewer(),
attach_mappings = M.mappings(),
})
:find()
end