Commit graph

225 commits

Author SHA1 Message Date
psfloyd
6c1e87676c maintainers: add psfloyd 2024-08-06 22:58:32 -03:00
Matt Sturgeon
27c4c9c210
lib/modules: init with specialArgs helpers 2024-08-02 14:38:38 +01:00
Matt Sturgeon
491ca5cf51
lib: provide an "extended lib" to our modules
lib/extend-lib.nix returns a nixpkg's lib extended with our own
helpers.

This is exposed as `helpers.extendedLib`, but when evaluating our
modules it should be assigned to `specialArgs.lib`.

Outside of our modules you must still access our helpers via
`config.lib.nixvim` or `config.lib.nixvim.extendedLib`.

Within helpers' sub-sections, `lib` is the extended lib.
2024-08-02 14:33:59 +01:00
Matt Sturgeon
7c39d77b9f
lib/helpers: scope each subsection, but offer aliases 2024-08-01 18:05:00 +01:00
Matt Sturgeon
bc84fda2b8
lib/options: remove with helpers 2024-08-01 17:55:03 +01:00
Stanislav Asunkin
44849233e0 modules/performance: add ability to byte compile lua configuration files
This commit adds support for byte compiling lua configuration files.
It's enabled by default (if byte compiling is enabled at all) and can be
disabled with `performance.byteCompileLua.configs` toggle.

To implement this feature `extraFiles.<name>.finalSource` internal
read-only option is introduced. `source` option cannot be used because
it's user configurable. In order to access the values of the
`performance.byteCompileLua` options, parent config is added to
specialArgs of extraFiles submodule. Then the usages of `source` option
changed to `finalSource` in all relevant places (filesPlugin and
wrappers).

Added more helpers for various cases of byte compiling:

* `byteCompileLuaFile` byte compiles lua file
* `byteCompileLuaHook` is a setup hook that byte compiles all lua files
* `byteCompileLuaDrv` overrides derivation by adding byteCompileLuaHook
  to it

Added tests to validate that extraFiles specified by various methods are
handled correctly. Added a separate home-manager test, that is intended
to validate that extraFiles propagated to wrapper modules are correctly
byte compiled.
2024-07-31 11:31:40 +00:00
Stanislav Asunkin
17e8904992 modules/performance: add performance.byteCompileLua option
* add `performance.byteCompileLua.enable` toggle to enable or disable
  all byte compiling features
* add `performance.byteCompileLua.initLua` toggle to enable or
  disable byte compiling of init.lua
* add `writeByteCompiledLua` helper for saving byte compiled lua source
  code to the nix store
* `nixvim-print-init` utility is always pointed to uncompiled init.lua
* add tests
2024-07-31 11:31:40 +00:00
Matt Sturgeon
040bab5f55
lib/helpers: call with auto-args
Define `call = callPackageWith { inherit pkgs lib helpers; }`, which can
be used to automatically pass the correct args into helpers files.

`helpers` is passed in recursively.
2024-07-28 22:51:24 +01:00
Matt Sturgeon
0e98d9cf1e
lib/helpers: build recursively 2024-07-28 22:30:11 +01:00
GGORG
230f95eae0 maintainers: add GGORG 2024-07-25 13:40:08 +02:00
Nathan Felber
a1bd7aebc6
maintainers: add NathanFelber 2024-07-24 10:15:51 +01:00
Stanislav Asunkin
9317537848 modules: avoid setting empty strings to extraConfig* options
Problem:  Some modules are setting empty strings to extraConfig* options
          with the intention to not generate any config. But empty
          strings are also values, so they are still concatenated in the
          final value of extraConfig* options. This results in a
          multiple empty strings in extraConfigs.

Solution: Avoid using optionalString when setting values to extraConfig*
          options. Use mkIf instead.

          This commit also fixes mkIf condition in autocmd module.

          `mkNeovimPlugin` is a special case. To avoid evaluating
          caller's arguments mkMerge/optionalAttrs pattern is used
          instead.
2024-07-22 23:18:53 +02:00
Stanislav Asunkin
299d0406bb modules/output: refactor config generation
The motivation for this change was to avoid generating empty
config sections like

    vim.cmd([[

    ]])

To make a config generation cleaner several helper functions introduced:

* `hasContent` have been moved to helpers
* `concatNonEmptyLines` joins strings (which has content) separated with
  newlines
* `wrapVimscriptForLua` wraps a lua string for using in Vimscript, but
  only if the string has content, otherwise empty string is returned
* `wrapLuaForVimscript` wraps Vimscript for using in lua, but only if
  the string has content, otherwise empty string is returned

Added tests:

* testing that all possible config sections are present in the final
  generated config
* testing that the config files generated by empty `files` definitions
  don't have any content in it
2024-07-22 23:18:53 +02:00
Matt Sturgeon
6dc0bda459
lib/to-lua: handle derivations as path strings
Fixes #1888
2024-07-22 13:24:16 +01:00
Matt Sturgeon
497ce47593
maintainers: remove MattSturgeon 2024-07-10 09:18:17 +01:00
Matt Sturgeon
0e8b248a52
lib/options: allow rawLua in mkEnum' default 2024-07-08 17:48:00 +01:00
Matt Sturgeon
1b7efacdf4
wrappers: bootstrap "helpers" directly
We don't need to pass a `getHelpers` function in, since we can just
import `../lib/helpers.nix`.
2024-07-08 16:24:06 +01:00
Gaetan Lepage
6055d0f28c lib/types: allow emptyTable as a valid rawLua value 2024-07-08 10:21:49 +02:00
Matt Sturgeon
c12694f4ba
lib/deprecation: add transitionType
Based on `types.coerceTo`, which is like `types.either` but coerces the
left-hand type into the right-hand type.

`transitionType` only shows the right-hand type in its description and
also prints a warning when the left-hand type is used.

Co-authored-by: Silvan Mosberger <contact@infinisil.com>
2024-07-07 16:02:37 +01:00
Matt Sturgeon
843fb302eb
lib/neovim-plugin: allow disabling installPackage
Some plugins may wish to handle package installation themselves.
2024-07-06 13:01:07 +01:00
Matt Sturgeon
9b25eaaa6f
lib/to-lua: fix removing empties nested in lists
- Add options for removing empty/null list entries (default false)
- Fix recursion into attrs that are themselves list entries

Fixes #1804
2024-07-03 16:44:30 +01:00
Matt Sturgeon
b0d8c00264
lib/vim-plugin: fix + improve settings example
`foo_bar = true` -> `${prefix}foo_bar=1` is incorrect and confusing.

See related issue #1741
2024-06-29 00:09:43 +01:00
Matt Sturgeon
039f6c1973
lib/lua: workaround builtins.match alias issue
It seems that `with lib` isn't (always) bringing `match` into scope
Odd, but we can fix by explicitly using `builtins.match`.
2024-06-28 23:59:39 +01:00
Matt Sturgeon
7c35bdb3f7
lib/neovim-plugin: allow overriding settings description
- The `setup` function name can be overridden with `setup`
  (default ".setup")
- The entire `settings` option description can be overridden with
  `settingsDescription`
- `luaName` and `setup` are used in the default description
2024-06-28 22:58:31 +01:00
Matt Sturgeon
c351c175ec
lib/neovim-plugin: support not having settings
Allow callers to explicitly set `settingsOptions = null` to disable
creating the `settings` option.

`settingsOptions` still defaults to `{ }`.
2024-06-28 22:58:30 +01:00
Matt Sturgeon
aff12581d8
lib/lua: refactor toLuaObject, now configurable
Heavily based on nixpkgs lib.generators.toPretty
2024-06-28 22:44:43 +01:00
Jamis Hartley
479430c2d8 maintainers: add sheemap 2024-06-28 01:09:46 +01:00
Matt Sturgeon
53a9599cc4
lib/lua: pad table , with a space
Makes toLuaObject's output a little more readable.
2024-06-26 12:35:47 +01:00
Matt Sturgeon
00ce71f51a
lib/lua: only quote table keys when needed 2024-06-26 12:31:05 +01:00
Matt Sturgeon
01cf43dbaa
lib/lua: add isKeyword and isIdentifier
Allow testing whether a string is a valid lua identifier or a reserved
keyword.
2024-06-26 11:40:52 +01:00
Matt Sturgeon
54d118869b
lib/deprecation: init with mkDeprecatedSubOptionModule
Similar to `lib.mkRemovedOptionModule` but tweaked to work with
sub-options (e.g. settings options).

Also uses warnings instead of assertions.
2024-06-25 15:48:33 +01:00
Nikita Shirokov
54207d1eff maintainers: add braindefender 2024-06-22 07:13:11 +07:00
Matt Sturgeon
9000e69f4b
lib/options: drop special case for string defaults
No longer assume that string-type plugin defaults are already
pre-formatted.

Instead, pre-formatted values should be defined using
`literalExpression` or `literalMD`.
2024-06-21 08:45:30 +01:00
Gaetan Lepage
735fbeece8 Revert "helpers/vim-plugin: fix mkVimPlugin when defaultPackage.meta.homepage doesn't exist"
This reverts commit a6b247359f.
2024-06-21 08:53:33 +02:00
Gaetan Lepage
846b3c991e helpers/vim-plugin: fix mkVimPlugin when defaultPackage.meta.homepage doesn't exist 2024-06-18 11:38:52 +02:00
Matt Sturgeon
36b4a39b2b
lib/types: allow assigning raw lua to string lua
Relax the check a little to allow (slightly) incorrect usage and enable migrating option types to string lua types.
2024-06-17 00:01:40 +01:00
Matt Sturgeon
2d063c2c24
lib/types: simplify isRawType
No change in behaviour.
2024-06-17 00:01:39 +01:00
Matt Sturgeon
69e43a6bf9
plugins/none-ls: refactor mkRaw
- Allow passing raw types through mkRaw
- Throw an error when passing invalid input into mkRaw
2024-06-17 00:01:39 +01:00
Matt Sturgeon
582641a639
lib/options: fix minor typo 2024-06-14 12:29:53 +01:00
Matt Sturgeon
8e8c22ce65
lib/options: rename convertArgs to processDefaultNullArgs 2024-06-14 12:28:59 +01:00
Matt Sturgeon
5cec79e59f
lib/options: migrate defaultNullOpts to use pluginDefault
Rename all instances where the plugin default argument is named
`default` to `pluginDefault` to avoid conflict.
2024-06-14 12:25:06 +01:00
Matt Sturgeon
e51b8b9b5c
lib/options: remove defaultNullOpts.mkDesc
Leave a stub for now, which aborts with an error message.
2024-06-14 10:56:11 +01:00
Matt Sturgeon
a8943f2502
lib/options: allow pluginDefault in any helper
All helpers eventually go through `mkNullOrOption`, so we can move where
`pluginDefault` is handled there.

Added a private helper `processNixvimArgs` that can be used by any future
helper that needs to call `lib.mkOption` directly.

It might make sense to offer a `helpers.mkOption` which simply wraps
`lib.mkOption` but with support for custom args like `pluginDefault`?
2024-06-14 10:49:05 +01:00
Matt Sturgeon
33a32c9417
lib/options: move "plugin default" into defaultText
Introduce a new `helpers.pluginDefaultText` and deprecate `helpers.defaultNullOpts.mkDesc`.

Displaying the "plugin default" within `defaultText` ensures that both
defaults are grouped together in the docs.

Also take the first step towards transitioning `defaultNullOpts` from
using `default` to `pluginDefault` to mean "plugin default".
2024-06-10 15:11:21 +01:00
Matt Sturgeon
f34fda8d99
meta: extend meta.nixvimInfo support treewide
Rather than supplying a `kind` and `name` pair, we now supply a raw
path.

This path could point to any nixvim option.
2024-06-07 22:22:55 +01:00
Matt Sturgeon
b2a477260d
docs: emphasise "Plugin default" to match nixpkgs
Nixpkg's "headings" are emphasised in italics ("Default", "Example",
"Type", etc). We should match the style.
2024-06-07 17:47:33 +01:00
Matt Sturgeon
ade4539b3f
lib/options: defaultNullOpts don't require having a default
Made the `default` and `description` arguments optional for all prime
variants of `defaultNullOpts` functions.

If neither `default` nor `description` are provided, the option will
have no description.

The "Plugin default" line is only added when a `default` argument is
present (`args ? default`).
2024-06-07 17:34:46 +01:00
Matt Sturgeon
302262304e
lib/keymaps: refactor mkMapOptionSubmodule again
Allow passing in `key` and `action` as either bool or an attrset.

If `false`, the option is omitted. If `true` or an attrset, the option is included.
If an attrset is used, it will update the default `mkOption` args.
This is useful for overriding `type` or adding an `example`.
2024-06-07 15:42:54 +01:00
Matt Sturgeon
c16533b3f7
lib: add upperFirstChar
A util function to capitalize the first character of a string.
2024-06-07 09:17:29 +01:00
Matt Sturgeon
f7e009d29e
lib/options: add mkEnum' argument assertions 2024-06-02 03:18:11 +01:00