refactor: LazyVim.config

This commit is contained in:
Folke Lemaitre 2024-06-16 15:35:38 +02:00
parent 57ef349910
commit 05e45e0d35
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
15 changed files with 32 additions and 42 deletions

View file

@ -1,4 +1,3 @@
local Config = require("lazyvim.config")
local Float = require("lazy.view.float")
local LazyConfig = require("lazy.core.config")
local Plugin = require("lazy.core.plugin")
@ -124,7 +123,7 @@ function M.get_extra(source, modname)
imports = imports,
desc = require(modname).desc,
recommended = recommended,
managed = vim.tbl_contains(Config.json.data.extras, modname) or not enabled,
managed = vim.tbl_contains(LazyVim.config.json.data.extras, modname) or not enabled,
plugins = plugins,
optional = optional,
}
@ -169,17 +168,17 @@ function X:toggle()
return
end
extra.enabled = not extra.enabled
Config.json.data.extras = vim.tbl_filter(function(name)
LazyVim.config.json.data.extras = vim.tbl_filter(function(name)
return name ~= extra.module
end, Config.json.data.extras)
end, LazyVim.config.json.data.extras)
M.state = vim.tbl_filter(function(name)
return name ~= extra.module
end, M.state)
if extra.enabled then
table.insert(Config.json.data.extras, extra.module)
table.insert(LazyVim.config.json.data.extras, extra.module)
M.state[#M.state + 1] = extra.module
end
table.sort(Config.json.data.extras)
table.sort(LazyVim.config.json.data.extras)
LazyVim.json.save()
LazyVim.info(
"`"

View file

@ -1,5 +1,3 @@
local Config = require("lazyvim.config")
---@class lazyvim.util.json
local M = {}
@ -46,18 +44,18 @@ function M.encode(value)
end
function M.save()
Config.json.data.version = Config.json.version
LazyVim.config.json.data.version = LazyVim.config.json.version
local path = vim.fn.stdpath("config") .. "/lazyvim.json"
local f = io.open(path, "w")
if f then
f:write(LazyVim.json.encode(Config.json.data))
f:write(LazyVim.json.encode(LazyVim.config.json.data))
f:close()
end
end
function M.migrate()
LazyVim.info("Migrating `lazyvim.json` to version `" .. Config.json.version .. "`")
local json = Config.json
LazyVim.info("Migrating `lazyvim.json` to version `" .. LazyVim.config.json.version .. "`")
local json = LazyVim.config.json
-- v0
if not json.data.version then

View file

@ -30,7 +30,7 @@ function M.cmp_source(name, icon)
return {
function()
return icon or require("lazyvim.config").icons.kinds[name:sub(1, 1):upper() .. name:sub(2)]
return icon or LazyVim.config.icons.kinds[name:sub(1, 1):upper() .. name:sub(2)]
end,
cond = function()
return status() ~= nil

View file

@ -1,5 +1,3 @@
local Config = require("lazyvim.config")
---@class lazyvim.util.news
local M = {}
@ -13,13 +11,13 @@ end
function M.setup()
vim.schedule(function()
if Config.news.lazyvim then
if not Config.json.data.news["NEWS.md"] then
if LazyVim.config.news.lazyvim then
if not LazyVim.config.json.data.news["NEWS.md"] then
M.welcome()
end
M.lazyvim(true)
end
if Config.news.neovim then
if LazyVim.config.news.neovim then
M.neovim(true)
end
end)
@ -61,12 +59,12 @@ function M.open(file, opts)
end
if opts.when_changed then
local is_new = not Config.json.data.news[ref]
local is_new = not LazyVim.config.json.data.news[ref]
local hash = M.hash(file)
if hash == Config.json.data.news[ref] then
if hash == LazyVim.config.json.data.news[ref] then
return
end
Config.json.data.news[ref] = hash
LazyVim.config.json.data.news[ref] = hash
LazyVim.json.save()
-- don't open if file has never been opened
if is_new then

View file

@ -78,7 +78,7 @@ function M.foldtext()
if not ret or type(ret) == "string" then
ret = { { vim.api.nvim_buf_get_lines(0, vim.v.lnum - 1, vim.v.lnum, false)[1], {} } }
end
table.insert(ret, { " " .. require("lazyvim.config").icons.misc.dots })
table.insert(ret, { " " .. LazyVim.config.icons.misc.dots })
if not vim.treesitter.foldtext then
return table.concat(