mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-06-28 03:30:12 +02:00
feat: use LazyVim everywhere instead of require("lazyvim.util")
This commit is contained in:
parent
3a87c08cda
commit
7a5dbeae75
41 changed files with 188 additions and 229 deletions
|
@ -3,7 +3,6 @@ local Float = require("lazy.view.float")
|
|||
local LazyConfig = require("lazy.core.config")
|
||||
local Plugin = require("lazy.core.plugin")
|
||||
local Text = require("lazy.view.text")
|
||||
local Util = require("lazyvim.util")
|
||||
|
||||
---@class LazyExtraSource
|
||||
---@field name string
|
||||
|
@ -39,9 +38,9 @@ function M.get()
|
|||
M.state = M.state or LazyConfig.spec.modules
|
||||
local extras = {} ---@type LazyExtra[]
|
||||
for _, source in ipairs(M.sources) do
|
||||
local root = Util.find_root(source.module)
|
||||
local root = LazyVim.find_root(source.module)
|
||||
if root then
|
||||
Util.walk(root, function(path, name, type)
|
||||
LazyVim.walk(root, function(path, name, type)
|
||||
if (type == "file" or type == "link") and name:match("%.lua$") then
|
||||
name = path:sub(#root + 2, -5):gsub("/", ".")
|
||||
local ok, extra = pcall(M.get_extra, source, source.module .. "." .. name)
|
||||
|
@ -119,7 +118,7 @@ function X:toggle()
|
|||
for _, extra in ipairs(self.extras) do
|
||||
if extra.row == pos[1] then
|
||||
if not extra.managed then
|
||||
Util.error(
|
||||
LazyVim.error(
|
||||
"Not managed by LazyExtras. Remove from your config to enable/disable here.",
|
||||
{ title = "LazyExtras" }
|
||||
)
|
||||
|
@ -137,8 +136,8 @@ function X:toggle()
|
|||
M.state[#M.state + 1] = extra.module
|
||||
end
|
||||
table.sort(Config.json.data.extras)
|
||||
Util.json.save()
|
||||
Util.info(
|
||||
LazyVim.json.save()
|
||||
LazyVim.info(
|
||||
"`"
|
||||
.. extra.name
|
||||
.. "`"
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
local Util = require("lazyvim.util")
|
||||
|
||||
---@class lazyvim.util.format
|
||||
---@overload fun(opts?: {force?:boolean})
|
||||
local M = setmetatable({}, {
|
||||
|
@ -26,7 +24,7 @@ function M.register(formatter)
|
|||
end
|
||||
|
||||
function M.formatexpr()
|
||||
if Util.has("conform.nvim") then
|
||||
if LazyVim.has("conform.nvim") then
|
||||
return require("conform").formatexpr()
|
||||
end
|
||||
return vim.lsp.formatexpr({ timeout_ms = 3000 })
|
||||
|
@ -76,7 +74,7 @@ function M.info(buf)
|
|||
if not have then
|
||||
lines[#lines + 1] = "\n***No formatters available for this buffer.***"
|
||||
end
|
||||
Util[enabled and "info" or "warn"](
|
||||
LazyVim[enabled and "info" or "warn"](
|
||||
table.concat(lines, "\n"),
|
||||
{ title = "LazyFormat (" .. (enabled and "enabled" or "disabled") .. ")" }
|
||||
)
|
||||
|
@ -120,14 +118,14 @@ function M.format(opts)
|
|||
for _, formatter in ipairs(M.resolve(buf)) do
|
||||
if formatter.active then
|
||||
done = true
|
||||
Util.try(function()
|
||||
LazyVim.try(function()
|
||||
return formatter.format(buf)
|
||||
end, { msg = "Formatter `" .. formatter.name .. "` failed" })
|
||||
end
|
||||
end
|
||||
|
||||
if not done and opts and opts.force then
|
||||
Util.warn("No formatter available", { title = "LazyVim" })
|
||||
LazyVim.warn("No formatter available", { title = "LazyVim" })
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -136,7 +134,7 @@ function M.health()
|
|||
local has_plugin = Config.spec.plugins["none-ls.nvim"]
|
||||
local has_extra = vim.tbl_contains(Config.spec.modules, "lazyvim.plugins.extras.lsp.none-ls")
|
||||
if has_plugin and not has_extra then
|
||||
Util.warn({
|
||||
LazyVim.warn({
|
||||
"`conform.nvim` and `nvim-lint` are now the default formatters and linters in LazyVim.",
|
||||
"",
|
||||
"You can use those plugins together with `none-ls.nvim`,",
|
||||
|
|
|
@ -38,7 +38,7 @@ setmetatable(M, {
|
|||
if dep then
|
||||
local mod = type(dep) == "table" and dep[1] or dep
|
||||
local key = type(dep) == "table" and dep[2] or k
|
||||
M.deprecate([[require("lazyvim.util").]] .. k, [[require("lazyvim.util").]] .. mod .. "." .. key)
|
||||
M.deprecate([[LazyVim.]] .. k, [[LazyVim.]] .. mod .. "." .. key)
|
||||
---@diagnostic disable-next-line: no-unknown
|
||||
t[mod] = require("lazyvim.util." .. mod) -- load here to prevent loops
|
||||
return t[mod][key]
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
local Config = require("lazyvim.config")
|
||||
local Util = require("lazyvim.util")
|
||||
|
||||
---@class lazyvim.util.json
|
||||
local M = {}
|
||||
|
@ -14,7 +13,7 @@ local function encode(value, indent)
|
|||
elseif t == "number" or t == "boolean" then
|
||||
return tostring(value)
|
||||
elseif t == "table" then
|
||||
local is_list = Util.is_list(value)
|
||||
local is_list = LazyVim.is_list(value)
|
||||
local parts = {}
|
||||
local next_indent = indent .. " "
|
||||
|
||||
|
@ -51,13 +50,13 @@ function M.save()
|
|||
local path = vim.fn.stdpath("config") .. "/lazyvim.json"
|
||||
local f = io.open(path, "w")
|
||||
if f then
|
||||
f:write(Util.json.encode(Config.json.data))
|
||||
f:write(LazyVim.json.encode(Config.json.data))
|
||||
f:close()
|
||||
end
|
||||
end
|
||||
|
||||
function M.migrate()
|
||||
Util.info("Migrating `lazyvim.json` to version `" .. Config.json.version .. "`")
|
||||
LazyVim.info("Migrating `lazyvim.json` to version `" .. Config.json.version .. "`")
|
||||
local json = Config.json
|
||||
|
||||
-- v0
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
local Util = require("lazyvim.util")
|
||||
|
||||
---@class lazyvim.util.lsp
|
||||
local M = {}
|
||||
|
||||
|
@ -87,10 +85,10 @@ function M.formatter(opts)
|
|||
primary = true,
|
||||
priority = 1,
|
||||
format = function(buf)
|
||||
M.format(Util.merge({}, filter, { bufnr = buf }))
|
||||
M.format(LazyVim.merge({}, filter, { bufnr = buf }))
|
||||
end,
|
||||
sources = function(buf)
|
||||
local clients = M.get_clients(Util.merge({}, filter, { bufnr = buf }))
|
||||
local clients = M.get_clients(LazyVim.merge({}, filter, { bufnr = buf }))
|
||||
---@param client lsp.Client
|
||||
local ret = vim.tbl_filter(function(client)
|
||||
return client.supports_method("textDocument/formatting")
|
||||
|
@ -102,7 +100,7 @@ function M.formatter(opts)
|
|||
end, ret)
|
||||
end,
|
||||
}
|
||||
return Util.merge(ret, opts) --[[@as LazyFormatter]]
|
||||
return LazyVim.merge(ret, opts) --[[@as LazyFormatter]]
|
||||
end
|
||||
|
||||
---@alias lsp.Client.format {timeout_ms?: number, format_options?: table} | lsp.Client.filter
|
||||
|
@ -113,8 +111,8 @@ function M.format(opts)
|
|||
"force",
|
||||
{},
|
||||
opts or {},
|
||||
require("lazyvim.util").opts("nvim-lspconfig").format or {},
|
||||
require("lazyvim.util").opts("conform.nvim").format or {}
|
||||
LazyVim.opts("nvim-lspconfig").format or {},
|
||||
LazyVim.opts("conform.nvim").format or {}
|
||||
)
|
||||
local ok, conform = pcall(require, "conform")
|
||||
-- use conform for formatting with LSP when available,
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
local Util = require("lazyvim.util")
|
||||
|
||||
---@class lazyvim.util.lualine
|
||||
local M = {}
|
||||
|
||||
|
@ -25,9 +23,9 @@ function M.cmp_source(name, icon)
|
|||
end
|
||||
|
||||
local colors = {
|
||||
ok = Util.ui.fg("Special"),
|
||||
error = Util.ui.fg("DiagnosticError"),
|
||||
pending = Util.ui.fg("DiagnosticWarn"),
|
||||
ok = LazyVim.ui.fg("Special"),
|
||||
error = LazyVim.ui.fg("DiagnosticError"),
|
||||
pending = LazyVim.ui.fg("DiagnosticWarn"),
|
||||
}
|
||||
|
||||
return {
|
||||
|
@ -90,8 +88,8 @@ function M.pretty_path(opts)
|
|||
return ""
|
||||
end
|
||||
|
||||
local root = Util.root.get({ normalize = true })
|
||||
local cwd = Util.root.cwd()
|
||||
local root = LazyVim.root.get({ normalize = true })
|
||||
local cwd = LazyVim.root.cwd()
|
||||
|
||||
if opts.relative == "cwd" and path:find(cwd, 1, true) == 1 then
|
||||
path = path:sub(#cwd + 2)
|
||||
|
@ -130,12 +128,12 @@ function M.root_dir(opts)
|
|||
parent = true,
|
||||
other = true,
|
||||
icon = " ",
|
||||
color = Util.ui.fg("Special"),
|
||||
color = LazyVim.ui.fg("Special"),
|
||||
}, opts or {})
|
||||
|
||||
local function get()
|
||||
local cwd = Util.root.cwd()
|
||||
local root = Util.root.get({ normalize = true })
|
||||
local cwd = LazyVim.root.cwd()
|
||||
local root = LazyVim.root.get({ normalize = true })
|
||||
local name = vim.fs.basename(root)
|
||||
|
||||
if root == cwd then
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
local Config = require("lazyvim.config")
|
||||
local Util = require("lazyvim.util")
|
||||
|
||||
---@class lazyvim.util.news
|
||||
local M = {}
|
||||
|
@ -27,7 +26,7 @@ function M.setup()
|
|||
end
|
||||
|
||||
function M.welcome()
|
||||
Util.info("Welcome to LazyVim!")
|
||||
LazyVim.info("Welcome to LazyVim!")
|
||||
end
|
||||
|
||||
function M.changelog()
|
||||
|
@ -50,7 +49,7 @@ function M.open(file, opts)
|
|||
if opts.plugin then
|
||||
local plugin = require("lazy.core.config").plugins[opts.plugin] --[[@as LazyPlugin?]]
|
||||
if not plugin then
|
||||
return Util.error("plugin not found: " .. opts.plugin)
|
||||
return LazyVim.error("plugin not found: " .. opts.plugin)
|
||||
end
|
||||
file = plugin.dir .. "/" .. file
|
||||
elseif opts.rtp then
|
||||
|
@ -58,7 +57,7 @@ function M.open(file, opts)
|
|||
end
|
||||
|
||||
if not file then
|
||||
return Util.error("File not found")
|
||||
return LazyVim.error("File not found")
|
||||
end
|
||||
|
||||
if opts.when_changed then
|
||||
|
@ -68,7 +67,7 @@ function M.open(file, opts)
|
|||
return
|
||||
end
|
||||
Config.json.data.news[ref] = hash
|
||||
Util.json.save()
|
||||
LazyVim.json.save()
|
||||
-- don't open if file has never been opened
|
||||
if is_new then
|
||||
return
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
local Plugin = require("lazy.core.plugin")
|
||||
local Util = require("lazyvim.util")
|
||||
|
||||
---@class lazyvim.util.plugin
|
||||
local M = {}
|
||||
|
@ -35,7 +34,7 @@ function M.setup()
|
|||
M.lazy_file()
|
||||
table.insert(package.loaders, function(module)
|
||||
if M.deprecated_modules[module] then
|
||||
Util.warn(
|
||||
LazyVim.warn(
|
||||
("`%s` is no longer included by default in **LazyVim**.\nPlease install the `%s` extra if you still want to use it."):format(
|
||||
module,
|
||||
M.deprecated_modules[module]
|
||||
|
@ -125,21 +124,21 @@ function M.lazy_file()
|
|||
end
|
||||
|
||||
function M.fix_imports()
|
||||
Plugin.Spec.import = Util.inject.args(Plugin.Spec.import, function(_, spec)
|
||||
Plugin.Spec.import = LazyVim.inject.args(Plugin.Spec.import, function(_, spec)
|
||||
local dep = M.deprecated_extras[spec and spec.import]
|
||||
if dep then
|
||||
dep = dep .. "\n" .. "Please remove the extra to hide this warning."
|
||||
Util.warn(dep, { title = "LazyVim", once = true, stacktrace = true, stacklevel = 6 })
|
||||
LazyVim.warn(dep, { title = "LazyVim", once = true, stacktrace = true, stacklevel = 6 })
|
||||
return false
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
function M.fix_renames()
|
||||
Plugin.Spec.add = Util.inject.args(Plugin.Spec.add, function(self, plugin)
|
||||
Plugin.Spec.add = LazyVim.inject.args(Plugin.Spec.add, function(self, plugin)
|
||||
if type(plugin) == "table" then
|
||||
if M.renames[plugin[1]] then
|
||||
Util.warn(
|
||||
LazyVim.warn(
|
||||
("Plugin `%s` was renamed to `%s`.\nPlease update your config for `%s`"):format(
|
||||
plugin[1],
|
||||
M.renames[plugin[1]],
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
local Util = require("lazyvim.util")
|
||||
|
||||
---@class lazyvim.util.root
|
||||
---@overload fun(): string
|
||||
local M = setmetatable({}, {
|
||||
|
@ -31,7 +29,7 @@ function M.detectors.lsp(buf)
|
|||
return {}
|
||||
end
|
||||
local roots = {} ---@type string[]
|
||||
for _, client in pairs(Util.lsp.get_clients({ bufnr = buf })) do
|
||||
for _, client in pairs(LazyVim.lsp.get_clients({ bufnr = buf })) do
|
||||
-- only check workspace folders, since we're not interested in clients
|
||||
-- running in single file mode
|
||||
local workspace = client.config.workspace_folders
|
||||
|
@ -40,7 +38,7 @@ function M.detectors.lsp(buf)
|
|||
end
|
||||
end
|
||||
return vim.tbl_filter(function(path)
|
||||
path = Util.norm(path)
|
||||
path = LazyVim.norm(path)
|
||||
return path and bufpath:find(path, 1, true) == 1
|
||||
end, roots)
|
||||
end
|
||||
|
@ -66,7 +64,7 @@ function M.realpath(path)
|
|||
return nil
|
||||
end
|
||||
path = vim.uv.fs_realpath(path) or path
|
||||
return Util.norm(path)
|
||||
return LazyVim.norm(path)
|
||||
end
|
||||
|
||||
---@param spec LazyRootSpec
|
||||
|
@ -132,7 +130,7 @@ function M.info()
|
|||
lines[#lines + 1] = "```lua"
|
||||
lines[#lines + 1] = "vim.g.root_spec = " .. vim.inspect(spec)
|
||||
lines[#lines + 1] = "```"
|
||||
require("lazyvim.util").info(lines, { title = "LazyVim Roots" })
|
||||
LazyVim.info(lines, { title = "LazyVim Roots" })
|
||||
return roots[1] and roots[1].paths[1] or vim.uv.cwd()
|
||||
end
|
||||
|
||||
|
@ -141,7 +139,7 @@ M.cache = {}
|
|||
|
||||
function M.setup()
|
||||
vim.api.nvim_create_user_command("LazyRoot", function()
|
||||
Util.root.info()
|
||||
LazyVim.root.info()
|
||||
end, { desc = "LazyVim roots for the current buffer" })
|
||||
|
||||
vim.api.nvim_create_autocmd({ "LspAttach", "BufWritePost", "DirChanged" }, {
|
||||
|
@ -170,7 +168,7 @@ function M.get(opts)
|
|||
if opts and opts.normalize then
|
||||
return ret
|
||||
end
|
||||
return Util.is_win() and ret:gsub("/", "\\") or ret
|
||||
return LazyVim.is_win() and ret:gsub("/", "\\") or ret
|
||||
end
|
||||
|
||||
function M.git()
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
local Util = require("lazyvim.util")
|
||||
|
||||
---@class lazyvim.util.telescope.opts
|
||||
---@field cwd? string|boolean
|
||||
---@field show_untracked? boolean
|
||||
|
@ -22,7 +20,7 @@ function M.telescope(builtin, opts)
|
|||
return function()
|
||||
builtin = params.builtin
|
||||
opts = params.opts
|
||||
opts = vim.tbl_deep_extend("force", { cwd = Util.root() }, opts or {}) --[[@as lazyvim.util.telescope.opts]]
|
||||
opts = vim.tbl_deep_extend("force", { cwd = LazyVim.root() }, opts or {}) --[[@as lazyvim.util.telescope.opts]]
|
||||
if builtin == "files" then
|
||||
if
|
||||
vim.uv.fs_stat((opts.cwd or vim.uv.cwd()) .. "/.git")
|
||||
|
@ -59,7 +57,7 @@ function M.telescope(builtin, opts)
|
|||
end
|
||||
|
||||
function M.config_files()
|
||||
return Util.telescope("find_files", { cwd = vim.fn.stdpath("config") })
|
||||
return LazyVim.telescope("find_files", { cwd = vim.fn.stdpath("config") })
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
local Util = require("lazyvim.util")
|
||||
|
||||
---@class lazyvim.util.toggle
|
||||
local M = {}
|
||||
|
||||
|
@ -14,15 +12,15 @@ function M.option(option, silent, values)
|
|||
---@diagnostic disable-next-line: no-unknown
|
||||
vim.opt_local[option] = values[1]
|
||||
end
|
||||
return Util.info("Set " .. option .. " to " .. vim.opt_local[option]:get(), { title = "Option" })
|
||||
return LazyVim.info("Set " .. option .. " to " .. vim.opt_local[option]:get(), { title = "Option" })
|
||||
end
|
||||
---@diagnostic disable-next-line: no-unknown
|
||||
vim.opt_local[option] = not vim.opt_local[option]:get()
|
||||
if not silent then
|
||||
if vim.opt_local[option]:get() then
|
||||
Util.info("Enabled " .. option, { title = "Option" })
|
||||
LazyVim.info("Enabled " .. option, { title = "Option" })
|
||||
else
|
||||
Util.warn("Disabled " .. option, { title = "Option" })
|
||||
LazyVim.warn("Disabled " .. option, { title = "Option" })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -33,11 +31,11 @@ function M.number()
|
|||
nu = { number = vim.opt_local.number:get(), relativenumber = vim.opt_local.relativenumber:get() }
|
||||
vim.opt_local.number = false
|
||||
vim.opt_local.relativenumber = false
|
||||
Util.warn("Disabled line numbers", { title = "Option" })
|
||||
LazyVim.warn("Disabled line numbers", { title = "Option" })
|
||||
else
|
||||
vim.opt_local.number = nu.number
|
||||
vim.opt_local.relativenumber = nu.relativenumber
|
||||
Util.info("Enabled line numbers", { title = "Option" })
|
||||
LazyVim.info("Enabled line numbers", { title = "Option" })
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -52,10 +50,10 @@ function M.diagnostics()
|
|||
|
||||
if enabled then
|
||||
vim.diagnostic.enable()
|
||||
Util.info("Enabled diagnostics", { title = "Diagnostics" })
|
||||
LazyVim.info("Enabled diagnostics", { title = "Diagnostics" })
|
||||
else
|
||||
vim.diagnostic.disable()
|
||||
Util.warn("Disabled diagnostics", { title = "Diagnostics" })
|
||||
LazyVim.warn("Disabled diagnostics", { title = "Diagnostics" })
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue