Commit graph

24 commits

Author SHA1 Message Date
Matt Sturgeon
f4a7447d27
lib/util: move docs from lib/index to doc-comments
Moved all function-specific docs from `docs/lib/index.md` into RFC145
doc-comments.

Added `lib.nixvim.lua.toLuaObject` to hold the public docs and serve as
a stable impl of `toLua'` in case we decide to change its defaults.
2025-05-19 00:23:21 +01:00
Matt Sturgeon
5cf8cb5ee6
lib/utils: split into public and internal files
We will include the public file in the docs.
2025-05-19 00:23:20 +01:00
Matt Sturgeon
e6e5369535
lib/utils: fix literalLua multiline rendering
`lib.generators.toPretty` has bespoke handling for rendering nix strings
using either the `" "` or `'' ''` syntax, based on some heuristics.

Using `toPretty` instead of `toJSON` improves how literal-lua examples
render in the docs.
2025-04-24 19:07:34 +01:00
Gaetan Lepage
abba4af10b lib/utils: fix typo in example of mkAssertions 2025-01-29 15:05:42 +01:00
Gaetan Lepage
a7e516b322 lib/utils: add mkAssertions 2025-01-20 14:17:26 +01:00
Gaetan Lepage
02e16b2a76 lib/utils: add mkWarnings 2025-01-20 12:25:33 +00:00
Gaetan Lepage
1d50fa4f63 lib: add applyPrefixToAttrs 2024-12-17 21:40:20 +00:00
Matt Sturgeon
da6e3499d4
lib/utils: add nestedLiteral and nestedLiteralLua
`nestedLiteral` converts a `literalExpression` into a `toPretty` style
pretty-printer.

`nestedLiteralLua` composes `nestedLiteral` and `literalLua` together.
2024-11-15 21:46:25 +00:00
Matt Sturgeon
eb76e62a9b
lib/utils: add literalLua for use in option docs
Creates a `literalExpression` equivalent to using `lib.nixvim.mkRaw`.
2024-11-15 21:46:25 +00:00
Matt Sturgeon
cd76b4feb8
lib: remove helpers from internal usage 2024-09-29 14:41:41 +01:00
Quentin Boyer
d2f9e011d9 lib/neovim-plugin: Add lua configuration scoped to the plugin
This commit adds a `plugins.<name>.luaConfig` section controlling the
plugin specific configuration.

The section contains the internal `init` option, containing the plugin's
initialization code.

It also contains the public `pre` and `post` options, that allow to add
code before & after the `init` section

Finally, it contains the `final` option, being the concatenation of the
three previous options.
2024-09-22 16:15:27 +00:00
Jeremy Fleischman
400d1d927d
lib: fix escaping bugs in wrapVimscriptForLua and wrapLuaForVimscript
These functions had very similar bugs: they didn't check if their chosen
"close token" was already present in the string they're escaping.

I went ahead and did the work implied by the TODOs: search for a "close
token" that is *not* in the original string. Pretty simple concept, but
it turned into an annoying amount of code. I couldn't find anything in
upstream nixpkgs lib, or some clever insight about lua/vimscript that
makes this work unecessary, but I'll be thrilled (and a little bummed
about a wasted afternoon) to learn about something.
2024-09-19 15:41:46 -07:00
Austin Horstman
35788bbc5a
lib: cleanup with lib 2024-09-03 22:12:33 -05:00
Matt Sturgeon
b7f419a759
lib: migrate helpers.nixvimTypes -> lib.types 2024-08-21 07:37:11 +01:00
Matt Sturgeon
8f99c3953c
lib/util: add groupListBySize
Splits up a list into many sub-lists based on the given max-size.

e.g.
```nix
groupListBySize 2 [ 1 2 3 4 5 ]
=> [ [ 1 2 ] [ 3 4 ] [ 5 ] ]
```
2024-08-19 00:50:57 +01:00
Matt Sturgeon
0e98d9cf1e
lib/helpers: build recursively 2024-07-28 22:30:11 +01: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
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
c16533b3f7
lib: add upperFirstChar
A util function to capitalize the first character of a string.
2024-06-07 09:17:29 +01:00
Gaetan Lepage
0ba2ea5416 helpers: add rawKeysAttrs 2024-05-31 21:53:40 +02:00
traxys
62f32bfc71 treewide: Reformat with nixfmt 2024-05-05 22:00:40 +02:00
traxys
6d7e429537
tests: Introduce a way to disable options when running in tests (#1095)
In our basic template we used to provide a check based on
`mkTestDerivationFromNvim`. The issue with this check (that is handled
correctly internally) is that some plugins _can't_ be used in the test
environment, for example image.nvim like in #1085.

This commit introduces a new function to generate such checks,
`mkTestDerivationFromNixvimModule`, that wraps a nixvim configuration
instead of a built nvim instance.

Then a configuration can rely on the newly added
`helpers.enableExceptInTests` attribute to disable parts of the
configuration depending if it is evaluated in tests or in a real final
configuration.

Resolves #1085
2024-02-15 14:27:45 +01:00
Gaetan Lepage
89cac08ac7 helpers: add toSnakeCase converter 2024-02-02 10:50:35 +01:00
Gaetan Lepage
7164a89f72 lib/helpers: factor out nixvimUtils 2024-01-25 17:05:03 +01:00