peter-bread / peter.nvim

My Neovim Config
1 stars 0 forks source link

Merging Test #23

Open peter-bread opened 3 months ago

peter-bread commented 3 months ago

Test out looping through files in a directory and using vim.tbl_deep_extend to merge them, e.g. some lsp configs and formatter setup (using vim.list_extend).

If this works, then I can use vim.g to store configs for plugins and also mirror the opts merging from lazy.nvim to potentially be used with vim plug.

peter-bread commented 3 months ago
local t1 = {
  servers = {
    lua_ls = {
      inlay_hints = true,
    },
    vtsls = {},
  },
}

local t2 = {
  servers = {
    gopls = {},
    lua_ls = {
      inlay_hints = false,
    },
  },
}

local t3 = vim.tbl_deep_extend("force", t1, t2)

print(vim.inspect(t1))
print(vim.inspect(t2))
print(vim.inspect(t3))
-- t1
{
  servers = {
    lua_ls = {
      inlay_hints = true
    },
    vtsls = {}
  }
}

-- t2
{
  servers = {
    gopls = {},
    lua_ls = {
      inlay_hints = false
    }
  }
}

-- t3
{
  servers = {
    gopls = {},
    lua_ls = {
      inlay_hints = false
    },
    vtsls = {}
  }
}
peter-bread commented 3 weeks ago

If using a plugin that uses vim.g for config, you can still use opts for merging configs, then have:

config = function(opts)
  vim.g.my_plugin_config = opts
end

in your lazy plugin spec.