update
This commit is contained in:
@@ -61,9 +61,9 @@ vim.cmd([[
|
||||
-- }}}
|
||||
|
||||
-- {{{ Code companion hook
|
||||
local group = vim.api.nvim_create_augroup("CodeCompanionHooks", {})
|
||||
local group = augroup("CodeCompanionHooks", {})
|
||||
|
||||
vim.api.nvim_create_autocmd({ "User" }, {
|
||||
autocmd({ "User" }, {
|
||||
pattern = "CodeCompanionInline*",
|
||||
group = group,
|
||||
callback = function(request)
|
||||
|
||||
@@ -214,8 +214,8 @@ local code_companion_mappings = {
|
||||
{
|
||||
mode = "v",
|
||||
key = "<leader>Ci",
|
||||
cmd = ":CodeCompanion /buffer ",
|
||||
group = "CodeCompanion /buffer",
|
||||
cmd = ":CodeCompanion #buffer ",
|
||||
group = "CodeCompanion #buffer",
|
||||
opts = nosilent,
|
||||
},
|
||||
{ mode = "v", key = "<leader>Ce", cmd = ":CodeCompanion /explain<CR>", group = "CodeCompanion /explain" },
|
||||
|
||||
126
lua/plugins/codecompanion/fidget-spinner-notify.lua
Normal file
126
lua/plugins/codecompanion/fidget-spinner-notify.lua
Normal file
@@ -0,0 +1,126 @@
|
||||
local notify = require("notify")
|
||||
local spinner_frames = { "⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏" }
|
||||
local spinner_len = #spinner_frames -- cache spinner length
|
||||
local M = {}
|
||||
local timeout = 2999
|
||||
|
||||
-- Helper function to safely call notify
|
||||
local function safe_notify(msg, level, opts)
|
||||
local ok, res = pcall(notify, msg, level, opts)
|
||||
return ok, res
|
||||
end
|
||||
|
||||
function M:init()
|
||||
local group = vim.api.nvim_create_augroup("CodeCompanionFidgetHooks", {})
|
||||
|
||||
vim.api.nvim_create_autocmd({ "User" }, {
|
||||
pattern = "CodeCompanionRequestStarted",
|
||||
group = group,
|
||||
callback = function(request)
|
||||
local handle = M:create_progress_handle(request)
|
||||
M:store_progress_handle(request.data.id, handle)
|
||||
end,
|
||||
})
|
||||
|
||||
vim.api.nvim_create_autocmd({ "User" }, {
|
||||
pattern = "CodeCompanionRequestFinished",
|
||||
group = group,
|
||||
callback = function(request)
|
||||
local handle = M:pop_progress_handle(request.data.id)
|
||||
if handle then
|
||||
M:report_exit_status(handle, request)
|
||||
handle:finish()
|
||||
end
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
M.handles = {}
|
||||
|
||||
function M:store_progress_handle(id, handle)
|
||||
M.handles[id] = handle
|
||||
end
|
||||
|
||||
function M:pop_progress_handle(id)
|
||||
local handle = M.handles[id]
|
||||
M.handles[id] = nil
|
||||
return handle
|
||||
end
|
||||
|
||||
function M:create_progress_handle(request)
|
||||
local title = " Requesting assistance"
|
||||
.. " ("
|
||||
.. request.data.strategy
|
||||
.. ") from "
|
||||
.. request.data.adapter.formatted_name
|
||||
.. " using "
|
||||
.. request.data.adapter.model
|
||||
local idx = 1
|
||||
local start_time = os.time()
|
||||
local notification_id =
|
||||
notify(spinner_frames[idx] .. " In progress (" .. "0s" .. ")...", "info", { title = title, timeout = false })
|
||||
local handle = { notification_id = notification_id, title = title, finished = false }
|
||||
local timer = vim.loop.new_timer()
|
||||
timer:start(
|
||||
0,
|
||||
100,
|
||||
vim.schedule_wrap(function()
|
||||
if handle.finished then
|
||||
return
|
||||
end -- stop updating if finished
|
||||
idx = idx % spinner_len + 1
|
||||
local elapsed = os.difftime(os.time(), start_time)
|
||||
local opts = { replace = handle.notification_id, title = title, timeout = false }
|
||||
local ok, new_id = safe_notify(spinner_frames[idx] .. " In progress (" .. elapsed .. "s)...", "info", opts)
|
||||
if ok then
|
||||
handle.notification_id = new_id
|
||||
else
|
||||
handle.notification_id = notify(
|
||||
spinner_frames[idx] .. " In progress (" .. elapsed .. "s)...",
|
||||
"info",
|
||||
{ title = title, timeout = false }
|
||||
)
|
||||
end
|
||||
end)
|
||||
)
|
||||
handle.timer = timer
|
||||
handle.finish = function()
|
||||
handle.finished = true -- mark as finished to abort future updates
|
||||
if handle.timer then
|
||||
handle.timer:stop()
|
||||
handle.timer:close()
|
||||
handle.timer = nil
|
||||
end
|
||||
end
|
||||
return handle
|
||||
end
|
||||
|
||||
function M:report_exit_status(handle, request)
|
||||
local title = handle.title
|
||||
or (
|
||||
" Requesting assistance"
|
||||
.. " ("
|
||||
.. request.data.strategy
|
||||
.. ") from "
|
||||
.. request.data.adapter.formatted_name
|
||||
.. " using "
|
||||
.. request.data.adapter.model
|
||||
)
|
||||
local function report(msg, level)
|
||||
local opts = { replace = handle.notification_id, title = title, timeout = timeout }
|
||||
local ok = safe_notify(msg, level, opts)
|
||||
if not ok then
|
||||
notify(msg, level, { title = title, timeout = timeout })
|
||||
end
|
||||
end
|
||||
|
||||
if request.data.status == "success" then
|
||||
report("Completed", "info")
|
||||
elseif request.data.status == "error" then
|
||||
report(" Error", "error")
|
||||
else
|
||||
report(" Cancelled", "warn")
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -1,14 +1,8 @@
|
||||
local notify = require("notify")
|
||||
local spinner_frames = { "⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏" }
|
||||
local spinner_len = #spinner_frames -- cache spinner length
|
||||
local M = {}
|
||||
local timeout = 2999
|
||||
-- lua/plugins/codecompanion/fidget-spinner.lua
|
||||
|
||||
-- Helper function to safely call notify
|
||||
local function safe_notify(msg, level, opts)
|
||||
local ok, res = pcall(notify, msg, level, opts)
|
||||
return ok, res
|
||||
end
|
||||
local progress = require("fidget.progress")
|
||||
|
||||
local M = {}
|
||||
|
||||
function M:init()
|
||||
local group = vim.api.nvim_create_augroup("CodeCompanionFidgetHooks", {})
|
||||
@@ -48,78 +42,31 @@ function M:pop_progress_handle(id)
|
||||
end
|
||||
|
||||
function M:create_progress_handle(request)
|
||||
local title = " Requesting assistance"
|
||||
.. " ("
|
||||
.. request.data.strategy
|
||||
.. ") from "
|
||||
.. request.data.adapter.formatted_name
|
||||
.. " using "
|
||||
.. request.data.adapter.model
|
||||
local idx = 1
|
||||
local start_time = os.time()
|
||||
local notification_id =
|
||||
notify(spinner_frames[idx] .. " In progress (" .. "0s" .. ")...", "info", { title = title, timeout = false })
|
||||
local handle = { notification_id = notification_id, title = title, finished = false }
|
||||
local timer = vim.loop.new_timer()
|
||||
timer:start(
|
||||
0,
|
||||
100,
|
||||
vim.schedule_wrap(function()
|
||||
if handle.finished then
|
||||
return
|
||||
end -- stop updating if finished
|
||||
idx = idx % spinner_len + 1
|
||||
local elapsed = os.difftime(os.time(), start_time)
|
||||
local opts = { replace = handle.notification_id, title = title, timeout = false }
|
||||
local ok, new_id = safe_notify(spinner_frames[idx] .. " In progress (" .. elapsed .. "s)...", "info", opts)
|
||||
if ok then
|
||||
handle.notification_id = new_id
|
||||
else
|
||||
handle.notification_id = notify(
|
||||
spinner_frames[idx] .. " In progress (" .. elapsed .. "s)...",
|
||||
"info",
|
||||
{ title = title, timeout = false }
|
||||
)
|
||||
end
|
||||
end)
|
||||
)
|
||||
handle.timer = timer
|
||||
handle.finish = function()
|
||||
handle.finished = true -- mark as finished to abort future updates
|
||||
if handle.timer then
|
||||
handle.timer:stop()
|
||||
handle.timer:close()
|
||||
handle.timer = nil
|
||||
end
|
||||
return progress.handle.create({
|
||||
title = " Requesting assistance (" .. request.data.strategy .. ")",
|
||||
message = "In progress...",
|
||||
lsp_client = {
|
||||
name = M:llm_role_title(request.data.adapter),
|
||||
},
|
||||
})
|
||||
end
|
||||
|
||||
function M:llm_role_title(adapter)
|
||||
local parts = {}
|
||||
table.insert(parts, adapter.formatted_name)
|
||||
if adapter.model and adapter.model ~= "" then
|
||||
table.insert(parts, "(" .. adapter.model .. ")")
|
||||
end
|
||||
return handle
|
||||
return table.concat(parts, " ")
|
||||
end
|
||||
|
||||
function M:report_exit_status(handle, request)
|
||||
local title = handle.title
|
||||
or (
|
||||
" Requesting assistance"
|
||||
.. " ("
|
||||
.. request.data.strategy
|
||||
.. ") from "
|
||||
.. request.data.adapter.formatted_name
|
||||
.. " using "
|
||||
.. request.data.adapter.model
|
||||
)
|
||||
local function report(msg, level)
|
||||
local opts = { replace = handle.notification_id, title = title, timeout = timeout }
|
||||
local ok = safe_notify(msg, level, opts)
|
||||
if not ok then
|
||||
notify(msg, level, { title = title, timeout = timeout })
|
||||
end
|
||||
end
|
||||
|
||||
if request.data.status == "success" then
|
||||
report("Completed", "info")
|
||||
handle.message = "Completed"
|
||||
elseif request.data.status == "error" then
|
||||
report(" Error", "error")
|
||||
handle.message = " Error"
|
||||
else
|
||||
report(" Cancelled", "warn")
|
||||
handle.message = " Cancelled"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
4
lua/plugins/conform.lua
Normal file
4
lua/plugins/conform.lua
Normal file
@@ -0,0 +1,4 @@
|
||||
return {
|
||||
"stevearc/conform.nvim",
|
||||
opts = {},
|
||||
}
|
||||
@@ -1,54 +1,6 @@
|
||||
return {
|
||||
"nvim-lualine/lualine.nvim",
|
||||
config = function()
|
||||
local M = require("lualine.component"):extend()
|
||||
|
||||
M.processing = false
|
||||
M.spinner_index = 1
|
||||
|
||||
local spinner_symbols = {
|
||||
"⠋",
|
||||
"⠙",
|
||||
"⠹",
|
||||
"⠸",
|
||||
"⠼",
|
||||
"⠴",
|
||||
"⠦",
|
||||
"⠧",
|
||||
"⠇",
|
||||
"⠏",
|
||||
}
|
||||
local spinner_symbols_len = 10
|
||||
|
||||
-- Initializer
|
||||
function M:init(options)
|
||||
M.super.init(self, options)
|
||||
|
||||
local group = vim.api.nvim_create_augroup("CodeCompanionHooks", {})
|
||||
|
||||
vim.api.nvim_create_autocmd({ "User" }, {
|
||||
pattern = "CodeCompanionRequest*",
|
||||
group = group,
|
||||
callback = function(request)
|
||||
if request.match == "CodeCompanionRequestStarted" then
|
||||
self.processing = true
|
||||
elseif request.match == "CodeCompanionRequestFinished" then
|
||||
self.processing = false
|
||||
end
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
-- Function that runs every time statusline is updated
|
||||
function M:update_status()
|
||||
if self.processing then
|
||||
self.spinner_index = (self.spinner_index % spinner_symbols_len) + 1
|
||||
return spinner_symbols[self.spinner_index]
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
require("lualine").setup({
|
||||
options = {
|
||||
icons_enabled = true,
|
||||
@@ -66,8 +18,8 @@ return {
|
||||
lualine_b = { "branch", "diff" },
|
||||
lualine_c = { "filename" },
|
||||
lualine_x = {
|
||||
M,
|
||||
{
|
||||
"seachcount",
|
||||
"copilot",
|
||||
symbols = {
|
||||
status = {
|
||||
@@ -130,7 +82,7 @@ return {
|
||||
lualine_z = {},
|
||||
},
|
||||
tabline = {},
|
||||
extensions = { "quickfix", "fzf", "nvim-tree", "symbols-outline", "fugitive" },
|
||||
extensions = { "quickfix", "fzf", "nvim-tree", "symbols-outline", "fugitive", "toggleterm", "man" },
|
||||
})
|
||||
end,
|
||||
depends = { "kyazdani42/nvim-web-devicons" },
|
||||
|
||||
Reference in New Issue
Block a user