Replies: 4 comments
-
AnswerYes, this is a limitation of the current impl. Currently, unkeyed attrs are merged in the same way as any other attr-set, so Note that the indexes don't necessarily have to be sequential, you could have one definition using indexes 1-10, while another definition uses indexes 100-110, for example. State of nixvimIn the vast majority of nixvim options, lua is typed as The two ways we could go about it are:
For some additional context, there's a parallel effort for serialising lua in nixpkgs. Nixvim uses lua serialisation in nixvim vs nixpkgsEventually, I'd like to upstream nixvim-specific serialisation features into nixpkgs, however currently some things are done differently:
I've been brainstorming about a replacement for
I have a nixpkgs/table branch where I was playing with this. Feedback or ideas welcome. |
Beta Was this translation helpful? Give feedback.
-
Ha! So, full disclosure, I'm not actually trying to merge unkeyed attrs in nixvim. I actually was researching how y'all handled that problem, because I've got a similar problem trying to add |
Beta Was this translation helpful? Give feedback.
-
Nice. You can definitely learn from our mistakes 😁 Prior art for a mixed data type includes:
I believe the best way to go about this is to first settle on a structure to represent the mixed data, then create some util functions for working with that structure, and finally implement an option-type for it. Other steps would include adding support to the relevant My draft branch has done steps 1 & 2, and has a sketched out option-type for step 3 (I believe the merge function may not be handling all edge cases yet; tests needed). Maybe I'll start a PR for steps 1&2 and postpone the option-type for a dedicated PR? Regarding the data structure itself: the first question is does it need a The second question is should the named elements be at the top-level, or nested in a separate The third question is should the unnamed elements be in a Personally I believe nixvim's approach of using special I'm unsure whether it's better to have the named elements as top-level attrs or nest them under a
Sounds good 👍 |
Beta Was this translation helpful? Give feedback.
-
That sounds reasonable to me!
One thing to consider is if it's important to be able to preserve insertion order across mixed values. I believe lua intentionally does not preserve this information, but if we're trying to build a general mixed data type, we might need to? In other words, I believe these two lua tables are identical: local t1 = { "first", second = 2, "third" }
local t2 = { "first", "third", second = 2 }But I believe these 2 PHP arrays are "different" (PHP seems to remember insertion order): php > print_r(array("first", "second" => 2, "third"));
Array
(
[0] => first
[second] => 2
[1] => third
)
php > print_r(array("first", "third", "second" => 2));
Array
(
[0] => first
[1] => third
[second] => 2
)While it might be weird for a configuration file to have semantics that depend on this order, I think ideally we would build something that can represent this. If we take that as a design constraint, then I think the most natural representation is a list of |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm curious how to merge multiple
listToUnkeyedAttrs. For example:Ideally, I would want the resulting lua table to be:
{ "a", "b", "c", "d", foo = "bar" }It feels like this is a fundamental issue with how
listToUnkeyedAttrsrepresents unkeyed attrs:Have we considered one of the following?
lib.nixvim.listToUnkeyedAttrsto represent unkeyed attrs in a different way? For example, rather than injecting integer indices into the keys, we could inject the value.--unkeyed-<N>attrs specially.Beta Was this translation helpful? Give feedback.
All reactions