diff --git a/nvim/lua/my/configure/session.lua b/nvim/lua/my/configure/session.lua new file mode 100644 index 00000000..1bb483e3 --- /dev/null +++ b/nvim/lua/my/configure/session.lua @@ -0,0 +1,30 @@ +return { + 'stevearc/resession.nvim', + event = 'VeryLazy', + init = function() + local function get_session_name() + local name = vim.fn.getcwd() + local branch = vim.fn.system('git branch --show-current') + if vim.v.shell_error == 0 then + return name .. branch + else + return name + end + end + + -- Only load the session if nvim was started with no args, or if command was to open a directory, not a file + local num_args = vim.fn.argc(-1) + if num_args == 0 or (num_args == 1 and vim.fn.isdirectory(vim.fn.argv(0) or '') ~= 0) then + require('resession').load(get_session_name(), { dir = 'dirsession', silence_errors = true, notify = false }) + end + + vim.api.nvim_create_autocmd('VimLeavePre', { + callback = function() + require('resession').save(get_session_name(), { dir = 'dirsession', notify = false }) + end, + }) + end, + opts = { + autosave = { enabled = true }, + }, +} diff --git a/nvim/lua/my/lsp/utils/init.lua b/nvim/lua/my/lsp/utils/init.lua index 8c5ca2a7..415bcc74 100644 --- a/nvim/lua/my/lsp/utils/init.lua +++ b/nvim/lua/my/lsp/utils/init.lua @@ -52,7 +52,9 @@ function M.setup_async_formatting() then local view = vim.fn.winsaveview() vim.lsp.util.apply_text_edits(result, ctx.bufnr, 'utf-16') - vim.fn.winrestview(view) + if view then + vim.fn.winrestview(view) + end if ctx.bufnr == vim.api.nvim_get_current_buf() then vim.b.format_saving = true vim.cmd.noautocmd('update') @@ -68,7 +70,9 @@ function M.apply_ui_tweaks() for type, icon in pairs(icons) do local highlight = 'DiagnosticSign' .. type local legacy_highlight = 'DiagnosticSign' .. type + ---@diagnostic disable-next-line vim.fn.sign_define(highlight, { text = icon, texthl = highlight, numhl = highlight }) + ---@diagnostic disable-next-line vim.fn.sign_define(legacy_highlight, { text = icon, texthl = legacy_highlight, numhl = legacy_highlight }) end