Skip to content

[BUG] filetype doesn't get restored after change of directory #204

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

Closed
nnako opened this issue Feb 15, 2023 · 12 comments
Closed

[BUG] filetype doesn't get restored after change of directory #204

nnako opened this issue Feb 15, 2023 · 12 comments
Assignees
Labels
bug Something isn't working

Comments

@nnako
Copy link

nnako commented Feb 15, 2023

After starting nvim and creating some tabs containing some buffers with different language files (all the same files will work as well), I use the command cd to walk into a specific project folder. After that, I issue the command SaveSession. This leads to creating a vim file within the default folder ... / nvim-data / sessions / ... . This file contains all the settings to restore the session.

Now, after closing vim, restarting it and cd-ing into the folder from the last session, all the buffers get restored into the appropriate tabs. BUT: the filetype is lost. issuing the command :set filetype results in an empty string.

The expected behavior would be to see the filetypes restored for all the buffers / tabs. Not to be obliged to manually re-set all the filetypes.

Baseline

  • OS. Windows 10:
  • Neovim version v0.9.0

what could this be? Is this not the expected behavior? is it maybe a configuration issue?

@rmagatti
Copy link
Owner

Hi, custom filetypes are not something that gets saved in sessions in Neovim. Which is why I mentioned on the last issue that you'd have to use a hook to set a particular filetype, or even configure Neovim to always associate a particular file extension to a particular filetype of your choice.

You are setting the filetype manually, right?

@nnako
Copy link
Author

nnako commented Feb 17, 2023

It is not about "custom" filetypes, here, but just the "normal", "standard" ones like python or vim which get set automatically when loading respective files into vim or nvim. The problem here seems to be that after retrieving sessions with auto-session, the filetype option stays empty. Even for "standard" filetypes.

yes, I have to set any filetype manually (or using :tabdo set filetype=...) after retrieving / restoring any session by triggering the plugin using cd <project-folder>.

I can't imagine this being the intended behavior. As I am just starting with nvim there are not many plugins which might be able to influence filetype detection.

@rmagatti
Copy link
Owner

Right. You mention there are not many plugins that would influence filetype detection, auto-session is also not one of them. It just uses the underlying session creation and loading capabilities from Neovim.

Something you can try is:

  • Manually opening a file nvim file.py
  • Manually Saving a session :mksess
  • Manually loading the session file :source Session.vim

Do you still see the issue happening?

@nnako
Copy link
Author

nnako commented Feb 18, 2023

I did this:

  • start nvim (via icon on desktop)
  • open Python file from anywhere in the filesystem e.g. using built-in netrw
  • create session file in current folder via :mksess
  • close nvim
  • re-open nvim by desktop icon (same current folder)
  • restore session via :source Session.vim

and the filetype is restored, so I see the Python coloring. So, there does not seem to be an issue within the built-in session management.

@nnako
Copy link
Author

nnako commented Feb 18, 2023

one thing is odd, though: when I create a session file for the default nvim binary folder (in my case it is at c:\PROGS\Neovim__v0_9_0_dev\bin) with the auto-session sessions folder:

C++%PROGS%Neovim__v0_9_0_dev%bin.vim

then, when I start nvim, the session is loaded and the filetype from this session is loaded, correctly. But as soon as I use the cd command from the command line, the appropriate filetype does not get applied for files / buffers loaded into nvim.

@nnako nnako changed the title [BUG] filetype doesn't get restored [BUG] filetype doesn't get restored after change of directory Feb 18, 2023
@rmagatti
Copy link
Owner

Have you set cwd_change_handling correctly in your config? What does your setup call look like?

@nnako
Copy link
Author

nnako commented Feb 22, 2023

yes, I have and had (as mentioned in #205). But this should not influence the missing colors, anyway, I would think.

It is odd that restoration of colors works in the first place (when starting nvim and auto-loading the session respective to the current folder) but fails on all subsequent folder changes.

@3rd
Copy link

3rd commented May 6, 2024

    post_restore_cmds = {
      function()
        vim.api.nvim_exec2("edit", {})
      end,
    },

@apaleslimghost
Copy link

i was running into this issue, and it appears to have been fixed by adding localsettings to my sessionoptions

@rmagatti
Copy link
Owner

@nnako it's probably worth trying out @apaleslimghost's findings here if you haven't already

@rbmarliere
Copy link

I just came across this and can confirm that this solves the issue:

vim.opt.sessionoptions:append({ "localoptions" })

Thanks @apaleslimghost

@cameronr
Copy link
Collaborator

Seems like we should add a check for that and pop up a warning if localoptions isn't present. I'll look into that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants