flake/nixos/nvim/plugins/profile.nix
2025-02-04 08:28:09 -06:00

63 lines
1.9 KiB
Nix

{ 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
local function toggle_profile()
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
vim.keymap.set("", "<leader>p", toggle_profile, { desc = "Toggle Profiling", silent = true })
'';
# keymaps = [
# {
# mode = "n";
# key = "<leader>p";
# action = "toggle_profile";
# options = {
# desc = "Toggle Profiling";
# silent = true;
# };
# }
# ];
};
}