Skip to content

Commit

Permalink
feat(nvim): add resession.nvim
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjones2014 committed Aug 28, 2023
1 parent a5fadb2 commit 5231cd7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
30 changes: 30 additions & 0 deletions nvim/lua/my/configure/session.lua
Original file line number Diff line number Diff line change
@@ -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')

This comment has been minimized.

Copy link
@towry

towry Aug 28, 2023

:h system()

		If {cmd} is a List it runs directly (no 'shell').
		If {cmd} is a String it runs in the 'shell', like this: >vim
		  call jobstart(split(&shell) + split(&shellcmdflag) + ['{cmd}'])

may cause issues like this: akinsho/git-conflict.nvim#58

This comment has been minimized.

Copy link
@mrjones2014

mrjones2014 Aug 28, 2023

Author Owner

Thanks! Fixed by b2fc7c3

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 },
},
}
6 changes: 5 additions & 1 deletion nvim/lua/my/lsp/utils/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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

Expand Down

0 comments on commit 5231cd7

Please sign in to comment.