mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 08:35:43 +02:00
plugins/auto-session: migrate to mkNeovimPlugin
This commit is contained in:
parent
7f4cfa2728
commit
eda1402981
2 changed files with 210 additions and 178 deletions
|
@ -1,120 +1,191 @@
|
||||||
{
|
{
|
||||||
lib,
|
lib,
|
||||||
config,
|
|
||||||
pkgs,
|
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
|
inherit (lib.nixvim) defaultNullOpts;
|
||||||
inherit (lib) types;
|
inherit (lib) types;
|
||||||
cfg = config.plugins.auto-session;
|
|
||||||
in
|
in
|
||||||
{
|
lib.nixvim.neovim-plugin.mkNeovimPlugin {
|
||||||
options.plugins.auto-session = lib.nixvim.neovim-plugin.extraOptionsOptions // {
|
name = "auto-session";
|
||||||
enable = lib.mkEnableOption "auto-session";
|
package = "auto-session";
|
||||||
|
|
||||||
package = lib.mkPackageOption pkgs "auto-session" {
|
maintainers = [ lib.maintainers.khaneliman ];
|
||||||
default = [
|
|
||||||
"vimPlugins"
|
# TODO: added 204-10-05 remove after 24.11
|
||||||
|
deprecateExtraOptions = true;
|
||||||
|
optionsRenamedToSettings = [
|
||||||
|
"logLevel"
|
||||||
|
[
|
||||||
|
"sessionLens"
|
||||||
|
"loadOnSetup"
|
||||||
|
]
|
||||||
|
[
|
||||||
|
"sessionLens"
|
||||||
|
"themeConf"
|
||||||
|
]
|
||||||
|
[
|
||||||
|
"sessionLens"
|
||||||
|
"previewer"
|
||||||
|
]
|
||||||
|
[
|
||||||
|
"sessionControl"
|
||||||
|
"controlDir"
|
||||||
|
]
|
||||||
|
[
|
||||||
|
"sessionControl"
|
||||||
|
"controlFilename"
|
||||||
|
]
|
||||||
|
];
|
||||||
|
# NOTE: rename the old settings to use the correct variables
|
||||||
|
imports =
|
||||||
|
let
|
||||||
|
basePluginPath = [
|
||||||
|
"plugins"
|
||||||
"auto-session"
|
"auto-session"
|
||||||
];
|
];
|
||||||
};
|
settingsPath = basePluginPath ++ [ "settings" ];
|
||||||
|
nestedAutoSessionPluginPath = basePluginPath ++ [ "autoSession" ];
|
||||||
|
in
|
||||||
|
[
|
||||||
|
(lib.mkRenamedOptionModule (
|
||||||
|
basePluginPath
|
||||||
|
++ [
|
||||||
|
"autoSave"
|
||||||
|
"enabled"
|
||||||
|
]
|
||||||
|
) (settingsPath ++ [ "auto_save" ]))
|
||||||
|
(lib.mkRenamedOptionModule (
|
||||||
|
basePluginPath
|
||||||
|
++ [
|
||||||
|
"autoRestore"
|
||||||
|
"enabled"
|
||||||
|
]
|
||||||
|
) (settingsPath ++ [ "auto_restore" ]))
|
||||||
|
|
||||||
logLevel = lib.nixvim.defaultNullOpts.mkEnum [
|
(lib.mkRenamedOptionModule (
|
||||||
|
basePluginPath
|
||||||
|
++ [
|
||||||
|
"bypassSessionSaveFileTypes"
|
||||||
|
]
|
||||||
|
) (settingsPath ++ [ "bypass_save_filetypes" ]))
|
||||||
|
(lib.mkRenamedOptionModule (nestedAutoSessionPluginPath ++ [ "enableLastSession" ]) (
|
||||||
|
settingsPath
|
||||||
|
++ [
|
||||||
|
"auto_restore_last_session"
|
||||||
|
]
|
||||||
|
))
|
||||||
|
(lib.mkRenamedOptionModule (nestedAutoSessionPluginPath ++ [ "rootDir" ]) (
|
||||||
|
settingsPath
|
||||||
|
++ [
|
||||||
|
"root_dir"
|
||||||
|
]
|
||||||
|
))
|
||||||
|
(lib.mkRenamedOptionModule (nestedAutoSessionPluginPath ++ [ "enabled" ]) (
|
||||||
|
settingsPath
|
||||||
|
++ [
|
||||||
|
"enabled"
|
||||||
|
]
|
||||||
|
))
|
||||||
|
(lib.mkRenamedOptionModule (nestedAutoSessionPluginPath ++ [ "createEnabled" ]) (
|
||||||
|
settingsPath
|
||||||
|
++ [
|
||||||
|
"auto_create"
|
||||||
|
]
|
||||||
|
))
|
||||||
|
(lib.mkRenamedOptionModule (nestedAutoSessionPluginPath ++ [ "suppressDirs" ]) (
|
||||||
|
settingsPath
|
||||||
|
++ [
|
||||||
|
"suppressed_dirs"
|
||||||
|
]
|
||||||
|
))
|
||||||
|
(lib.mkRenamedOptionModule (nestedAutoSessionPluginPath ++ [ "allowedDirs" ]) (
|
||||||
|
settingsPath
|
||||||
|
++ [
|
||||||
|
"allowed_dirs"
|
||||||
|
]
|
||||||
|
))
|
||||||
|
(lib.mkRenamedOptionModule (nestedAutoSessionPluginPath ++ [ "useGitBranch" ]) (
|
||||||
|
settingsPath
|
||||||
|
++ [
|
||||||
|
"use_git_branch"
|
||||||
|
]
|
||||||
|
))
|
||||||
|
(lib.mkRemovedOptionModule (
|
||||||
|
basePluginPath
|
||||||
|
++ [
|
||||||
|
"cwdChangeHandling"
|
||||||
|
]
|
||||||
|
) ''Please switch to `cwd_change_handling` with just a boolean value.'')
|
||||||
|
];
|
||||||
|
|
||||||
|
settingsOptions = {
|
||||||
|
enabled = defaultNullOpts.mkBool true ''
|
||||||
|
Enables/disables auto creating, saving and restoring.
|
||||||
|
'';
|
||||||
|
|
||||||
|
root_dir = defaultNullOpts.mkStr { __raw = "vim.fn.stdpath 'data' .. '/sessions/'"; } ''
|
||||||
|
Root directory for session files.
|
||||||
|
Can be either a string or lua code (using `{__raw = 'foo';}`).
|
||||||
|
'';
|
||||||
|
|
||||||
|
auto_save = defaultNullOpts.mkBool true ''
|
||||||
|
Whether to enable auto saving session.
|
||||||
|
'';
|
||||||
|
|
||||||
|
auto_restore = defaultNullOpts.mkBool true ''
|
||||||
|
Whether to enable auto restoring session.
|
||||||
|
'';
|
||||||
|
|
||||||
|
auto_create = defaultNullOpts.mkBool true ''
|
||||||
|
Whether to enable auto creating new sessions
|
||||||
|
'';
|
||||||
|
|
||||||
|
suppressed_dirs = defaultNullOpts.mkListOf types.str null ''
|
||||||
|
Suppress session create/restore if in one of the list of dirs.
|
||||||
|
'';
|
||||||
|
|
||||||
|
allowed_dirs = defaultNullOpts.mkListOf types.str null ''
|
||||||
|
Allow session create/restore if in one of the list of dirs.
|
||||||
|
'';
|
||||||
|
|
||||||
|
auto_restore_last_session = defaultNullOpts.mkBool false ''
|
||||||
|
On startup, loads the last saved session if session for cwd does not exist.
|
||||||
|
'';
|
||||||
|
|
||||||
|
use_git_branch = defaultNullOpts.mkBool false ''
|
||||||
|
Include git branch name in session name to differentiate between sessions for different
|
||||||
|
git branches.
|
||||||
|
'';
|
||||||
|
|
||||||
|
bypass_save_filetypes = defaultNullOpts.mkListOf types.str null ''
|
||||||
|
List of file types to bypass auto save when the only buffer open is one of the file types
|
||||||
|
listed.
|
||||||
|
'';
|
||||||
|
|
||||||
|
cwd_change_handling = defaultNullOpts.mkBool false ''
|
||||||
|
Follow cwd changes, saving a session before change and restoring after.
|
||||||
|
'';
|
||||||
|
|
||||||
|
log_level = defaultNullOpts.mkEnum [
|
||||||
"debug"
|
"debug"
|
||||||
"info"
|
"info"
|
||||||
"warn"
|
"warn"
|
||||||
"error"
|
"error"
|
||||||
] "error" "Sets the log level of the plugin.";
|
] "error" "Sets the log level of the plugin.";
|
||||||
|
|
||||||
autoSession = {
|
session_lens = {
|
||||||
enabled = lib.nixvim.defaultNullOpts.mkBool true ''
|
load_on_setup = defaultNullOpts.mkBool true ''
|
||||||
Enables/disables auto creating, saving and restoring.
|
If `load_on_setup` is set to false, one needs to eventually call
|
||||||
'';
|
|
||||||
|
|
||||||
enableLastSession = lib.nixvim.defaultNullOpts.mkBool false ''
|
|
||||||
Whether to enable the "last session" feature.
|
|
||||||
'';
|
|
||||||
|
|
||||||
rootDir = lib.nixvim.defaultNullOpts.mkStr { __raw = "vim.fn.stdpath 'data' .. '/sessions/'"; } ''
|
|
||||||
Root directory for session files.
|
|
||||||
Can be either a string or lua code (using `{__raw = 'foo';}`).
|
|
||||||
'';
|
|
||||||
|
|
||||||
createEnabled = lib.nixvim.mkNullOrOption types.bool ''
|
|
||||||
Whether to enable auto creating new sessions
|
|
||||||
'';
|
|
||||||
|
|
||||||
suppressDirs = lib.nixvim.mkNullOrOption (with types; listOf str) ''
|
|
||||||
Suppress session create/restore if in one of the list of dirs.
|
|
||||||
'';
|
|
||||||
|
|
||||||
allowedDirs = lib.nixvim.mkNullOrOption (with types; listOf str) ''
|
|
||||||
Allow session create/restore if in one of the list of dirs.
|
|
||||||
'';
|
|
||||||
|
|
||||||
useGitBranch = lib.nixvim.mkNullOrOption types.bool ''
|
|
||||||
Include git branch name in session name to differentiate between sessions for different
|
|
||||||
git branches.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
autoSave = {
|
|
||||||
enabled = lib.nixvim.defaultNullOpts.mkNullable types.bool null ''
|
|
||||||
Whether to enable auto saving session.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
autoRestore = {
|
|
||||||
enabled = lib.nixvim.defaultNullOpts.mkNullable types.bool null ''
|
|
||||||
Whether to enable auto restoring session.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
cwdChangeHandling =
|
|
||||||
lib.nixvim.defaultNullOpts.mkNullable
|
|
||||||
(
|
|
||||||
with types;
|
|
||||||
either (enum [ false ]) (submodule {
|
|
||||||
options = {
|
|
||||||
restoreUpcomingSession = lib.nixvim.defaultNullOpts.mkBool true ''
|
|
||||||
Restore session for upcoming cwd on cwd change.
|
|
||||||
'';
|
|
||||||
|
|
||||||
preCwdChangedHook = lib.nixvim.defaultNullOpts.mkLuaFn "nil" ''
|
|
||||||
lua function hook.
|
|
||||||
This is called after auto_session code runs for the `DirChangedPre` autocmd.
|
|
||||||
'';
|
|
||||||
|
|
||||||
postCwdChangedHook = lib.nixvim.defaultNullOpts.mkLuaFn "nil" ''
|
|
||||||
lua function hook.
|
|
||||||
This is called after auto_session code runs for the `DirChanged` autocmd.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
})
|
|
||||||
)
|
|
||||||
false
|
|
||||||
''
|
|
||||||
Config for handling the DirChangePre and DirChanged autocmds.
|
|
||||||
Set to `false` to disable the feature.
|
|
||||||
'';
|
|
||||||
|
|
||||||
bypassSessionSaveFileTypes = lib.nixvim.mkNullOrOption (with types; listOf str) ''
|
|
||||||
List of file types to bypass auto save when the only buffer open is one of the file types
|
|
||||||
listed.
|
|
||||||
'';
|
|
||||||
|
|
||||||
sessionLens = {
|
|
||||||
loadOnSetup = lib.nixvim.defaultNullOpts.mkBool true ''
|
|
||||||
If `loadOnSetup` is set to false, one needs to eventually call
|
|
||||||
`require("auto-session").setup_session_lens()` if they want to use session-lens.
|
`require("auto-session").setup_session_lens()` if they want to use session-lens.
|
||||||
'';
|
'';
|
||||||
|
|
||||||
themeConf = lib.nixvim.defaultNullOpts.mkAttrsOf types.anything {
|
theme_conf = defaultNullOpts.mkAttrsOf types.anything {
|
||||||
winblend = 10;
|
winblend = 10;
|
||||||
border = true;
|
border = true;
|
||||||
} "Theme configuration.";
|
} "Theme configuration.";
|
||||||
|
|
||||||
previewer = lib.nixvim.defaultNullOpts.mkBool false ''
|
previewer = defaultNullOpts.mkBool false ''
|
||||||
Use default previewer config by setting the value to `null` if some sets previewer to
|
Use default previewer config by setting the value to `null` if some sets previewer to
|
||||||
true in the custom config.
|
true in the custom config.
|
||||||
Passing in the boolean value errors out in the telescope code with the picker trying to
|
Passing in the boolean value errors out in the telescope code with the picker trying to
|
||||||
|
@ -123,61 +194,16 @@ in
|
||||||
configs if they want to.
|
configs if they want to.
|
||||||
'';
|
'';
|
||||||
|
|
||||||
sessionControl = {
|
session_control = {
|
||||||
controlDir =
|
control_dir = defaultNullOpts.mkStr { __raw = "vim.fn.stdpath 'data' .. '/auto_session/'"; } ''
|
||||||
lib.nixvim.defaultNullOpts.mkStr { __raw = "vim.fn.stdpath 'data' .. '/auto_session/'"; }
|
Auto session control dir, for control files, like alternating between two sessions
|
||||||
''
|
with session-lens.
|
||||||
Auto session control dir, for control files, like alternating between two sessions
|
'';
|
||||||
with session-lens.
|
|
||||||
'';
|
|
||||||
|
|
||||||
controlFilename = lib.nixvim.defaultNullOpts.mkStr "session_control.json" ''
|
control_filename = defaultNullOpts.mkStr "session_control.json" ''
|
||||||
File name of the session control file.
|
File name of the session control file.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config =
|
|
||||||
let
|
|
||||||
setupOptions = {
|
|
||||||
log_level = cfg.logLevel;
|
|
||||||
auto_session_enable_last_session = cfg.autoSession.enableLastSession;
|
|
||||||
auto_session_root_dir = cfg.autoSession.rootDir;
|
|
||||||
auto_session_enabled = cfg.autoSession.enabled;
|
|
||||||
auto_session_create_enabled = cfg.autoSession.createEnabled;
|
|
||||||
auto_save_enabled = cfg.autoSave.enabled;
|
|
||||||
auto_restore_enabled = cfg.autoRestore.enabled;
|
|
||||||
auto_session_suppress_dirs = cfg.autoSession.suppressDirs;
|
|
||||||
auto_session_allowed_dirs = cfg.autoSession.allowedDirs;
|
|
||||||
auto_session_use_git_branch = cfg.autoSession.useGitBranch;
|
|
||||||
cwd_change_handling =
|
|
||||||
if lib.isAttrs cfg.cwdChangeHandling then
|
|
||||||
with cfg.cwdChangeHandling;
|
|
||||||
{
|
|
||||||
restore_upcoming_session = restoreUpcomingSession;
|
|
||||||
pre_cwd_changed_hook = preCwdChangedHook;
|
|
||||||
post_cwd_changed_hook = postCwdChangedHook;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
cfg.cwdChangeHandling;
|
|
||||||
bypass_session_save_file_types = cfg.bypassSessionSaveFileTypes;
|
|
||||||
session_lens = with cfg.sessionLens; {
|
|
||||||
load_on_setup = loadOnSetup;
|
|
||||||
theme_conf = themeConf;
|
|
||||||
inherit previewer;
|
|
||||||
session_control = with sessionControl; {
|
|
||||||
control_dir = controlDir;
|
|
||||||
control_filename = controlFilename;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
} // cfg.extraOptions;
|
|
||||||
in
|
|
||||||
lib.mkIf cfg.enable {
|
|
||||||
extraPlugins = [ cfg.package ];
|
|
||||||
|
|
||||||
extraConfigLua = ''
|
|
||||||
require('auto-session').setup(${lib.nixvim.toLuaObject setupOptions})
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,44 +3,50 @@
|
||||||
plugins.auto-session.enable = true;
|
plugins.auto-session.enable = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
example = {
|
defaults = {
|
||||||
plugins.auto-session = {
|
plugins.auto-session = {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
|
||||||
logLevel = "error";
|
settings = {
|
||||||
autoSession = {
|
|
||||||
enabled = true;
|
enabled = true;
|
||||||
enableLastSession = false;
|
root_dir.__raw = ''vim.fn.stdpath "data" .. "/sessions/"'';
|
||||||
rootDir = {
|
auto_save = true;
|
||||||
__raw = "vim.fn.stdpath 'data' .. '/sessions/'";
|
auto_restore = true;
|
||||||
};
|
auto_create = true;
|
||||||
createEnabled = true;
|
suppressed_dirs = null;
|
||||||
suppressDirs = null;
|
allowed_dirs = null;
|
||||||
allowedDirs = [ ];
|
auto_restore_last_session = false;
|
||||||
useGitBranch = true;
|
use_git_branch = false;
|
||||||
};
|
lazy_support = true;
|
||||||
autoSave = {
|
bypass_save_filetypes = null;
|
||||||
enabled = true;
|
close_unsupported_windows = true;
|
||||||
};
|
args_allow_single_directory = true;
|
||||||
autoRestore = {
|
args_allow_files_auto_save = false;
|
||||||
enabled = true;
|
continue_restore_on_error = true;
|
||||||
};
|
cwd_change_handling = false;
|
||||||
cwdChangeHandling = {
|
log_level = "error";
|
||||||
restoreUpcomingSession = true;
|
session_lens = {
|
||||||
preCwdChangedHook = null;
|
load_on_setup = true;
|
||||||
postCwdChangedHook = null;
|
theme_conf = { };
|
||||||
};
|
previewer = false;
|
||||||
bypassSessionSaveFileTypes = [ ];
|
mappings = {
|
||||||
sessionLens = {
|
delete_session = {
|
||||||
loadOnSetup = true;
|
__unkeyed-1 = "i";
|
||||||
themeConf = {
|
__unkeyed-2 = "<C-D>";
|
||||||
winblend = 10;
|
};
|
||||||
border = true;
|
alternate_session = [
|
||||||
};
|
"i"
|
||||||
previewer = false;
|
"<C-S>"
|
||||||
sessionControl = {
|
];
|
||||||
controlDir = "vim.fn.stdpath 'data' .. '/auto_session/'";
|
copy_session = [
|
||||||
controlFilename = "session_control.json";
|
"i"
|
||||||
|
"<C-Y>"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
session_control = {
|
||||||
|
control_dir.__raw = ''vim.fn.stdpath "data" .. "/auto_session/"'';
|
||||||
|
control_filename = "session_control.json";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue