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
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
41 changed files with 188 additions and 229 deletions

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,