rmagatti / auto-session

A small automated session manager for Neovim
MIT License
1.29k stars 46 forks source link

Config clean up #339

Closed cameronr closed 2 months ago

cameronr commented 3 months ago

I'm thinking about trying to revamp the config to something like:

local AutoSessionConf = {
  enabled = true, -- Enables/disables auto creating, saving and restoring
  session_root_dir = vim.fn.stdpath "data" .. "/sessions/", -- Root dir where sessions will be stored
  auto_save_enabled = true, -- Enables/disables auto save feature
  auto_restore_enabled = true, -- Enables/disables auto restore feature
  auto_create_enabled = true, -- Enables/disables auto creating new sessions. Can take a function that should return true/false if a session should be created or not
  suppress_dirs = nil, -- Suppress session restore/create in certain directories
  allowed_dirs = nil, -- Allow session restore/create in certain directories
  enable_last_session = false, -- Enables/disables the "last session" feature
  use_git_branch = false, -- Include git branch name in session name
  lazy_delay_enabled = true, -- Enables/disables Lazy delay feature
  log_level = "error", -- Sets the log level of the plugin (debug, info, error)
  bypass_session_save_file_types = nil, -- Bypass auto save when only buffer open is one of these file types
  close_unsupported_windows = true, -- Close windows that aren't backed by normal file before autosaving a session
  args_allow_single_directory = true, -- Allow single directory arguments by default
  args_allow_files_auto_save = false, -- Don't save session for file args by default

  cwd_change_handling = false, -- Try to save/restore sessions when changing directories. pre/post cmds converted to hooks

  session_lens = {
    load_on_setup = true, -- Initialize on startup (requires Telescope)
    theme_conf = {}, -- Pass through for Telescope theme options
    previewer = false, -- File preview for session picker
  },
  session_control = {
    control_dir = vim.fn.stdpath "data" .. "/auto_session/", -- Auto session control dir, for control files, like alternating between two sessions with session-lens
    control_filename = "session_control.json", -- File name of the session control file
  },
  continue_restore_on_error = true, -- Suppress extraneous messages and source the whole session, even if there's an error. Set to false to get the line number of a restore error
}

I would plan to make the Lua config the default in the docs but I'd support the existing vimscript args. I think I'd add a config.lua file and do everything there but that's still just a thought.

@rmagatti What do you think? Are there other changes you'd make?

rmagatti commented 3 months ago

Hey @cameronr sorry, been a bit busy with work lately. Yes, I've been wanting to streamline the configs for sometime now. Something that particularly bothers me is that the LSP gets confused as to what options are available to use. And yes the vimscript configs need to be supported as legacy but certainly shouldn't be the default checks. Maybe a more streamlined implementation in a config.lua file like you mentioned could transparently handle whether the configs come from vimscript or the lua config.

I think the goal on a revamp like this should be to make the configs easily discoverable by the LSP, with proper docstring documentation for each field.

cameronr commented 2 months ago

No worries, this is just a background idea. Good point to make sure whatever we do works well with the lua ls. I'm still ruminating on this one. I'd like to do it at some point but may take some time.

cameronr commented 2 months ago

@rmagatti it's not done yet (still have to do readme, maybe unify autocmds), but i made a bunch of progress on the config cleanup. can see some of it here if you want to take an early look:

https://github.com/cameronr/auto-session/blob/config-overhaul/lua/auto-session/config.lua

it's working nicely with lua_ls (when using a config function, sadly lazy opts tables don't get the same treatment):

Screenshot 2024-08-22 at 15 08 47

rmagatti commented 2 months ago

Nice, that looks awesome!

cameronr commented 2 months ago

ooh, i figured out how to enable it for opts as well:

Screenshot 2024-08-25 at 20 30 03

cameronr commented 2 months ago

Closed in #359