Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Neovim Session Manager integration to create IDE-like project switching #101

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

coffebar
Copy link

Goal: create IDE-like project switching with saved sessions

Demo how it works in this PR:

I'm switching projects by using :Telescope projects (i mapped this command to <leader>p for me, but only in my personal configuration).

As you can see on the video, opened tabs depends on which project is opened and everything auto-saving when switching projects.

rec.webm

Before merge this PR, you can test it by installing from packer:

use({
"coffebar/project.nvim",
branch = "session-manager",
config = function()
	require("project_nvim").setup({
		session_autoload = true,
		silent_chdir = false,
	})
end,
})

-- session manager
use("Shatur/neovim-session-manager")

Not sure if require("session_manager").setup({... is required by neovim-session-manager, it seems not, but i'm using configuration options for that plugin.

How it NOT breaking things

With default configuration it will not bring any additional features. To add integration user have to enable a new option "session_autoload".
If this option will be enabled, but session manager plugin is not installed, user will see warning message from this code:

print("Warning: session autoloading is enabled, but neovim-session-manager in not installed!")
print("Consider to install 'Shatur/neovim-session-manager' or")
print("change project.nvim option ('session_autoload' = false) to remove this message")

When plugin is installed and option is enabled, project selection can be done in 3 ways:

  • by session manager itself (with it's autoload_mode option)
  • :Telescope projects type project keywords and press <CR>
  • :Telescope projects type project keywords and press <C-w>

<C-d> will work for delete project from history as usual.

Important

When session manager is installed, using find_project_files is not recommended! Opening individual files will make projects.nvim to change current directory, and session manager will automatically overwrite saved sessions with mess from individual files from different projects.

Therefore, using these two plugins together as it was before this PR - is a bad idea. This should fix problem.

Testing

I have tested only for 2 days by using this branch in my Neovim setup. Testing from different configs and workflows are welcome.

Known issues

  • <C-f> will switch project, so find_project_files is totally disabled with session_autoload=true.
  • <C-b> leads to error for me: telescope.builtin.file_browser is nil. I believe this is related with telescope update

@coffebar
Copy link
Author

coffebar commented Nov 19, 2022

UPD: after a month of using this update I am happy with it and have nothing to change about it.
Switching projects happens instantly.

@wenanoshe
Copy link

I don't understand why the command :Telescope projects shows me "unknown command" if everything is installed

 ["coffebar/project.nvim"] = {
    branch = "session-manager",
    config = function()
      require("project_nvim").setup({
        session_autoload = true,
        silent_chdir = false,
      })
    end,
  },

-- session manager
  ["Shatur/neovim-session-manager"] ={},

@coffebar
Copy link
Author

@wenanoshe config seems ok. Did you run :PackerSync ?
Maybe try to restart nvim.


ls ~/.local/share/nvim/site/pack/packer/start | grep -P 'project|session'

should display installed plugins

neovim-session-manager
project.nvim

@wenanoshe
Copy link

Yeah, it displays that

neovim-session-manager
project.nvim

But the comand still not working, shows me that

Error in packer_compiled: ...vim/site/pack/packer/opt/packer.nvim/lua/packer/load.lua:91: Vim:[telescope.run_command]: Unknown command
Please check your config for correctness

@coffebar
Copy link
Author

Projects need to be registered as extension for telescope

require("telescope").load_extension("projects")

@wenanoshe
Copy link

wenanoshe commented Jan 26, 2023

Where i set that command?, excuse my ignorance

@coffebar
Copy link
Author

where you put telescope config

@musjj
Copy link

musjj commented Feb 28, 2023

Maybe it's time for a fork? There's a lot of low-hanging fruit PRs that is being ignored for over a year now, so I think the dev isn't really interested in maintaining/improving this project anymore.

@coffebar
Copy link
Author

Update:

I decided to create a fork, focused on my desired workflow with auto-saved sessions.

This fork has different vision and way.

project.mp4

@ditsuke
Copy link

ditsuke commented May 8, 2023

I would prefer we get #77 to avoid coupling to a single session manager plugin.

@jay-babu
Copy link

jay-babu@4591e8d

merged here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants