-
-
Notifications
You must be signed in to change notification settings - Fork 47
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
File tree integration with nvim-tree and NERDTree #179
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @zwhitchcox, thanks for the PR! I appreciate you trying to fix this!
However, I still have a pretty strong view on adding code into auto-session to support/interface with specific plugins, like I mention in this comment: #105 (comment)
Ultimately adding this code would mean I have to support a whole new set of functionality for interfacing with plugins I don't even personally use myself.
While I can certainly understand the appeal of "just fixing it here", the long-term support of this is what worries me.
@rmagatti Hey, thanks for getting back to me so quickly. I actually think you're right. You don't want external plugin-specific code in your code, because then if they change something, it could break your code. I had hoped there would be a file-tree generalized approach, but I can't see one. Oh well. Instead, I think I can make a Anyway, I took out all the external plugin-specific stuff and left in general bug fixes which prevent the "hook" solution from working. (causing session corruption, infinite loops, etc.) Let me know if this looks good, and I'll squash the commits. |
b22064d
to
014d905
Compare
|
||
-- Deferring to avoid otherwise there are tresitter highlighting issues | ||
vim.defer_fn(function() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This approach was causing an infinite loop. From the docs:
DirChanged After the current-directory was changed.
...
Non-recursive (event cannot trigger itself).
By triggering Autosession.AutoRestoreSession
asynchronously, it caused an infinite loop where the opened buffer could change the global directory (somehow) after opening. So, I moved the asynchronous part to after the session was restored. It then runs filetype detect
on all the open buffers which fixes the syntax highlighting error.
@@ -480,6 +480,19 @@ function AutoSession.RestoreSessionFromFile(session_file) | |||
AutoSession.RestoreSession(string.format(AutoSession.get_root_dir() .. "%s.vim", session_file:gsub("/", "%%"))) | |||
end | |||
|
|||
-- | |||
-- Refresh syntax highlighting and file trees | |||
local function post_restore_refresh() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what fixes the syntax highlighting. I moved it to after the restore session, so that it's always triggered. Although, I'm not sure if the problem exists other than in during the autocmd
callbacks? So, it might be better to move it back there if not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, I hadn't noticed problems with this. But this should be fine anyway 👍
Ok, I created a plugin Please review the code and let me know what you think if you don't mind. |
Ok, I actually just realized there's a That's not really directly relevant to this PR, but more for the plugin.
This PR will still need to be merged though, because the aforementioned issue will still break, just wanted to let you know. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for putting the time into this! 🎉
@@ -480,6 +480,19 @@ function AutoSession.RestoreSessionFromFile(session_file) | |||
AutoSession.RestoreSession(string.format(AutoSession.get_root_dir() .. "%s.vim", session_file:gsub("/", "%%"))) | |||
end | |||
|
|||
-- | |||
-- Refresh syntax highlighting and file trees | |||
local function post_restore_refresh() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, I hadn't noticed problems with this. But this should be fine anyway 👍
Yeah, happy to help! So, upon further inspection, it looks like if you add
this will automatically restore syntax highlighting without needing to redetect the this also saves options like |
This enables file tree integration with
nvim-tree
andNERDTree
.It is fairly difficult to get sessions and file tree browsers to play nicely together, but when you do, the result is spectacular.
As such, I thought I'd make it easier to integrate the two with a simple configuration option:
This hopefully fixes:
nvim-tree
not recognized - With Workaround #178And would be a solution for people struggling with sessions/file trees elsewhere as well: