Skip to content

Commit

Permalink
refactor(fidget): rename code_companion to code_companion_fidget
Browse files Browse the repository at this point in the history
* Rename module to avoid potential naming conflicts
* Add helper function to handle underscore issues in embedded lua
* Remove commented out code at end of file
  • Loading branch information
simonwjackson committed Jan 31, 2025
1 parent cdf7706 commit 86874b8
Showing 1 changed file with 33 additions and 83 deletions.
116 changes: 33 additions & 83 deletions config/fidget.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{lib, ...}: {
{lib, ...}: let
# HACK: There is an issue with the LSP server and embedded lua code
unDerscore = str: builtins.replaceStrings ["_("] ["("] str;
in {
plugins.fidget = {
enable = true;
settings = {
Expand All @@ -11,18 +14,22 @@
display = {
done_icon = "";
done_ttl = 5;
format_message = lib.nixvim.mkRaw ''
function(msg)
if string.find(msg.title, "Indexing") then
return nil -- Ignore \"Indexing...\" progress messages
format_message = lib.nixvim.mkRaw (
unDerscore
# lua
''
function _(msg)
if string.find(msg.title, "Indexing") then
return nil -- Ignore \"Indexing...\" progress messages
end
if msg.message then
return msg.message
else
return msg.done and "Completed" or "In progress..."
end
end
if msg.message then
return msg.message
else
return msg.done and "Completed" or "In progress..."
end
end
'';
''
);
};
};
text = {
Expand All @@ -32,37 +39,37 @@
};

extraConfigLua = ''
local code_companion = {}
local code_companion_fidget = {}
function code_companion.start_fidget()
function code_companion_fidget.start_fidget()
local has_fidget, fidget = pcall(require, "fidget")
if not has_fidget then
return
end
if code_companion.fidget_progress_handle then
code_companion.fidget_progress_handle.message = "Abort."
code_companion.fidget_progress_handle:cancel()
code_companion.fidget_progress_handle = nil
if code_companion_fidget.fidget_progress_handle then
code_companion_fidget.fidget_progress_handle.message = "Abort."
code_companion_fidget.fidget_progress_handle:cancel()
code_companion_fidget.fidget_progress_handle = nil
end
code_companion.fidget_progress_handle = fidget.progress.handle.create({
code_companion_fidget.fidget_progress_handle = fidget.progress.handle.create({
title = "",
message = "Thinking...",
lsp_client = { name = "CodeCompanion" },
})
end
function code_companion.stop_fidget()
function code_companion_fidget.stop_fidget()
local has_fidget, _ = pcall(require, "fidget")
if not has_fidget then
return
end
if code_companion.fidget_progress_handle then
code_companion.fidget_progress_handle.message = "Done."
code_companion.fidget_progress_handle:finish()
code_companion.fidget_progress_handle = nil
if code_companion_fidget.fidget_progress_handle then
code_companion_fidget.fidget_progress_handle.message = "Done."
code_companion_fidget.fidget_progress_handle:finish()
code_companion_fidget.fidget_progress_handle = nil
end
end
Expand All @@ -73,68 +80,11 @@
group = group,
callback = function(event)
if event.match == "CodeCompanionRequestStarted" then
code_companion.start_fidget()
code_companion_fidget.start_fidget()
elseif event.match == "CodeCompanionRequestFinished" then
code_companion.stop_fidget()
code_companion_fidget.stop_fidget()
end
end,
})
'';
}
# local M = {}
#
# function M.start_fidget()
# local has_fidget, fidget = pcall(require, "fidget")
# if not has_fidget then
# return
# end
#
# if M.fidget_progress_handle then
# M.fidget_progress_handle.message = "Abort."
# M.fidget_progress_handle:cancel()
# M.fidget_progress_handle = nil
# end
#
# M.fidget_progress_handle = fidget.progress.handle.create({
# title = "",
# message = "Thinking...",
# lsp_client = { name = "CodeCompanion" },
# })
# end
#
# function M.stop_fidget()
# local has_fidget, _ = pcall(require, "fidget")
# if not has_fidget then
# return
# end
#
# if M.fidget_progress_handle then
# M.fidget_progress_handle.message = "Done."
# M.fidget_progress_handle:finish()
# M.fidget_progress_handle = nil
# end
# end
#
# function M.setup_fidget()
# local has_fidget, _ = pcall(require, "fidget")
# if has_fidget then
# -- New AU group:
# local group = vim.api.nvim_create_augroup("CodeCompanionHooks", {})
#
# -- Attach:
# vim.api.nvim_create_autocmd({ "User" }, {
# pattern = "CodeCompanionRequest*",
# group = group,
# callback = function(request)
# if request.match == "CodeCompanionRequestStarted" then
# M.start_req_fidget()
# elseif request.match == "CodeCompanionRequestFinished" then
# M.stop_req_fidget()
# end
# end,
# })
# end
# end
#
# return M

0 comments on commit 86874b8

Please sign in to comment.