From 407ecf00d5c7eca436c03498ffa04c03c79dc74d Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Wed, 8 May 2024 23:49:08 +0300 Subject: [PATCH] wrapper/rc: add `vim.additionaLuafiles` Allows the user to specify a list of lua files that will be called via `luafile`. All paths that are passed to this option are checked by `builtins.isPath` so attempting to source paths that do not exist do not result in a broken Lua configuration. --- docs/release-notes/rl-0.7.md | 12 ++++++---- modules/wrapper/rc/config.nix | 10 +++++++- modules/wrapper/rc/options.nix | 44 ++++++++++++++++++++++++++++++---- 3 files changed, 57 insertions(+), 9 deletions(-) diff --git a/docs/release-notes/rl-0.7.md b/docs/release-notes/rl-0.7.md index d822399..9c5d395 100644 --- a/docs/release-notes/rl-0.7.md +++ b/docs/release-notes/rl-0.7.md @@ -6,13 +6,14 @@ Release notes for release 0.7 [ItsSorae](https://github.com/ItsSorae): -- Added support for [typst](https://typst.app/) under `vim.languages.typst` - This will enable the `typst-lsp` language server, and the `typstfmt` formatter +- Added support for [typst](https://typst.app/) under `vim.languages.typst` This + will enable the `typst-lsp` language server, and the `typstfmt` formatter [frothymarrow](https://github.com/frothymarrow): -- Modified type for [](#opt-vim.visuals.fidget-nvim.setupOpts.progress.display.overrides) - from `anything` to a `submodule` for better type checking. +- Modified type for + [](#opt-vim.visuals.fidget-nvim.setupOpts.progress.display.overrides) from + `anything` to a `submodule` for better type checking. - Fix null `vim.lsp.mappings` generating an error and not being filtered out. [horriblename](https://github.com/horriblename): @@ -25,6 +26,9 @@ Release notes for release 0.7 automatically if you have autoformatting enabled, but can be disabled manually if you choose to. +- Add `vim.extraLuaFiles` for optionally sourcing additional lua files in your + configuration. + - Refactor `programs.languages.elixir` to use lspconfig and none-ls for LSP and formatter setups respectively. Diagnostics support is considered, and may be added once the [credo](https://github.com/rrrene/credo) linter has been added diff --git a/modules/wrapper/rc/config.nix b/modules/wrapper/rc/config.nix index f42f040..b50531b 100644 --- a/modules/wrapper/rc/config.nix +++ b/modules/wrapper/rc/config.nix @@ -133,6 +133,14 @@ in { configRC = { globalsScript = entryAnywhere (concatStringsSep "\n" globalsScript); + # Call additional lua files with :luafile in Vimscript + # section of the configuration, only after + # the luaScript section has been evaluated + extraLuaFiles = let + callLuaFiles = map (file: "luafile ${file}") cfg.extraLuaFiles; + in + entryAfter ["globalScript"] (concatStringsSep "\n" callLuaFiles); + # wrap the lua config in a lua block # using the wrapLuaConfic function from the lib luaScript = let @@ -148,7 +156,7 @@ in { inherit mapResult; }; in - entryAfter ["globalsScript"] luaConfig; + entryAnywhere luaConfig; extraPluginConfigs = let mapResult = result: (wrapLuaConfig { diff --git a/modules/wrapper/rc/options.nix b/modules/wrapper/rc/options.nix index 106701e..bc14241 100644 --- a/modules/wrapper/rc/options.nix +++ b/modules/wrapper/rc/options.nix @@ -37,8 +37,8 @@ in { To avoid leaking imperative user configuration into your configuration, this is enabled by default. If you wish to load configuration from user configuration directories - (e.g. `$HOME/.config/nvim`, `$HOME/.config/nvim/after` - and `$HOME/.local/share/nvim/site`) you may set this + (e.g. {file}`$HOME/.config/nvim`, {file}`$HOME/.config/nvim/after` + and {file}`$HOME/.local/share/nvim/site`) you may set this option to true. ::: ''; @@ -68,16 +68,52 @@ in { active runtimepath of the Neovim. This can be used to add additional lookup paths for configs, plugins, spell languages and other things you would generally place in - your `$HOME/.config/nvim`. + your {file}`$HOME/.config/nvim`. This is meant as a declarative alternative to throwing - files into `~/.config/nvim` and having the Neovim + files into {file}`~/.config/nvim` and having the Neovim wrapper pick them up. For more details on `vim.o.runtimepath`, and what paths to use; please see [the official documentation](https://neovim.io/doc/user/options.html#'runtimepath') ''; }; + extraLuaFiles = mkOption { + type = listOf (either path str); + default = []; + example = literalExpression '' + [ + # absolute path, as a string - impure + "$HOME/.config/nvim/my-lua-file.lua" + + # relative path, as a path - pure + ./nvim/my-lua-file.lua + + # source type path - pure and reproducible + (builtins.source { + path = ./nvim/my-lua-file.lua; + name = "my-lua-file"; + }) + ] + ''; + + description = '' + Additional lua files that will be sourced by Neovim. + Takes both absolute and relative paths, all of which + will be called via the `luafile` command in Neovim. + + See [lua-commands](https://neovim.io/doc/user/lua.html#lua-commands) + on the Neovim documentation for more details. + + ::: {.warning} + All paths passed to this option must be valid. If Neovim cannot + resolve the path you are attempting to sourcee, then your configuration + will error, and Neovim will not start. Please ensure that all paths + are correct before using this option. + ::: + ''; + }; + globals = mkOption { type = attrs; default = {};