Skip to content

Commit

Permalink
wrapper/rc: add vim.additionaLuafiles
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
NotAShelf committed May 8, 2024
1 parent 7c1a8e2 commit 407ecf0
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 9 deletions.
12 changes: 8 additions & 4 deletions docs/release-notes/rl-0.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand Down
10 changes: 9 additions & 1 deletion modules/wrapper/rc/config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -148,7 +156,7 @@ in {
inherit mapResult;
};
in
entryAfter ["globalsScript"] luaConfig;
entryAnywhere luaConfig;

extraPluginConfigs = let
mapResult = result: (wrapLuaConfig {
Expand Down
44 changes: 40 additions & 4 deletions modules/wrapper/rc/options.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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.
:::
'';
Expand Down Expand Up @@ -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 = {};
Expand Down

0 comments on commit 407ecf0

Please sign in to comment.