flake/nixos/nvim/plugins/profile.nix

63 lines
1.8 KiB
Nix
Raw Normal View History

2025-02-04 08:26:49 -06:00
{ pkgs, ... }:
{
programs.nixvim = {
extraPlugins = [
(pkgs.vimUtils.buildVimPlugin {
# https://github.com/stevearc/profile.nvim
name = "profile";
src = pkgs.fetchFromGitHub {
owner = "stevearc";
repo = "profile.nvim";
rev = "f2d2cf5eae9ba3b9ca6bc148507d153f3e6ae282";
sha256 = "sha256-xnScKSrlm1N3cw+hPmUd97b1gjue7FG+1f9genzw5yM=";
};
})
];
extraConfigLuaPre = # lua
''
local should_profile = os.getenv("NVIM_PROFILE")
if should_profile then
require("profile").instrument_autocmds()
if should_profile:lower():match("^start") then
require("profile").start("*")
else
require("profile").instrument("*")
end
end
2025-02-08 12:53:14 -06:00
vim.g.toggle_profile = function()
2025-02-04 08:26:49 -06:00
local prof = require("profile")
if prof.is_recording() then
prof.stop()
vim.ui.input({ prompt = "Save profile to:", completion = "file", default = "profile.json" }, function(filename)
if filename then
prof.export(filename)
vim.notify(string.format("Wrote %s", filename))
end
end)
else
vim.ui.select({ "yes", "no" }, { prompt = "Would you like to start profiling?", format_item = function(item)
return item
end,
}, function(choice)
if choice == "yes" then
prof.start("*")
end
end)
end
end
'';
2025-02-08 12:53:14 -06:00
keymaps = [
{
mode = "n";
key = "<leader>p";
action = "<CMD>lua vim.g.toggle_profile()<CR>";
options = {
desc = "Toggle Profiling";
silent = true;
};
}
];
2025-02-04 08:26:49 -06:00
};
}