olimorris / persisted.nvim

๐Ÿ’พ Simple session management for Neovim with git branching, autoloading and Telescope support

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

LSP not working on opened buffer

KiritchoukC opened this issue ยท comments

Thanks for your work on this plugin, it's awesome.

I just have one issue when a session is restored.
On the opened focused buffer, LSP is not running.
I have to close the buffer and reopen it.
The other opened buffers are fine tho.

I don't know what could cause such behavior.

persisted-issue

Any help is appreciated :)

commented

Really appreciate your comments, thank you.

A few questions:

  • Are you using autoload? Could you share your persisted config?
  • What about if you "force" reload the LSP like below?
:lua vim.lsp.stop_client(vim.lsp.get_active_clients())
:edit
  • Is it definitely the LSP? I notice there's no highlighting which makes me wonder if it's a Treesitter issue?

Thanks for the answer

  • Yes I'm using autoload. Here's my config:
persisted.setup({
  save_dir = vim.fn.expand(vim.fn.stdpath("data") .. "/sessions/"), -- directory where session files are saved
  command = "VimLeavePre", -- the autocommand for which the session is saved
  use_git_branch = false, -- create session files based on the branch of the git enabled repository
  autosave = true, -- automatically save session files when exiting Neovim
  autoload = true, -- automatically load the session for the cwd on Neovim startup
  allowed_dirs = nil, -- table of dirs that the plugin will auto-save and auto-load from
  ignored_dirs = nil, -- table of dirs that are ignored when auto-saving and auto-loading
  before_save = function() end, -- function to run before the session is saved to disk
  after_save = function() end, -- function to run after the session is saved to disk
  telescope = { -- options for the telescope extension
    before_source = function(session) end, -- function to run before the session is sourced via telescope
    after_source = function(session) end, -- function to run after the session is sourced via telescope
  },
})
  • Just entering :edit worked ๐Ÿ‘
  • I got no highlights and no diagnostics so I guess it's both
commented

@KiritchoukC what's the best way to resolve this? I could put an after_source callback config option in? Or, I could just add the :edit command when autoloading?

If I'm the only one having this issue then the after_source callback is good enough imo. What do you think?

commented

@KiritchoukC I've just pushed an update using the :edit option. Can you let me know if it works?

@olimorris awsome man, I'll do that first thing tomorrow morning!

Unfortunately, I still have to type :edit when entering the buffer.
Don't spend too much time on this. I will find a workaround when I have time.
It's not that bad :)

commented

Arghhhhh. I think this latest one may have fixed. If not...I am going with after_source config option

Still not working.
I forked the repo and tried things but my knowledge in nvim plugin development is non-existent.
I'll continue investigating and will make a pr if by any chance I'm able to resolve it ๐Ÿ˜„

Update:
Still no success.
Last thing I tried is

---Start recording a session and write to disk on a specific autocommand
---@return nil
function M.start()
  vim.api.nvim_create_augroup("Persisted", { clear = true })
  vim.api.nvim_create_autocmd(config.options.command, { command = "%s * lua require('persisted').save()", group = group })
  vim.api.nvim_create_autocmd("BufEnter", { command = "redraw | edit | echom 'Edited'", group = group })
  vim.g.persisting = true
end

Tried so many events, none of them would do the :edit for me
(SourcePost, BufEnter, TabEnter, WinEnter, FocusGained, FileReadPost, ...)

commented

I've added in the after_source callback. I've also included an example in the readme:

require("persisted").setup({
  after_source = function()
    -- Reload the LSP servers
    vim.lsp.stop_client(vim.lsp.get_active_clients())
    vim.cmd("edit")
  end
})

Let me know if this works.

Thank you for that.
No, it does not work. This does not make sense to me why manually :edit works but in function, it doesn't.

But the function is enough for me to try things so leave it like that and I will keep looking for a fix.

I appreciate your work, thank you @olimorris

commented

Haha damn!!! I'm refusing for us to beaten by this ๐Ÿ˜„.

Just to check, does stopping the LSPs first then enable "edit" to work?

:lua vim.lsp.stop_client(vim.lsp.get_active_clients())
:edit

Yeah I actually took your example but no it does not work ๐Ÿคทโ€โ™‚๏ธ

You can try this:

vim.keymap.set(
  {"n"},
  "<leader>sl",
  function()
    vim.cmd("silent! SessionLoad")
    -- reload lsp servers
    pcall(vim.cmd, "edit")
  end,
  {silent=true})
commented

@KiritchoukC wondered if you could test the latest version of the plugin. I think we may have solved this issue in #12

Awesome! I will try later and let you know how it went.
Thanks again

I can confirm that it is working with that latest version.
Thanks @olimorris and @simonmclean