feat: allow custom input provider, removing dressing.nvim (#2173)
Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Co-authored-by: yetone <yetoneful@gmail.com>
This commit is contained in:
@@ -3,13 +3,6 @@ local api, fn = vim.api, vim.fn
|
||||
local Config = require("avante.config")
|
||||
local Utils = require("avante.utils")
|
||||
|
||||
local DressingConfig = {
|
||||
conceal_char = "*",
|
||||
filetype = "DressingInput",
|
||||
close_window = function() require("dressing.input").close() end,
|
||||
}
|
||||
local DressingState = { winid = nil, input_winid = nil, input_bufnr = nil }
|
||||
|
||||
---@class avante.Providers
|
||||
---@field openai AvanteProviderFunctor
|
||||
---@field claude AvanteProviderFunctor
|
||||
@@ -78,7 +71,7 @@ function E.setup(opts)
|
||||
end
|
||||
end
|
||||
|
||||
local function mount_dressing_buffer()
|
||||
local function mount_input_ui()
|
||||
vim.defer_fn(function()
|
||||
-- only mount if given buffer is not of buftype ministarter, dashboard, alpha, qf
|
||||
local exclude_filetypes = {
|
||||
@@ -93,46 +86,30 @@ function E.setup(opts)
|
||||
"gitcommit",
|
||||
"gitrebase",
|
||||
"DressingInput",
|
||||
"snacks_input",
|
||||
"noice",
|
||||
}
|
||||
|
||||
if not vim.tbl_contains(exclude_filetypes, vim.bo.filetype) and not opts.provider.is_env_set() then
|
||||
DressingState.winid = api.nvim_get_current_win()
|
||||
vim.ui.input({ default = "", prompt = "Enter " .. var .. ": " }, on_confirm)
|
||||
for _, winid in ipairs(api.nvim_list_wins()) do
|
||||
local bufnr = api.nvim_win_get_buf(winid)
|
||||
if vim.bo[bufnr].filetype == DressingConfig.filetype then
|
||||
DressingState.input_winid = winid
|
||||
DressingState.input_bufnr = bufnr
|
||||
vim.wo[winid].conceallevel = 2
|
||||
vim.wo[winid].concealcursor = "nvi"
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
local prompt_length = api.nvim_strwidth(fn.prompt_getprompt(DressingState.input_bufnr))
|
||||
api.nvim_buf_call(
|
||||
DressingState.input_bufnr,
|
||||
function()
|
||||
vim.cmd(string.format(
|
||||
[[
|
||||
syn region SecretValue start=/^/ms=s+%s end=/$/ contains=SecretChar
|
||||
syn match SecretChar /./ contained conceal %s
|
||||
]],
|
||||
prompt_length,
|
||||
"cchar=*"
|
||||
))
|
||||
end
|
||||
)
|
||||
local Input = require("avante.ui.input")
|
||||
local input = Input:new({
|
||||
provider = Config.input.provider,
|
||||
title = "Enter " .. var .. ": ",
|
||||
default = "",
|
||||
conceal = true, -- Password input should be concealed
|
||||
provider_opts = Config.input.provider_opts,
|
||||
on_submit = on_confirm,
|
||||
})
|
||||
input:open()
|
||||
end
|
||||
end, 200)
|
||||
end
|
||||
|
||||
if refresh then return mount_dressing_buffer() end
|
||||
if refresh then return mount_input_ui() end
|
||||
|
||||
api.nvim_create_autocmd("User", {
|
||||
pattern = E.REQUEST_LOGIN_PATTERN,
|
||||
callback = mount_dressing_buffer,
|
||||
callback = mount_input_ui,
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user