diff options
| author | 2026-04-17 10:53:13 +0100 | |
|---|---|---|
| committer | 2026-04-17 10:53:13 +0100 | |
| commit | b2b9abba7c697a443e5da935c956d2fa4e4f5699 (patch) | |
| tree | 13bcc26cddb09504c30c398c8bb92c2d5f9702ff | |
| parent | c5fa38bd6da184b735be2cea5da477cc0913e9b3 (diff) | |
| download | dotfiles-b2b9abba7c697a443e5da935c956d2fa4e4f5699.tar.gz dotfiles-b2b9abba7c697a443e5da935c956d2fa4e4f5699.tar.bz2 dotfiles-b2b9abba7c697a443e5da935c956d2fa4e4f5699.zip | |
refactor: extract auto-session to plugins/session.lua
Move auto-session config (85 lines, with overseer and dap integration) from
plugins/init.lua into a dedicated session.lua file.
| -rw-r--r-- | home/.config/nvim/lua/plugins/init.lua | 86 | ||||
| -rw-r--r-- | home/.config/nvim/lua/plugins/session.lua | 84 |
2 files changed, 84 insertions, 86 deletions
diff --git a/home/.config/nvim/lua/plugins/init.lua b/home/.config/nvim/lua/plugins/init.lua index 9c3c20a..9594015 100644 --- a/home/.config/nvim/lua/plugins/init.lua +++ b/home/.config/nvim/lua/plugins/init.lua @@ -7,92 +7,6 @@ return { ft = "markdown", }, { - "rmagatti/auto-session", - lazy = false, - opts = function() - -- Convert the cwd to a simple file name - local function get_cwd_as_name() - local dir = vim.fn.getcwd(0) - return dir:gsub("[^A-Za-z0-9]", "_") - end - local overseer = require("overseer") - return { - use_git_branch = true, - pre_save_cmds = { - function() - overseer.save_task_bundle( - get_cwd_as_name(), - -- Passing nil will use config.opts.save_task_opts. You can call list_tasks() explicitly and - -- pass in the results if you want to save specific tasks. - nil, - { on_conflict = "overwrite" } -- Overwrite existing bundle, if any - ) - end, - }, - -- Optionally get rid of all previous tasks when restoring a session - pre_restore_cmds = { - function() - for _, task in ipairs(overseer.list_tasks({})) do - task:dispose(true) - end - end, - }, - post_restore_cmds = { - function() - overseer.load_task_bundle( - get_cwd_as_name(), - { ignore_missing = true, autostart = false } - ) - end, - }, - save_extra_data = function(_) - local ok, breakpoints = pcall(require, "dap.breakpoints") - if not ok or not breakpoints then - return - end - - local bps = {} - local breakpoints_by_buf = breakpoints.get() - for buf, buf_bps in pairs(breakpoints_by_buf) do - bps[vim.api.nvim_buf_get_name(buf)] = buf_bps - end - if vim.tbl_isempty(bps) then - return - end - local extra_data = { - breakpoints = bps, - } - return vim.fn.json_encode(extra_data) - end, - - restore_extra_data = function(_, extra_data) - local json = vim.fn.json_decode(extra_data) - - if json.breakpoints then - local ok, breakpoints = pcall(require, "dap.breakpoints") - - if not ok or not breakpoints then - return - end - vim.notify("restoring breakpoints") - for buf_name, buf_bps in pairs(json.breakpoints) do - for _, bp in pairs(buf_bps) do - local line = bp.line - local opts = { - condition = bp.condition, - log_message = bp.logMessage, - hit_condition = bp.hitCondition, - } - breakpoints.set(opts, vim.fn.bufnr(buf_name), line) - end - end - end - end, - suppressed_dirs = { "~/", "/" }, - } - end, - }, - { "aserowy/tmux.nvim", event = "VeryLazy", opts = { diff --git a/home/.config/nvim/lua/plugins/session.lua b/home/.config/nvim/lua/plugins/session.lua new file mode 100644 index 0000000..36759b0 --- /dev/null +++ b/home/.config/nvim/lua/plugins/session.lua @@ -0,0 +1,84 @@ +return { + { + "rmagatti/auto-session", + lazy = false, + opts = function() + local function get_cwd_as_name() + local dir = vim.fn.getcwd(0) + return dir:gsub("[^A-Za-z0-9]", "_") + end + local overseer = require("overseer") + return { + use_git_branch = true, + pre_save_cmds = { + function() + overseer.save_task_bundle( + get_cwd_as_name(), + nil, + { on_conflict = "overwrite" } + ) + end, + }, + pre_restore_cmds = { + function() + for _, task in ipairs(overseer.list_tasks({})) do + task:dispose(true) + end + end, + }, + post_restore_cmds = { + function() + overseer.load_task_bundle( + get_cwd_as_name(), + { ignore_missing = true, autostart = false } + ) + end, + }, + save_extra_data = function(_) + local ok, breakpoints = pcall(require, "dap.breakpoints") + if not ok or not breakpoints then + return + end + + local bps = {} + local breakpoints_by_buf = breakpoints.get() + for buf, buf_bps in pairs(breakpoints_by_buf) do + bps[vim.api.nvim_buf_get_name(buf)] = buf_bps + end + if vim.tbl_isempty(bps) then + return + end + local extra_data = { + breakpoints = bps, + } + return vim.fn.json_encode(extra_data) + end, + + restore_extra_data = function(_, extra_data) + local json = vim.fn.json_decode(extra_data) + + if json.breakpoints then + local ok, breakpoints = pcall(require, "dap.breakpoints") + + if not ok or not breakpoints then + return + end + vim.notify("restoring breakpoints") + for buf_name, buf_bps in pairs(json.breakpoints) do + for _, bp in pairs(buf_bps) do + local line = bp.line + local opts = { + condition = bp.condition, + log_message = bp.logMessage, + hit_condition = bp.hitCondition, + } + breakpoints.set(opts, vim.fn.bufnr(buf_name), line) + end + end + end + end, + suppressed_dirs = { "~/", "/" }, + } + end, + }, +} |
