Skip to content

Merge variable tables instead of bailing - #64

Closed
runiq wants to merge 1 commit into
SuperCuber:masterfrom
runiq:merge-tables
Closed

runiq wants to merge 1 commit into
SuperCuber:masterfrom
runiq:merge-tables

Conversation

@runiq

@runiq runiq commented May 19, 2021

Copy link
Copy Markdown

This allows to have nested tables for variables.

I'm using it in my Neovim config to do some package-specific configuration if (and only if) a package is enabled:

# global.toml
[rustdev.variables]
neovim.subpackages.rustdev = true
[luadev.variables]
neovim.subpackages.luadev = true

With this, I can loop over the neovim.subpackages variable and do something for all enabled packages only鈥攍ike run some package-specific code:

-- subpackages.lua
local subpackages = {
  {{#each neovim.subpackages}}
  '{{@key}}',
  {{/each}}
}
for _, subpackage in ipairs(subpackages) do
  require(subpackage)

Now, if I decide to disable the luadev package, I won't have to change subpackages.lua in any way鈥攕ince the variable neovim.subpackages.luadev doesn't exist anymore, it won't be in the subpackages list.

I'm pretty sure this would enable other functionality as well, considering the power of the handlebars templating facility.

@runiq

runiq commented May 19, 2021

Copy link
Copy Markdown
Author

So I figured out how to do what I want to do without this PR. If you want it anyways, I could still keep it open, though? Your call. :)

@SuperCuber

Copy link
Copy Markdown
Owner

Hey, the CI went through some changes to make sure it works for older versions of Linux. Please merge the changes from master to your branch and re-run the CI (I might need to re-approve it)

This allows to have nested tables for variables.
@runiq

runiq commented May 21, 2021 •

Copy link
Copy Markdown
Author

Done! (Edit: And yeah, looks like you need to re-approve)

Comment thread src/config.rs
}
}

/// Merge two TOML tables

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function already exists:

fn recursive_extend_map(

You should either rewrite the below code to use it or rewrite the code that uses that function to use this instead

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wow, I'm sorry, how did I not notice that? Will do, thank you!

@LucasOe

LucasOe commented Jun 25, 2022

Copy link
Copy Markdown

I created a fix for this issue. Is there any way I can add to this pull request, or do I have to create a new one?

@SuperCuber

Copy link
Copy Markdown
Owner

I created a fix for this issue. Is there any way I can add to this pull request, or do I have to create a new one?

I think you need to create a new one. For bonus points, add a test that fails without the fix and passes with the fix :)

@SuperCuber

Copy link
Copy Markdown
Owner

Closed, see #102

@SuperCuber SuperCuber closed this Jun 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants