mirror of
https://github.com/ksyasuda/dotfiles.git
synced 2026-09-10 17:16:18 -07:00
update nvim
This commit is contained in:
@@ -1,126 +0,0 @@
|
||||
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.interaction
|
||||
.. ") 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,18 +1,16 @@
|
||||
-- lua/plugins/codecompanion/fidget-spinner.lua
|
||||
|
||||
local progress = require("fidget.progress")
|
||||
|
||||
local M = {}
|
||||
|
||||
function M:init()
|
||||
local group = vim.api.nvim_create_augroup("CodeCompanionFidgetHooks", {})
|
||||
function M.init()
|
||||
local group = vim.api.nvim_create_augroup("CodeCompanionFidgetHooks", { clear = true })
|
||||
|
||||
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)
|
||||
local handle = M.create_progress_handle(request)
|
||||
M.store_progress_handle(request.data.id, handle)
|
||||
end,
|
||||
})
|
||||
|
||||
@@ -20,9 +18,9 @@ function M:init()
|
||||
pattern = "CodeCompanionRequestFinished",
|
||||
group = group,
|
||||
callback = function(request)
|
||||
local handle = M:pop_progress_handle(request.data.id)
|
||||
local handle = M.pop_progress_handle(request.data.id)
|
||||
if handle then
|
||||
M:report_exit_status(handle, request)
|
||||
M.report_exit_status(handle, request)
|
||||
handle:finish()
|
||||
end
|
||||
end,
|
||||
@@ -31,27 +29,28 @@ end
|
||||
|
||||
M.handles = {}
|
||||
|
||||
function M:store_progress_handle(id, handle)
|
||||
function M.store_progress_handle(id, handle)
|
||||
M.handles[id] = handle
|
||||
end
|
||||
|
||||
function M:pop_progress_handle(id)
|
||||
function M.pop_progress_handle(id)
|
||||
local handle = M.handles[id]
|
||||
M.handles[id] = nil
|
||||
return handle
|
||||
end
|
||||
|
||||
function M:create_progress_handle(request)
|
||||
function M.create_progress_handle(request)
|
||||
local adapter = request.data.adapter
|
||||
return progress.handle.create({
|
||||
title = " Requesting assistance (" .. request.data.adapter.model .. ")",
|
||||
title = " Requesting assistance (" .. (adapter.model or "default") .. ")",
|
||||
message = "In progress...",
|
||||
lsp_client = {
|
||||
name = M:llm_role_title(request.data.adapter.name),
|
||||
name = M.llm_role_title(adapter),
|
||||
},
|
||||
})
|
||||
end
|
||||
|
||||
function M:llm_role_title(adapter)
|
||||
function M.llm_role_title(adapter)
|
||||
local parts = {}
|
||||
table.insert(parts, adapter.formatted_name)
|
||||
if adapter.model and adapter.model ~= "" then
|
||||
@@ -60,7 +59,7 @@ function M:llm_role_title(adapter)
|
||||
return table.concat(parts, " ")
|
||||
end
|
||||
|
||||
function M:report_exit_status(handle, request)
|
||||
function M.report_exit_status(handle, request)
|
||||
if request.data.status == "success" then
|
||||
handle.message = "Completed"
|
||||
elseif request.data.status == "error" then
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
return {
|
||||
require("utils.extensions.telescope"),
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
local ts = require("telescope")
|
||||
-- ts.load_extension("fzf")
|
||||
ts.load_extension("color_names")
|
||||
ts.load_extension("file_browser")
|
||||
ts.load_extension("glyph")
|
||||
ts.load_extension("ui-select")
|
||||
ts.load_extension("noice")
|
||||
@@ -42,16 +42,4 @@ function M.git_paste_prompt()
|
||||
end)
|
||||
end
|
||||
|
||||
--- Sets up the git-paste module.
|
||||
---
|
||||
--- The module expects an optional configuration table:
|
||||
--- { telescope_key = "<leader>pg" } (or any other keymap you prefer)
|
||||
---
|
||||
---@param opts table|nil
|
||||
function M.setup(opts)
|
||||
opts = opts or {}
|
||||
local telescope_key = opts.telescope_key or "<leader>pg"
|
||||
vim.keymap.set("n", telescope_key, M.git_paste_prompt, { desc = "Git Paste: paste content from git raw URL" })
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
return {
|
||||
require("utils.functions.git_paste"),
|
||||
require("utils.functions.mkdir_under_cursor"),
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
local M = {}
|
||||
vim.notify = require("notify")
|
||||
|
||||
function M.mkdir_under_cursor()
|
||||
local word
|
||||
@@ -19,18 +18,16 @@ function M.mkdir_under_cursor()
|
||||
-- Remove quotes if present
|
||||
word = word:gsub("^[\"']", ""):gsub("[\"']$", "")
|
||||
-- Check if directory exists
|
||||
local stat = vim.loop.fs_stat(word)
|
||||
local stat = vim.uv.fs_stat(word)
|
||||
if not stat then
|
||||
-- Create directory (recursive)
|
||||
vim.loop.fs_mkdir(word, 493) -- 493 = 0755 in decimal
|
||||
vim.notify("Directory created: " .. word, vim.log.levels.INFO)
|
||||
if vim.fn.mkdir(word, "p") == 1 then
|
||||
vim.notify("Directory created: " .. word, vim.log.levels.INFO)
|
||||
else
|
||||
vim.notify("Failed to create directory: " .. word, vim.log.levels.ERROR)
|
||||
end
|
||||
else
|
||||
vim.notify("Directory already exists: " .. word, vim.log.levels.WARN)
|
||||
end
|
||||
end
|
||||
|
||||
function M.setup(opts)
|
||||
return M.mkdir_under_cursor
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
vim.notify = require("notify")
|
||||
|
||||
local client_notifs = {}
|
||||
|
||||
local function get_notif_data(client_id, token)
|
||||
@@ -20,7 +18,7 @@ local function update_spinner(client_id, token)
|
||||
local notif_data = get_notif_data(client_id, token)
|
||||
|
||||
if notif_data.spinner then
|
||||
local new_spinner = (notif_data.spinner + 1) % #spinner_frames
|
||||
local new_spinner = (notif_data.spinner % #spinner_frames) + 1
|
||||
notif_data.spinner = new_spinner
|
||||
|
||||
notif_data.notification = vim.notify("", nil, {
|
||||
@@ -42,10 +40,12 @@ end
|
||||
local function format_message(message, percentage)
|
||||
return (percentage and percentage .. "%\t" or "") .. (message or "")
|
||||
end
|
||||
|
||||
local hyprland_lsp = vim.api.nvim_create_augroup("HyprlandLsp", { clear = true })
|
||||
vim.api.nvim_create_autocmd({ "BufEnter", "BufWinEnter" }, {
|
||||
group = hyprland_lsp,
|
||||
pattern = { "*.hl", "hypr*.conf" },
|
||||
callback = function(event)
|
||||
-- print(string.format("starting hyprls for %s", vim.inspect(event)))
|
||||
callback = function()
|
||||
vim.lsp.start({
|
||||
name = "hyprlang",
|
||||
cmd = { "hyprls" },
|
||||
@@ -94,6 +94,7 @@ vim.api.nvim_create_autocmd({ "BufEnter", "BufWinEnter" }, {
|
||||
})
|
||||
|
||||
notif_data.spinner = nil
|
||||
client_notifs[client_id][result.token] = nil
|
||||
end
|
||||
end,
|
||||
},
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
local M = {}
|
||||
local map = vim.keymap.set
|
||||
local opts = { noremap = true, silent = false }
|
||||
|
||||
--- Set keybindings from a table of mappings.
|
||||
--- @param bindings table A list of keybinding mappings.
|
||||
--- Each mapping should be a table with the following keys:
|
||||
--- - mode: string, the mode in which the keybinding applies (e.g., 'n', 'i', 'v').
|
||||
--- - key: string, the key to bind.
|
||||
--- - cmd: string, the command to execute when the key is pressed.
|
||||
--- - opts: table, optional, additional options for the keybinding (default:
|
||||
function M.set_keybindings(bindings)
|
||||
for _, binding in ipairs(bindings) do
|
||||
map(binding.mode, binding.key, binding.cmd, binding.opts or opts)
|
||||
end
|
||||
return bindings
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -1,51 +0,0 @@
|
||||
local M = {}
|
||||
|
||||
local whichkey = require("which-key")
|
||||
vim.notify = require("notify")
|
||||
|
||||
---Helper function to add mappings to which-key
|
||||
---@param mappings table List of mappings to add
|
||||
---@param group table Group to add mappings to (optional)
|
||||
---@return nil
|
||||
---@usage addToWhichKey(mappings, group)
|
||||
---@example addToWhichKey({{key = "n", cmd = "next", mode = "n", desc = "Next Line", group = "Navigation"}, {key = "t", group = "example"})
|
||||
function M.addToWhichKey(mappings, group)
|
||||
if group then
|
||||
whichkey.add({ group.key, group = group.group })
|
||||
end
|
||||
if not mappings and not group then
|
||||
vim.notify("Error: Mappings is nil", "error")
|
||||
return
|
||||
elseif not mappings and group then
|
||||
return
|
||||
end
|
||||
local wk_mappings = {}
|
||||
for _, mapping in ipairs(mappings) do
|
||||
wk_mappings = {}
|
||||
if not mapping.key or mapping.key == "" then
|
||||
vim.notify("Error: Key is empty or nil", "error")
|
||||
return
|
||||
end
|
||||
|
||||
if not mapping.cmd or mapping.cmd == "" then
|
||||
vim.notify("Error: Command is empty or nil for key: " .. mapping.key, "error")
|
||||
return
|
||||
end
|
||||
|
||||
if not mapping.mode or mapping.mode == "" then
|
||||
vim.notify("Error: Mode is empty or nil for key: " .. mapping.key, "error")
|
||||
return
|
||||
end
|
||||
|
||||
wk_mappings[1] = mapping.key
|
||||
wk_mappings[2] = mapping.cmd
|
||||
wk_mappings.mode = mapping.mode or "n"
|
||||
wk_mappings.desc = mapping.desc
|
||||
if mapping.group then
|
||||
wk_mappings.group = mapping.group
|
||||
end
|
||||
whichkey.add(wk_mappings)
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -1,4 +0,0 @@
|
||||
return {
|
||||
require('utils.keymaps.converters.whichkey'),
|
||||
require('utils.keymaps.converters.from_table'),
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
local telescope = require("telescope")
|
||||
local telescopeConfig = require("telescope.config")
|
||||
local actions = require("telescope.actions")
|
||||
|
||||
local M = {}
|
||||
|
||||
function M.find_and_paste_image()
|
||||
local telescope = require("telescope.builtin")
|
||||
local actions = require("telescope.actions")
|
||||
local action_state = require("telescope.actions.state")
|
||||
|
||||
telescope.find_files({
|
||||
attach_mappings = function(_, map)
|
||||
local function embed_image(prompt_bufnr)
|
||||
local entry = action_state.get_selected_entry()
|
||||
local filepath = entry[1]
|
||||
actions.close(prompt_bufnr)
|
||||
|
||||
local img_clip = require("img-clip")
|
||||
img_clip.paste_image(nil, filepath)
|
||||
end
|
||||
|
||||
map("i", "<CR>", embed_image)
|
||||
map("n", "<CR>", embed_image)
|
||||
|
||||
return true
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
function M.setup()
|
||||
-- Clone the default Telescope configuration
|
||||
local vimgrep_arguments = { unpack(telescopeConfig.values.vimgrep_arguments) }
|
||||
|
||||
-- I want to search in hidden/dot files.
|
||||
table.insert(vimgrep_arguments, "--hidden")
|
||||
-- I don't want to search in the `.git` directory.
|
||||
table.insert(vimgrep_arguments, "--glob")
|
||||
table.insert(vimgrep_arguments, "!**/.git/*")
|
||||
vim.tbl_deep_extend("force", telescopeConfig.values, {
|
||||
mappings = {
|
||||
i = {
|
||||
["<C-h>"] = actions.results_scrolling_left,
|
||||
["<C-l>"] = actions.results_scrolling_right,
|
||||
},
|
||||
},
|
||||
})
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -1,6 +0,0 @@
|
||||
local M = {}
|
||||
|
||||
M.term_factory = require("utils.terminal.term_factory").term_factory
|
||||
M.term_toggle = require("utils.terminal.toggle").term_toggle
|
||||
|
||||
return M
|
||||
@@ -1,12 +0,0 @@
|
||||
local Terminal = require("toggleterm.terminal").Terminal
|
||||
local notify = require("notify")
|
||||
local M = {}
|
||||
|
||||
function M.term_factory(cfg)
|
||||
cfg["on_stderr"] = function(_, job, data, name)
|
||||
notify(name .. " encountered an error on job: " .. job .. "\nData: " .. data, "error")
|
||||
end
|
||||
return Terminal:new(cfg)
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -1,9 +0,0 @@
|
||||
local M = {}
|
||||
|
||||
function M.term_toggle(term)
|
||||
if term then
|
||||
term:toggle()
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -1,15 +0,0 @@
|
||||
local parser_config = require("nvim-treesitter.parsers").get_parser_configs()
|
||||
parser_config.hyprlang = {
|
||||
install_info = {
|
||||
url = "~/github/tree-sitter-hyprlang", -- local path or git repo
|
||||
files = { "src/parser.c" }, -- note that some parsers also require src/scanner.c or src/scanner.cc
|
||||
-- optional entries:
|
||||
branch = "main", -- default branch in case of git repo if different from master
|
||||
generate_requires_npm = false, -- if stand-alone parser without npm dependencies
|
||||
requires_generate_from_grammar = true, -- if folder contains pre-generated src/parser.c
|
||||
},
|
||||
filetype = "conf", -- if filetype does not match the parser name
|
||||
}
|
||||
vim.filetype.add({
|
||||
pattern = { [".*/hypr/.*%.conf"] = "hyprlang" },
|
||||
})
|
||||
Reference in New Issue
Block a user