feat: use LazyVim everywhere instead of require("lazyvim.util")

This commit is contained in:
Folke Lemaitre
2024-03-22 09:15:09 +01:00
parent 3a87c08cda
commit 7a5dbeae75
41 changed files with 188 additions and 229 deletions

View File

@ -1,6 +1,4 @@
local Util = require("lazyvim.util")
_G.LazyVim = Util
_G.LazyVim = require("lazyvim.util")
---@class LazyVimConfig: LazyVimOptions
local M = {}
@ -151,7 +149,7 @@ function M.json.load()
if ok then
M.json.data = vim.tbl_deep_extend("force", M.json.data, json or {})
if M.json.data.version ~= M.json.version then
Util.json.migrate()
LazyVim.json.migrate()
end
end
end
@ -180,12 +178,12 @@ function M.setup(opts)
end
M.load("keymaps")
Util.format.setup()
Util.news.setup()
Util.root.setup()
LazyVim.format.setup()
LazyVim.news.setup()
LazyVim.root.setup()
vim.api.nvim_create_user_command("LazyExtras", function()
Util.extras.show()
LazyVim.extras.show()
end, { desc = "Manage LazyVim extras" })
vim.api.nvim_create_user_command("LazyHealth", function()
@ -195,8 +193,8 @@ function M.setup(opts)
end,
})
Util.track("colorscheme")
Util.try(function()
LazyVim.track("colorscheme")
LazyVim.try(function()
if type(M.colorscheme) == "function" then
M.colorscheme()
else
@ -205,11 +203,11 @@ function M.setup(opts)
end, {
msg = "Could not load your colorscheme",
on_error = function(msg)
Util.error(msg)
LazyVim.error(msg)
vim.cmd.colorscheme("habamax")
end,
})
Util.track()
LazyVim.track()
end
---@param buf? number
@ -231,7 +229,7 @@ end
function M.load(name)
local function _load(mod)
if require("lazy.core.cache").find(mod)[1] then
Util.try(function()
LazyVim.try(function()
require(mod)
end, { msg = "Failed loading " .. mod })
end
@ -261,19 +259,19 @@ function M.init()
end
package.preload["lazyvim.plugins.lsp.format"] = function()
Util.deprecate([[require("lazyvim.plugins.lsp.format")]], [[require("lazyvim.util").format]])
return Util.format
LazyVim.deprecate([[require("lazyvim.plugins.lsp.format")]], [[LazyVim.format]])
return LazyVim.format
end
-- delay notifications till vim.notify was replaced or after 500ms
require("lazyvim.util").lazy_notify()
LazyVim.lazy_notify()
-- load options here, before lazy init while sourcing plugin modules
-- this is needed to make sure options will be correctly applied
-- after installing missing plugins
M.load("options")
Util.plugin.setup()
LazyVim.plugin.setup()
M.json.load()
end

View File

@ -1,9 +1,8 @@
-- This file is automatically loaded by lazyvim.config.init
local Util = require("lazyvim.util")
-- DO NOT USE THIS IN YOU OWN CONFIG!!
-- use `vim.keymap.set` instead
local map = Util.safe_keymap_set
local map = LazyVim.safe_keymap_set
-- better up/down
map({ "n", "x" }, "j", "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true })
@ -88,7 +87,7 @@ map("n", "]q", vim.cmd.cnext, { desc = "Next quickfix" })
-- formatting
map({ "n", "v" }, "<leader>cf", function()
Util.format({ force = true })
LazyVim.format({ force = true })
end, { desc = "Format" })
-- diagnostic
@ -110,28 +109,28 @@ map("n", "[w", diagnostic_goto(false, "WARN"), { desc = "Prev Warning" })
-- stylua: ignore start
-- toggle options
map("n", "<leader>uf", function() Util.format.toggle() end, { desc = "Toggle auto format (global)" })
map("n", "<leader>uF", function() Util.format.toggle(true) end, { desc = "Toggle auto format (buffer)" })
map("n", "<leader>us", function() Util.toggle("spell") end, { desc = "Toggle Spelling" })
map("n", "<leader>uw", function() Util.toggle("wrap") end, { desc = "Toggle Word Wrap" })
map("n", "<leader>uL", function() Util.toggle("relativenumber") end, { desc = "Toggle Relative Line Numbers" })
map("n", "<leader>ul", function() Util.toggle.number() end, { desc = "Toggle Line Numbers" })
map("n", "<leader>ud", function() Util.toggle.diagnostics() end, { desc = "Toggle Diagnostics" })
map("n", "<leader>uf", function() LazyVim.format.toggle() end, { desc = "Toggle auto format (global)" })
map("n", "<leader>uF", function() LazyVim.format.toggle(true) end, { desc = "Toggle auto format (buffer)" })
map("n", "<leader>us", function() LazyVim.toggle("spell") end, { desc = "Toggle Spelling" })
map("n", "<leader>uw", function() LazyVim.toggle("wrap") end, { desc = "Toggle Word Wrap" })
map("n", "<leader>uL", function() LazyVim.toggle("relativenumber") end, { desc = "Toggle Relative Line Numbers" })
map("n", "<leader>ul", function() LazyVim.toggle.number() end, { desc = "Toggle Line Numbers" })
map("n", "<leader>ud", function() LazyVim.toggle.diagnostics() end, { desc = "Toggle Diagnostics" })
local conceallevel = vim.o.conceallevel > 0 and vim.o.conceallevel or 3
map("n", "<leader>uc", function() Util.toggle("conceallevel", false, {0, conceallevel}) end, { desc = "Toggle Conceal" })
map("n", "<leader>uc", function() LazyVim.toggle("conceallevel", false, {0, conceallevel}) end, { desc = "Toggle Conceal" })
if vim.lsp.buf.inlay_hint or vim.lsp.inlay_hint then
map( "n", "<leader>uh", function() Util.toggle.inlay_hints() end, { desc = "Toggle Inlay Hints" })
map( "n", "<leader>uh", function() LazyVim.toggle.inlay_hints() end, { desc = "Toggle Inlay Hints" })
end
map("n", "<leader>uT", function() if vim.b.ts_highlight then vim.treesitter.stop() else vim.treesitter.start() end end, { desc = "Toggle Treesitter Highlight" })
map("n", "<leader>ub", function() Util.toggle("background", false, {"light", "dark"}) end, { desc = "Toggle Background" })
map("n", "<leader>ub", function() LazyVim.toggle("background", false, {"light", "dark"}) end, { desc = "Toggle Background" })
-- lazygit
map("n", "<leader>gg", function() Util.terminal({ "lazygit" }, { cwd = Util.root.git(), esc_esc = false, ctrl_hjkl = false }) end, { desc = "Lazygit (root dir)" })
map("n", "<leader>gG", function() Util.terminal({ "lazygit" }, {esc_esc = false, ctrl_hjkl = false}) end, { desc = "Lazygit (cwd)" })
map("n", "<leader>gg", function() LazyVim.terminal({ "lazygit" }, { cwd = LazyVim.root.git(), esc_esc = false, ctrl_hjkl = false }) end, { desc = "Lazygit (root dir)" })
map("n", "<leader>gG", function() LazyVim.terminal({ "lazygit" }, {esc_esc = false, ctrl_hjkl = false}) end, { desc = "Lazygit (cwd)" })
map("n", "<leader>gf", function()
local git_path = vim.api.nvim_buf_get_name(0)
Util.terminal({ "lazygit", "-f", vim.trim(git_path) }, { esc_esc = false, ctrl_hjkl = false })
LazyVim.terminal({ "lazygit", "-f", vim.trim(git_path) }, { esc_esc = false, ctrl_hjkl = false })
end, { desc = "Lazygit current file history" })
-- quit
@ -141,12 +140,12 @@ map("n", "<leader>qq", "<cmd>qa<cr>", { desc = "Quit all" })
map("n", "<leader>ui", vim.show_pos, { desc = "Inspect Pos" })
-- LazyVim Changelog
map("n", "<leader>L", function() Util.news.changelog() end, { desc = "LazyVim Changelog" })
map("n", "<leader>L", function() LazyVim.news.changelog() end, { desc = "LazyVim Changelog" })
-- floating terminal
local lazyterm = function() Util.terminal(nil, { cwd = Util.root() }) end
local lazyterm = function() LazyVim.terminal(nil, { cwd = LazyVim.root() }) end
map("n", "<leader>ft", lazyterm, { desc = "Terminal (root dir)" })
map("n", "<leader>fT", function() Util.terminal() end, { desc = "Terminal (cwd)" })
map("n", "<leader>fT", function() LazyVim.terminal() end, { desc = "Terminal (cwd)" })
map("n", "<c-/>", lazyterm, { desc = "Terminal (root dir)" })
map("n", "<c-_>", lazyterm, { desc = "which_key_ignore" })

View File

@ -122,12 +122,11 @@ return {
{
"<leader>up",
function()
local Util = require("lazy.core.util")
vim.g.minipairs_disable = not vim.g.minipairs_disable
if vim.g.minipairs_disable then
Util.warn("Disabled auto pairs", { title = "Option" })
LazyVim.warn("Disabled auto pairs", { title = "Option" })
else
Util.info("Enabled auto pairs", { title = "Option" })
LazyVim.info("Enabled auto pairs", { title = "Option" })
end
end,
desc = "Toggle auto pairs",
@ -238,7 +237,7 @@ return {
config = function(_, opts)
require("mini.ai").setup(opts)
-- register all text objects with which-key
require("lazyvim.util").on_load("which-key.nvim", function()
LazyVim.on_load("which-key.nvim", function()
---@type table<string, string|table>
local i = {
[" "] = "Whitespace",

View File

@ -1,5 +1,3 @@
local Util = require("lazyvim.util")
return {
-- file explorer
@ -11,7 +9,7 @@ return {
{
"<leader>fe",
function()
require("neo-tree.command").execute({ toggle = true, dir = Util.root() })
require("neo-tree.command").execute({ toggle = true, dir = LazyVim.root() })
end,
desc = "Explorer NeoTree (root dir)",
},
@ -82,7 +80,7 @@ return {
},
config = function(_, opts)
local function on_move(data)
Util.lsp.on_rename(data.source, data.destination)
LazyVim.lsp.on_rename(data.source, data.destination)
end
local events = require("neo-tree.events")
@ -129,7 +127,7 @@ return {
build = "make",
enabled = vim.fn.executable("make") == 1,
config = function()
Util.on_load("telescope.nvim", function()
LazyVim.on_load("telescope.nvim", function()
require("telescope").load_extension("fzf")
end)
end,
@ -141,17 +139,17 @@ return {
"<cmd>Telescope buffers sort_mru=true sort_lastused=true<cr>",
desc = "Switch Buffer",
},
{ "<leader>/", Util.telescope("live_grep"), desc = "Grep (root dir)" },
{ "<leader>/", LazyVim.telescope("live_grep"), desc = "Grep (root dir)" },
{ "<leader>:", "<cmd>Telescope command_history<cr>", desc = "Command History" },
{ "<leader><space>", Util.telescope("files"), desc = "Find Files (root dir)" },
{ "<leader><space>", LazyVim.telescope("files"), desc = "Find Files (root dir)" },
-- find
{ "<leader>fb", "<cmd>Telescope buffers sort_mru=true sort_lastused=true<cr>", desc = "Buffers" },
{ "<leader>fc", Util.telescope.config_files(), desc = "Find Config File" },
{ "<leader>ff", Util.telescope("files"), desc = "Find Files (root dir)" },
{ "<leader>fF", Util.telescope("files", { cwd = false }), desc = "Find Files (cwd)" },
{ "<leader>fc", LazyVim.telescope.config_files(), desc = "Find Config File" },
{ "<leader>ff", LazyVim.telescope("files"), desc = "Find Files (root dir)" },
{ "<leader>fF", LazyVim.telescope("files", { cwd = false }), desc = "Find Files (cwd)" },
{ "<leader>fg", "<cmd>Telescope git_files<cr>", desc = "Find Files (git-files)" },
{ "<leader>fr", "<cmd>Telescope oldfiles<cr>", desc = "Recent" },
{ "<leader>fR", Util.telescope("oldfiles", { cwd = vim.uv.cwd() }), desc = "Recent (cwd)" },
{ "<leader>fR", LazyVim.telescope("oldfiles", { cwd = vim.uv.cwd() }), desc = "Recent (cwd)" },
-- git
{ "<leader>gc", "<cmd>Telescope git_commits<CR>", desc = "commits" },
{ "<leader>gs", "<cmd>Telescope git_status<CR>", desc = "status" },
@ -163,8 +161,8 @@ return {
{ "<leader>sC", "<cmd>Telescope commands<cr>", desc = "Commands" },
{ "<leader>sd", "<cmd>Telescope diagnostics bufnr=0<cr>", desc = "Document diagnostics" },
{ "<leader>sD", "<cmd>Telescope diagnostics<cr>", desc = "Workspace diagnostics" },
{ "<leader>sg", Util.telescope("live_grep"), desc = "Grep (root dir)" },
{ "<leader>sG", Util.telescope("live_grep", { cwd = false }), desc = "Grep (cwd)" },
{ "<leader>sg", LazyVim.telescope("live_grep"), desc = "Grep (root dir)" },
{ "<leader>sG", LazyVim.telescope("live_grep", { cwd = false }), desc = "Grep (cwd)" },
{ "<leader>sh", "<cmd>Telescope help_tags<cr>", desc = "Help Pages" },
{ "<leader>sH", "<cmd>Telescope highlights<cr>", desc = "Search Highlight Groups" },
{ "<leader>sk", "<cmd>Telescope keymaps<cr>", desc = "Key Maps" },
@ -172,11 +170,11 @@ return {
{ "<leader>sm", "<cmd>Telescope marks<cr>", desc = "Jump to Mark" },
{ "<leader>so", "<cmd>Telescope vim_options<cr>", desc = "Options" },
{ "<leader>sR", "<cmd>Telescope resume<cr>", desc = "Resume" },
{ "<leader>sw", Util.telescope("grep_string", { word_match = "-w" }), desc = "Word (root dir)" },
{ "<leader>sW", Util.telescope("grep_string", { cwd = false, word_match = "-w" }), desc = "Word (cwd)" },
{ "<leader>sw", Util.telescope("grep_string"), mode = "v", desc = "Selection (root dir)" },
{ "<leader>sW", Util.telescope("grep_string", { cwd = false }), mode = "v", desc = "Selection (cwd)" },
{ "<leader>uC", Util.telescope("colorscheme", { enable_preview = true }), desc = "Colorscheme with preview" },
{ "<leader>sw", LazyVim.telescope("grep_string", { word_match = "-w" }), desc = "Word (root dir)" },
{ "<leader>sW", LazyVim.telescope("grep_string", { cwd = false, word_match = "-w" }), desc = "Word (cwd)" },
{ "<leader>sw", LazyVim.telescope("grep_string"), mode = "v", desc = "Selection (root dir)" },
{ "<leader>sW", LazyVim.telescope("grep_string", { cwd = false }), mode = "v", desc = "Selection (cwd)" },
{ "<leader>uC", LazyVim.telescope("colorscheme", { enable_preview = true }), desc = "Colorscheme with preview" },
{
"<leader>ss",
function()
@ -208,12 +206,12 @@ return {
local find_files_no_ignore = function()
local action_state = require("telescope.actions.state")
local line = action_state.get_current_line()
Util.telescope("find_files", { no_ignore = true, default_text = line })()
LazyVim.telescope("find_files", { no_ignore = true, default_text = line })()
end
local find_files_with_hidden = function()
local action_state = require("telescope.actions.state")
local line = action_state.get_current_line()
Util.telescope("find_files", { hidden = true, default_text = line })()
LazyVim.telescope("find_files", { hidden = true, default_text = line })()
end
return {
@ -277,7 +275,7 @@ return {
"nvim-telescope/telescope.nvim",
optional = true,
opts = function(_, opts)
if not Util.has("flash.nvim") then
if not LazyVim.has("flash.nvim") then
return
end
local function flash(prompt_bufnr)

View File

@ -27,7 +27,7 @@ return {
optional = true,
event = "VeryLazy",
opts = function(_, opts)
table.insert(opts.sections.lualine_x, 2, require("lazyvim.util").lualine.cmp_source("codeium"))
table.insert(opts.sections.lualine_x, 2, LazyVim.lualine.cmp_source("codeium"))
end,
},
}

View File

@ -19,12 +19,11 @@ return {
optional = true,
event = "VeryLazy",
opts = function(_, opts)
local Util = require("lazyvim.util")
local colors = {
[""] = Util.ui.fg("Special"),
["Normal"] = Util.ui.fg("Special"),
["Warning"] = Util.ui.fg("DiagnosticError"),
["InProgress"] = Util.ui.fg("DiagnosticWarn"),
[""] = LazyVim.ui.fg("Special"),
["Normal"] = LazyVim.ui.fg("Special"),
["Warning"] = LazyVim.ui.fg("DiagnosticError"),
["InProgress"] = LazyVim.ui.fg("DiagnosticWarn"),
}
table.insert(opts.sections.lualine_x, 2, {
function()
@ -36,7 +35,7 @@ return {
if not package.loaded["copilot"] then
return
end
local ok, clients = pcall(require("lazyvim.util").lsp.get_clients, { name = "copilot", bufnr = 0 })
local ok, clients = pcall(LazyVim.lsp.get_clients, { name = "copilot", bufnr = 0 })
if not ok then
return false
end
@ -66,7 +65,7 @@ return {
copilot_cmp.setup(opts)
-- attach cmp source whenever copilot attaches
-- fixes lazy-loading issues with the copilot cmp source
require("lazyvim.util").lsp.on_attach(function(client)
LazyVim.lsp.on_attach(function(client)
if client.name == "copilot" then
copilot_cmp._on_insert_enter({})
end

View File

@ -1,5 +1,3 @@
local Util = require("lazyvim.util")
return {
-- Tabnine cmp source
{
@ -8,7 +6,7 @@ return {
{
"tzachar/cmp-tabnine",
build = {
Util.is_win() and "pwsh -noni .\\install.ps1" or "./install.sh",
LazyVim.is_win() and "pwsh -noni .\\install.ps1" or "./install.sh",
":CmpTabnineHub",
},
dependencies = "hrsh7th/nvim-cmp",
@ -30,7 +28,7 @@ return {
priority = 100,
})
opts.formatting.format = Util.inject.args(opts.formatting.format, function(entry, item)
opts.formatting.format = LazyVim.inject.args(opts.formatting.format, function(entry, item)
-- Hide percentage in the menu
if entry.source.name == "cmp_tabnine" then
item.menu = ""
@ -45,7 +43,7 @@ return {
event = "VeryLazy",
opts = function(_, opts)
local icon = require("lazyvim.config").icons.kinds.TabNine
table.insert(opts.sections.lualine_x, 2, require("lazyvim.util").lualine.cmp_source("cmp_tabnine", icon))
table.insert(opts.sections.lualine_x, 2, LazyVim.lualine.cmp_source("cmp_tabnine", icon))
end,
},
}

View File

@ -1,5 +1,4 @@
local Config = require("lazyvim.config")
local Util = require("lazyvim.util")
return {
desc = "Aerial Symbol Browser",
@ -55,7 +54,7 @@ return {
"nvim-telescope/telescope.nvim",
optional = true,
opts = function()
Util.on_load("telescope.nvim", function()
LazyVim.on_load("telescope.nvim", function()
require("telescope").load_extension("aerial")
end)
end,
@ -73,11 +72,11 @@ return {
"folke/edgy.nvim",
optional = true,
opts = function(_, opts)
local edgy_idx = Util.plugin.extra_idx("ui.edgy")
local aerial_idx = Util.plugin.extra_idx("editor.aerial")
local edgy_idx = LazyVim.plugin.extra_idx("ui.edgy")
local aerial_idx = LazyVim.plugin.extra_idx("editor.aerial")
if edgy_idx and edgy_idx > aerial_idx then
Util.warn("The `edgy.nvim` extra must be **imported** before the `aerial.nvim` extra to work properly.", {
LazyVim.warn("The `edgy.nvim` extra must be **imported** before the `aerial.nvim` extra to work properly.", {
title = "LazyVim",
})
end

View File

@ -57,7 +57,7 @@ return {
vim.api.nvim_create_autocmd("User", {
pattern = "MiniFilesActionRename",
callback = function(event)
require("lazyvim.util").lsp.on_rename(event.data.from, event.data.to)
LazyVim.lsp.on_rename(event.data.from, event.data.to)
end,
})
end,

View File

@ -7,7 +7,7 @@ return {
lazy = true,
init = function()
vim.g.navic_silence = true
require("lazyvim.util").lsp.on_attach(function(client, buffer)
LazyVim.lsp.on_attach(function(client, buffer)
if client.supports_method("textDocument/documentSymbol") then
require("nvim-navic").attach(client, buffer)
end

View File

@ -1,5 +1,3 @@
local Util = require("lazyvim.util")
return {
{
"hedyhli/outline.nvim",
@ -37,11 +35,11 @@ return {
"folke/edgy.nvim",
optional = true,
opts = function(_, opts)
local edgy_idx = Util.plugin.extra_idx("ui.edgy")
local symbols_idx = Util.plugin.extra_idx("editor.outline")
local edgy_idx = LazyVim.plugin.extra_idx("ui.edgy")
local symbols_idx = LazyVim.plugin.extra_idx("editor.outline")
if edgy_idx and edgy_idx > symbols_idx then
Util.warn(
LazyVim.warn(
"The `edgy.nvim` extra must be **imported** before the `outline.nvim` extra to work properly.",
{ title = "LazyVim" }
)

View File

@ -85,7 +85,7 @@ return {
},
setup = {
clangd = function(_, opts)
local clangd_ext_opts = require("lazyvim.util").opts("clangd_extensions.nvim")
local clangd_ext_opts = LazyVim.opts("clangd_extensions.nvim")
require("clangd_extensions").setup(vim.tbl_deep_extend("force", clangd_ext_opts or {}, { server = opts }))
return false
end,

View File

@ -61,7 +61,7 @@ return {
gopls = function(_, opts)
-- workaround for gopls not supporting semanticTokensProvider
-- https://github.com/golang/go/issues/54531#issuecomment-1464982242
require("lazyvim.util").lsp.on_attach(function(client, _)
LazyVim.lsp.on_attach(function(client, _)
if client.name == "gopls" then
if not client.server_capabilities.semanticTokensProvider then
local semantic = client.config.capabilities.textDocument.semanticTokens

View File

@ -1,4 +1,4 @@
require("lazyvim.util").lsp.on_attach(function(client, buffer)
LazyVim.lsp.on_attach(function(client, buffer)
if client.name == "yamlls" then
if vim.api.nvim_get_option_value("filetype", { buf = buffer }) == "helm" then
vim.schedule(function()

View File

@ -1,5 +1,3 @@
local Util = require("lazyvim.util")
-- This is the same as in lspconfig.server_configurations.jdtls, but avoids
-- needing to require that when this module loads.
local java_filetypes = { "java" }
@ -109,13 +107,13 @@ return {
}
end,
config = function()
local opts = Util.opts("nvim-jdtls") or {}
local opts = LazyVim.opts("nvim-jdtls") or {}
-- Find the extra bundles that should be passed on the jdtls command-line
-- if nvim-dap is enabled with java debug/test.
local mason_registry = require("mason-registry")
local bundles = {} ---@type string[]
if opts.dap and Util.has("nvim-dap") and mason_registry.is_installed("java-debug-adapter") then
if opts.dap and LazyVim.has("nvim-dap") and mason_registry.is_installed("java-debug-adapter") then
local java_dbg_pkg = mason_registry.get_package("java-debug-adapter")
local java_dbg_path = java_dbg_pkg:get_install_path()
local jar_patterns = {
@ -196,7 +194,7 @@ return {
},
}, { mode = "v", buffer = args.buf })
if opts.dap and Util.has("nvim-dap") and mason_registry.is_installed("java-debug-adapter") then
if opts.dap and LazyVim.has("nvim-dap") and mason_registry.is_installed("java-debug-adapter") then
-- custom init for Java debugger
require("jdtls").setup_dap(opts.dap)
require("jdtls.dap").setup_dap_main_class_configs(opts.dap_main)

View File

@ -43,7 +43,7 @@ return {
},
setup = {
ruff_lsp = function()
require("lazyvim.util").lsp.on_attach(function(client, _)
LazyVim.lsp.on_attach(function(client, _)
if client.name == "ruff_lsp" then
-- Disable hover in favor of Pyright
client.server_capabilities.hoverProvider = false
@ -89,7 +89,7 @@ return {
"linux-cultist/venv-selector.nvim",
cmd = "VenvSelect",
opts = function(_, opts)
if require("lazyvim.util").has("nvim-dap-python") then
if LazyVim.has("nvim-dap-python") then
opts.dap_enabled = true
end
return vim.tbl_deep_extend("force", opts, {

View File

@ -1,5 +1,3 @@
local Util = require("lazyvim.util")
return {
{
"nvim-treesitter/nvim-treesitter",
@ -58,7 +56,7 @@ return {
{
"ANGkeith/telescope-terraform-doc.nvim",
config = function()
Util.on_load("telescope.nvim", function()
LazyVim.on_load("telescope.nvim", function()
require("telescope").load_extension("terraform_doc")
end)
end,
@ -66,7 +64,7 @@ return {
{
"cappyzawa/telescope-terraform.nvim",
config = function()
Util.on_load("telescope.nvim", function()
LazyVim.on_load("telescope.nvim", function()
require("telescope").load_extension("terraform")
end)
end,

View File

@ -64,7 +64,7 @@ return {
yamlls = function()
-- Neovim < 0.10 does not have dynamic registration for formatting
if vim.fn.has("nvim-0.10") == 0 then
require("lazyvim.util").lsp.on_attach(function(client, _)
LazyVim.lsp.on_attach(function(client, _)
if client.name == "yamlls" then
client.server_capabilities.documentFormattingProvider = true
end

View File

@ -23,11 +23,10 @@ vim.api.nvim_create_autocmd("User", {
once = true,
callback = function()
local Config = require("lazy.core.config")
local Util = require("lazyvim.util")
local lazyrc_idx = Util.plugin.extra_idx("lazyrc")
local lazyrc_idx = LazyVim.plugin.extra_idx("lazyrc")
if lazyrc_idx and lazyrc_idx ~= #Config.spec.modules then
Util.warn({
LazyVim.warn({
"The `lazyrc` extra must be the last plugin spec added to **lazy.nvim**. ",
"",
"Add `{ import = 'lazyvim.plugins.extras.lazyrc' }` to file `config.lazy`. ",

View File

@ -15,10 +15,10 @@ return {
setup = {
eslint = function()
local function get_client(buf)
return require("lazyvim.util").lsp.get_clients({ name = "eslint", bufnr = buf })[1]
return LazyVim.lsp.get_clients({ name = "eslint", bufnr = buf })[1]
end
local formatter = require("lazyvim.util").lsp.formatter({
local formatter = LazyVim.lsp.formatter({
name = "eslint: lsp",
primary = false,
priority = 200,
@ -44,7 +44,7 @@ return {
end
-- register the formatter with LazyVim
require("lazyvim.util").format.register(formatter)
LazyVim.format.register(formatter)
end,
},
},

View File

@ -1,5 +1,3 @@
local Util = require("lazyvim.util")
return {
-- none-ls
{
@ -7,14 +5,14 @@ return {
event = "LazyFile",
dependencies = { "mason.nvim" },
init = function()
Util.on_very_lazy(function()
LazyVim.on_very_lazy(function()
-- register the formatter with LazyVim
require("lazyvim.util").format.register({
LazyVim.format.register({
name = "none-ls.nvim",
priority = 200, -- set higher than conform, the builtin formatter
primary = true,
format = function(buf)
return Util.lsp.format({
return LazyVim.lsp.format({
bufnr = buf,
filter = function(client)
return client.name == "null-ls"

View File

@ -27,7 +27,7 @@ return {
output = { open_on_run = true },
quickfix = {
open = function()
if require("lazyvim.util").has("trouble.nvim") then
if LazyVim.has("trouble.nvim") then
require("trouble").open({ mode = "quickfix", focus = false })
else
vim.cmd("copen")
@ -47,7 +47,7 @@ return {
},
}, neotest_ns)
if require("lazyvim.util").has("trouble.nvim") then
if LazyVim.has("trouble.nvim") then
opts.consumers = opts.consumers or {}
-- Refresh and auto close trouble after running tests
---@type neotest.Consumer

View File

@ -6,12 +6,12 @@ return {
keys = {
{ "<leader>gG",
function()
require("lazyvim.util").terminal.open({ "gitui" }, { esc_esc = false, ctrl_hjkl = false })
LazyVim.terminal.open({ "gitui" }, { esc_esc = false, ctrl_hjkl = false })
end,
desc = "gitui (cwd)" },
{ "<leader>gg",
function()
require("lazyvim.util").terminal.open({ "gitui" }, { cwd = require("lazyvim.util").root.get(), esc_esc = false, ctrl_hjkl = false })
LazyVim.terminal.open({ "gitui" }, { cwd = LazyVim.root.get(), esc_esc = false, ctrl_hjkl = false })
end,
desc = "gitui (root dir)" }
},

View File

@ -11,7 +11,7 @@ return {
event = "VeryLazy",
config = function(_, opts)
require("project_nvim").setup(opts)
require("lazyvim.util").on_load("telescope.nvim", function()
LazyVim.on_load("telescope.nvim", function()
require("telescope").load_extension("projects")
end)
end,

View File

@ -1,5 +1,3 @@
local Util = require("lazyvim.util")
local M = {}
---@param opts ConformOpts
@ -10,14 +8,17 @@ function M.setup(_, opts)
if formatter.extra_args then
---@diagnostic disable-next-line: undefined-field
formatter.prepend_args = formatter.extra_args
Util.deprecate(("opts.formatters.%s.extra_args"):format(name), ("opts.formatters.%s.prepend_args"):format(name))
LazyVim.deprecate(
("opts.formatters.%s.extra_args"):format(name),
("opts.formatters.%s.prepend_args"):format(name)
)
end
end
end
for _, key in ipairs({ "format_on_save", "format_after_save" }) do
if opts[key] then
Util.warn(
LazyVim.warn(
("Don't set `opts.%s` for `conform.nvim`.\n**LazyVim** will use the conform formatter automatically"):format(
key
)
@ -47,8 +48,8 @@ return {
},
init = function()
-- Install the conform formatter on VeryLazy
require("lazyvim.util").on_very_lazy(function()
require("lazyvim.util").format.register({
LazyVim.on_very_lazy(function()
LazyVim.format.register({
name = "conform.nvim",
priority = 100,
primary = true,
@ -56,7 +57,7 @@ return {
local plugin = require("lazy.core.config").plugins["conform.nvim"]
local Plugin = require("lazy.core.plugin")
local opts = Plugin.values(plugin, "opts", false)
require("conform").format(Util.merge({}, opts.format, { bufnr = buf }))
require("conform").format(LazyVim.merge({}, opts.format, { bufnr = buf }))
end,
sources = function(buf)
local ret = require("conform").list_formatters(buf)
@ -71,7 +72,7 @@ return {
opts = function()
local plugin = require("lazy.core.config").plugins["conform.nvim"]
if plugin.config ~= M.setup then
Util.error({
LazyVim.error({
"Don't set `plugin.config` for `conform.nvim`.\n",
"This will break **LazyVim** formatting.\n",
"Please refer to the docs at https://www.lazyvim.org/plugins/formatting",

View File

@ -27,8 +27,6 @@ return {
},
},
config = function(_, opts)
local Util = require("lazyvim.util")
local M = {}
local lint = require("lint")
@ -73,7 +71,7 @@ return {
names = vim.tbl_filter(function(name)
local linter = lint.linters[name]
if not linter then
Util.warn("Linter not found: " .. name, { title = "nvim-lint" })
LazyVim.warn("Linter not found: " .. name, { title = "nvim-lint" })
end
return linter and not (type(linter) == "table" and linter.condition and not linter.condition(ctx))
end, names)

View File

@ -1,5 +1,3 @@
local Util = require("lazyvim.util")
return {
-- lspconfig
{
@ -95,22 +93,22 @@ return {
},
---@param opts PluginLspOpts
config = function(_, opts)
if Util.has("neoconf.nvim") then
if LazyVim.has("neoconf.nvim") then
local plugin = require("lazy.core.config").spec.plugins["neoconf.nvim"]
require("neoconf").setup(require("lazy.core.plugin").values(plugin, "opts", false))
end
-- setup autoformat
Util.format.register(Util.lsp.formatter())
LazyVim.format.register(LazyVim.lsp.formatter())
-- deprecated options
if opts.autoformat ~= nil then
vim.g.autoformat = opts.autoformat
Util.deprecate("nvim-lspconfig.opts.autoformat", "vim.g.autoformat")
LazyVim.deprecate("nvim-lspconfig.opts.autoformat", "vim.g.autoformat")
end
-- setup keymaps
Util.lsp.on_attach(function(client, buffer)
LazyVim.lsp.on_attach(function(client, buffer)
require("lazyvim.plugins.lsp.keymaps").on_attach(client, buffer)
end)
@ -134,16 +132,16 @@ return {
-- inlay hints
if opts.inlay_hints.enabled then
Util.lsp.on_attach(function(client, buffer)
LazyVim.lsp.on_attach(function(client, buffer)
if client.supports_method("textDocument/inlayHint") then
Util.toggle.inlay_hints(buffer, true)
LazyVim.toggle.inlay_hints(buffer, true)
end
end)
end
-- code lens
if opts.codelens.enabled and vim.lsp.codelens then
Util.lsp.on_attach(function(client, buffer)
LazyVim.lsp.on_attach(function(client, buffer)
if client.supports_method("textDocument/codeLens") then
vim.lsp.codelens.refresh()
--- autocmd BufEnter,CursorHold,InsertLeave <buffer> lua vim.lsp.codelens.refresh()
@ -220,10 +218,10 @@ return {
mlsp.setup({ ensure_installed = ensure_installed, handlers = { setup } })
end
if Util.lsp.get_config("denols") and Util.lsp.get_config("tsserver") then
if LazyVim.lsp.get_config("denols") and LazyVim.lsp.get_config("tsserver") then
local is_deno = require("lspconfig.util").root_pattern("deno.json", "deno.jsonc")
Util.lsp.disable("tsserver", is_deno)
Util.lsp.disable("denols", function(root_dir)
LazyVim.lsp.disable("tsserver", is_deno)
LazyVim.lsp.disable("denols", function(root_dir)
return not is_deno(root_dir)
end)
end

View File

@ -41,7 +41,7 @@ function M.get()
has = "codeAction",
}
}
if require("lazyvim.util").has("inc-rename.nvim") then
if LazyVim.has("inc-rename.nvim") then
M._keys[#M._keys + 1] = {
"<leader>cr",
function()
@ -61,7 +61,7 @@ end
---@param method string
function M.has(buffer, method)
method = method:find("/") and method or "textDocument/" .. method
local clients = require("lazyvim.util").lsp.get_clients({ bufnr = buffer })
local clients = LazyVim.lsp.get_clients({ bufnr = buffer })
for _, client in ipairs(clients) do
if client.supports_method(method) then
return true
@ -77,8 +77,8 @@ function M.resolve(buffer)
return {}
end
local spec = M.get()
local opts = require("lazyvim.util").opts("nvim-lspconfig")
local clients = require("lazyvim.util").lsp.get_clients({ bufnr = buffer })
local opts = LazyVim.opts("nvim-lspconfig")
local clients = LazyVim.lsp.get_clients({ bufnr = buffer })
for _, client in ipairs(clients) do
local maps = opts.servers[client.name] and opts.servers[client.name].keys or {}
vim.list_extend(spec, maps)

View File

@ -124,13 +124,12 @@ return {
{
"<leader>ut",
function()
local Util = require("lazyvim.util")
local tsc = require("treesitter-context")
tsc.toggle()
if Util.inject.get_upvalue(tsc.toggle, "enabled") then
Util.info("Enabled Treesitter Context", { title = "Option" })
if LazyVim.inject.get_upvalue(tsc.toggle, "enabled") then
LazyVim.info("Enabled Treesitter Context", { title = "Option" })
else
Util.warn("Disabled Treesitter Context", { title = "Option" })
LazyVim.warn("Disabled Treesitter Context", { title = "Option" })
end
end,
desc = "Toggle Treesitter Context",

View File

@ -1,5 +1,3 @@
local Util = require("lazyvim.util")
return {
-- Better `vim.notify()`
{
@ -27,8 +25,8 @@ return {
},
init = function()
-- when noice is not enabled, install notify on VeryLazy
if not Util.has("noice.nvim") then
Util.on_very_lazy(function()
if not LazyVim.has("noice.nvim") then
LazyVim.on_very_lazy(function()
vim.notify = require("notify")
end)
end
@ -140,7 +138,7 @@ return {
lualine_b = { "branch" },
lualine_c = {
Util.lualine.root_dir(),
LazyVim.lualine.root_dir(),
{
"diagnostics",
symbols = {
@ -151,31 +149,31 @@ return {
},
},
{ "filetype", icon_only = true, separator = "", padding = { left = 1, right = 0 } },
{ Util.lualine.pretty_path() },
{ LazyVim.lualine.pretty_path() },
},
lualine_x = {
-- stylua: ignore
{
function() return require("noice").api.status.command.get() end,
cond = function() return package.loaded["noice"] and require("noice").api.status.command.has() end,
color = Util.ui.fg("Statement"),
color = LazyVim.ui.fg("Statement"),
},
-- stylua: ignore
{
function() return require("noice").api.status.mode.get() end,
cond = function() return package.loaded["noice"] and require("noice").api.status.mode.has() end,
color = Util.ui.fg("Constant"),
color = LazyVim.ui.fg("Constant"),
},
-- stylua: ignore
{
function() return "" .. require("dap").status() end,
cond = function () return package.loaded["dap"] and require("dap").status() ~= "" end,
color = Util.ui.fg("Debug"),
color = LazyVim.ui.fg("Debug"),
},
{
require("lazy.status").updates,
cond = require("lazy.status").has_updates,
color = Util.ui.fg("Special"),
color = LazyVim.ui.fg("Special"),
},
{
"diff",
@ -278,7 +276,7 @@ return {
{
"folke/which-key.nvim",
opts = function(_, opts)
if require("lazyvim.util").has("noice.nvim") then
if LazyVim.has("noice.nvim") then
opts.defaults["<leader>sn"] = { name = "+noice" }
end
end,
@ -338,7 +336,7 @@ return {
"goolord/alpha-nvim",
optional = true,
enabled = function()
require("lazyvim.util").warn({
LazyVim.warn({
"`dashboard.nvim` is now the default LazyVim starter plugin.",
"",
"To keep using `alpha.nvim`, please enable the `lazyvim.plugins.extras.ui.alpha` extra.",
@ -373,11 +371,11 @@ return {
header = vim.split(logo, "\n"),
-- stylua: ignore
center = {
{ action = Util.telescope("files"), desc = " Find file", icon = "", key = "f" },
{ action = LazyVim.telescope("files"), desc = " Find file", icon = "", key = "f" },
{ action = "ene | startinsert", desc = " New file", icon = "", key = "n" },
{ action = "Telescope oldfiles", desc = " Recent files", icon = "", key = "r" },
{ action = "Telescope live_grep", desc = " Find text", icon = "", key = "g" },
{ action = [[lua require("lazyvim.util").telescope.config_files()()]], desc = " Config", icon = "", key = "c" },
{ action = [[lua LazyVim.telescope.config_files()()]], desc = " Config", icon = "", key = "c" },
{ action = 'lua require("persistence").load()', desc = " Restore Session", icon = "", key = "s" },
{ action = "LazyExtras", desc = " Lazy Extras", icon = "", key = "x" },
{ action = "Lazy", desc = " Lazy", icon = "󰒲 ", key = "l" },

Some files were not shown because too many files have changed in this diff Show More