From 28b7a5add22a2f94dc75ba9f99fdc0c0bbd63d66 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 11 Oct 2023 14:39:44 +0200 Subject: [PATCH 01/83] chore(main): release 9.9.0 (#1648) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- CHANGELOG.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f9d136f..0163c09c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,18 @@ # Changelog +## [9.9.0](https://github.com/LazyVim/LazyVim/compare/v9.8.0...v9.9.0) (2023-10-10) + + +### Features + +* **dap:** added run with args `leader-ca`. Fixes [#1629](https://github.com/LazyVim/LazyVim/issues/1629) ([b1c9fd1](https://github.com/LazyVim/LazyVim/commit/b1c9fd15bdbc0bae5bf1ba1efd88ce7355e7f2c1)) + + +### Bug Fixes + +* **hypr:** automatically update/install hypr treesitter parser when needed ([88d465c](https://github.com/LazyVim/LazyVim/commit/88d465c3efac065f912e1de162c9a48bbae15316)) +* **treesitter:** typo with commands ([599798a](https://github.com/LazyVim/LazyVim/commit/599798a366d5fead7e8486e1b02dd2362d2e6bd1)) + ## [9.8.0](https://github.com/LazyVim/LazyVim/compare/v9.7.0...v9.8.0) (2023-10-09) From 8e88aa51f4d104e9da4ced0b4e9ae05d91565a36 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 11 Oct 2023 12:42:26 +0000 Subject: [PATCH 02/83] chore(build): auto-generate vimdoc --- doc/LazyVim.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/LazyVim.txt b/doc/LazyVim.txt index 4bf837e5..a950794a 100644 --- a/doc/LazyVim.txt +++ b/doc/LazyVim.txt @@ -1,4 +1,4 @@ -*LazyVim.txt* For Neovim >= 0.8.0 Last change: 2023 October 10 +*LazyVim.txt* For Neovim >= 0.8.0 Last change: 2023 October 11 ============================================================================== Table of Contents *LazyVim-table-of-contents* From ee7a401388f2933729afcd7090fb8e69631b912f Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Wed, 11 Oct 2023 14:46:05 +0200 Subject: [PATCH 03/83] fix(config): disable LazyFile till v10.0 --- lua/lazyvim/config/init.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lua/lazyvim/config/init.lua b/lua/lazyvim/config/init.lua index c0319dcf..d993ac19 100644 --- a/lua/lazyvim/config/init.lua +++ b/lua/lazyvim/config/init.lua @@ -278,6 +278,7 @@ function M.init() M.use_lazy_file = M.use_lazy_file and vim.fn.argc(-1) > 0 ---@diagnostic disable-next-line: undefined-field M.use_lazy_file = M.use_lazy_file and require("lazy.core.handler.event").trigger_events == nil + M.use_lazy_file = false -- disablle for now till v10.0 -- delay notifications till vim.notify was replaced or after 500ms require("lazyvim.util").lazy_notify() @@ -314,6 +315,7 @@ function M.init() events[#events + 1] = event end end + plugin.event = events end end end From 61f1c308bf6b87c51a2b49c314c7c7379f19a27e Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 11 Oct 2023 15:00:18 +0200 Subject: [PATCH 04/83] chore(main): release 9.9.1 (#1661) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0163c09c..c1136f07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## [9.9.1](https://github.com/LazyVim/LazyVim/compare/v9.9.0...v9.9.1) (2023-10-11) + + +### Bug Fixes + +* **config:** disable LazyFile till v10.0 ([ee7a401](https://github.com/LazyVim/LazyVim/commit/ee7a401388f2933729afcd7090fb8e69631b912f)) + ## [9.9.0](https://github.com/LazyVim/LazyVim/compare/v9.8.0...v9.9.0) (2023-10-10) From 5f5acb5b88789f4eae4781d3bf2ab52f880b3b86 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Wed, 11 Oct 2023 14:56:29 +0200 Subject: [PATCH 05/83] Revert "fix(config): disable LazyFile till v10.0" This reverts commit ee7a401388f2933729afcd7090fb8e69631b912f. --- lua/lazyvim/config/init.lua | 2 -- 1 file changed, 2 deletions(-) diff --git a/lua/lazyvim/config/init.lua b/lua/lazyvim/config/init.lua index d993ac19..c0319dcf 100644 --- a/lua/lazyvim/config/init.lua +++ b/lua/lazyvim/config/init.lua @@ -278,7 +278,6 @@ function M.init() M.use_lazy_file = M.use_lazy_file and vim.fn.argc(-1) > 0 ---@diagnostic disable-next-line: undefined-field M.use_lazy_file = M.use_lazy_file and require("lazy.core.handler.event").trigger_events == nil - M.use_lazy_file = false -- disablle for now till v10.0 -- delay notifications till vim.notify was replaced or after 500ms require("lazyvim.util").lazy_notify() @@ -315,7 +314,6 @@ function M.init() events[#events + 1] = event end end - plugin.event = events end end end From c8c929c9fdc44cc69cb034c47bd89d2bc4e4a429 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Tue, 10 Oct 2023 19:29:24 +0200 Subject: [PATCH 06/83] perf(util): split lazyvim.util in smaller separate modules --- lua/lazyvim/config/init.lua | 27 +- lua/lazyvim/config/keymaps.lua | 12 +- lua/lazyvim/config/options.lua | 4 +- lua/lazyvim/plugins/editor.lua | 6 +- lua/lazyvim/plugins/extras/coding/codeium.lua | 6 +- lua/lazyvim/plugins/extras/coding/copilot.lua | 12 +- .../plugins/extras/editor/mini-files.lua | 2 +- lua/lazyvim/plugins/extras/lang/go.lua | 2 +- lua/lazyvim/plugins/extras/lang/python.lua | 2 +- lua/lazyvim/plugins/extras/lang/yaml.lua | 2 +- lua/lazyvim/plugins/lsp/init.lua | 13 +- lua/lazyvim/plugins/lsp/keymaps.lua | 4 +- lua/lazyvim/plugins/ui.lua | 12 +- lua/lazyvim/util/init.lua | 280 +++--------------- lua/lazyvim/util/lsp.lua | 112 +++++++ lua/lazyvim/util/root.lua | 49 +++ lua/lazyvim/util/telescope.lua | 53 ++++ lua/lazyvim/util/terminal.lua | 55 ++++ lua/lazyvim/util/toggle.lua | 62 ++++ lua/lazyvim/util/ui.lua | 10 + 20 files changed, 442 insertions(+), 283 deletions(-) create mode 100644 lua/lazyvim/util/lsp.lua create mode 100644 lua/lazyvim/util/root.lua create mode 100644 lua/lazyvim/util/telescope.lua create mode 100644 lua/lazyvim/util/terminal.lua create mode 100644 lua/lazyvim/util/toggle.lua diff --git a/lua/lazyvim/config/init.lua b/lua/lazyvim/config/init.lua index c0319dcf..23ca90d4 100644 --- a/lua/lazyvim/config/init.lua +++ b/lua/lazyvim/config/init.lua @@ -1,4 +1,4 @@ -local Util = require("lazy.core.util") +local Util = require("lazyvim.util") ---@class LazyVimConfig: LazyVimOptions local M = {} @@ -155,6 +155,7 @@ function M.setup(opts) M.load("autocmds") end M.load("keymaps") + Util.format.setup() end, }) @@ -240,18 +241,11 @@ end ---@param name "autocmds" | "options" | "keymaps" function M.load(name) local function _load(mod) - Util.try(function() - require(mod) - end, { - msg = "Failed loading " .. mod, - on_error = function(msg) - local info = require("lazy.core.cache").find(mod) - if info == nil or (type(info) == "table" and #info == 0) then - return - end - Util.error(msg) - end, - }) + if require("lazy.core.cache").find(mod)[1] then + Util.try(function() + require(mod) + end, { msg = "Failed loading " .. mod }) + end end -- always load lazyvim, then user file if M.defaults[name] or name == "options" then @@ -275,6 +269,11 @@ function M.init() vim.opt.rtp:append(plugin.dir) end + package.preload["lazyvim.plugins.lsp.format"] = function() + Util.deprecate([[require("lazyvim.plugins.lsp.format")]], [[require("lazyvim.util").format]]) + return Util.format + end + M.use_lazy_file = M.use_lazy_file and vim.fn.argc(-1) > 0 ---@diagnostic disable-next-line: undefined-field M.use_lazy_file = M.use_lazy_file and require("lazy.core.handler.event").trigger_events == nil @@ -285,7 +284,7 @@ function M.init() -- 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 - require("lazyvim.config").load("options") + M.load("options") local Plugin = require("lazy.core.plugin") local add = Plugin.Spec.add ---@diagnostic disable-next-line: duplicate-set-field diff --git a/lua/lazyvim/config/keymaps.lua b/lua/lazyvim/config/keymaps.lua index e8307f45..b60aa43e 100644 --- a/lua/lazyvim/config/keymaps.lua +++ b/lua/lazyvim/config/keymaps.lua @@ -105,8 +105,8 @@ map("n", "uf", require("lazyvim.plugins.lsp.format").toggle, { desc = "T map("n", "us", function() Util.toggle("spell") end, { desc = "Toggle Spelling" }) map("n", "uw", function() Util.toggle("wrap") end, { desc = "Toggle Word Wrap" }) map("n", "uL", function() Util.toggle("relativenumber") end, { desc = "Toggle Relative Line Numbers" }) -map("n", "ul", function() Util.toggle_number() end, { desc = "Toggle Line Numbers" }) -map("n", "ud", Util.toggle_diagnostics, { desc = "Toggle Diagnostics" }) +map("n", "ul", function() Util.toggle.number() end, { desc = "Toggle Line Numbers" }) +map("n", "ud", function() Util.toggle.diagnostics() end, { desc = "Toggle Diagnostics" }) local conceallevel = vim.o.conceallevel > 0 and vim.o.conceallevel or 3 map("n", "uc", function() Util.toggle("conceallevel", false, {0, conceallevel}) end, { desc = "Toggle Conceal" }) if vim.lsp.inlay_hint then @@ -114,8 +114,8 @@ if vim.lsp.inlay_hint then end -- lazygit -map("n", "gg", function() Util.float_term({ "lazygit" }, { cwd = Util.get_root(), esc_esc = false, ctrl_hjkl = false }) end, { desc = "Lazygit (root dir)" }) -map("n", "gG", function() Util.float_term({ "lazygit" }, {esc_esc = false, ctrl_hjkl = false}) end, { desc = "Lazygit (cwd)" }) +map("n", "gg", function() Util.terminal({ "lazygit" }, { cwd = Util.root.get(), esc_esc = false, ctrl_hjkl = false }) end, { desc = "Lazygit (root dir)" }) +map("n", "gG", function() Util.terminal({ "lazygit" }, {esc_esc = false, ctrl_hjkl = false}) end, { desc = "Lazygit (cwd)" }) -- quit map("n", "qq", "qa", { desc = "Quit all" }) @@ -127,9 +127,9 @@ map("n", "ui", vim.show_pos, { desc = "Inspect Pos" }) map("n", "L", Util.changelog, {desc = "LazyVim Changelog"}) -- floating terminal -local lazyterm = function() Util.float_term(nil, { cwd = Util.get_root() }) end +local lazyterm = function() Util.terminal(nil, { cwd = Util.root.get() }) end map("n", "ft", lazyterm, { desc = "Terminal (root dir)" }) -map("n", "fT", function() Util.float_term() end, { desc = "Terminal (cwd)" }) +map("n", "fT", function() Util.terminal() end, { desc = "Terminal (cwd)" }) map("n", "", lazyterm, { desc = "Terminal (root dir)" }) map("n", "", lazyterm, { desc = "which_key_ignore" }) diff --git a/lua/lazyvim/config/options.lua b/lua/lazyvim/config/options.lua index f110f7fb..e2ae9485 100644 --- a/lua/lazyvim/config/options.lua +++ b/lua/lazyvim/config/options.lua @@ -63,10 +63,10 @@ end -- Folding vim.opt.foldlevel = 99 -vim.opt.foldtext = "v:lua.require'lazyvim.util.ui'.foldtext()" +vim.opt.foldtext = "v:lua.require'lazyvim.util'.ui.foldtext()" if vim.fn.has("nvim-0.9.0") == 1 then - vim.opt.statuscolumn = [[%!v:lua.require'lazyvim.util.ui'.statuscolumn()]] + vim.opt.statuscolumn = [[%!v:lua.require'lazyvim.util'.ui.statuscolumn()]] end -- HACK: causes freezes on <= 0.9, so only enable on >= 0.10 for now diff --git a/lua/lazyvim/plugins/editor.lua b/lua/lazyvim/plugins/editor.lua index e8df2e0b..0fb63944 100644 --- a/lua/lazyvim/plugins/editor.lua +++ b/lua/lazyvim/plugins/editor.lua @@ -11,7 +11,7 @@ return { { "fe", function() - require("neo-tree.command").execute({ toggle = true, dir = require("lazyvim.util").get_root() }) + require("neo-tree.command").execute({ toggle = true, dir = Util.root.get() }) end, desc = "Explorer NeoTree (root dir)", }, @@ -60,7 +60,7 @@ return { }, config = function(_, opts) local function on_move(data) - Util.on_rename(data.source, data.destination) + Util.lsp.on_rename(data.source, data.destination) end local events = require("neo-tree.events") @@ -270,7 +270,7 @@ return { "nvim-telescope/telescope.nvim", optional = true, opts = function(_, opts) - if not require("lazyvim.util").has("flash.nvim") then + if not Util.has("flash.nvim") then return end local function flash(prompt_bufnr) diff --git a/lua/lazyvim/plugins/extras/coding/codeium.lua b/lua/lazyvim/plugins/extras/coding/codeium.lua index f8d4c671..457535cd 100644 --- a/lua/lazyvim/plugins/extras/coding/codeium.lua +++ b/lua/lazyvim/plugins/extras/coding/codeium.lua @@ -49,9 +49,9 @@ return { local Util = require("lazyvim.util") local colors = { - ok = Util.fg("Special"), - error = Util.fg("DiagnosticError"), - pending = Util.fg("DiagnosticWarn"), + ok = Util.ui.fg("Special"), + error = Util.ui.fg("DiagnosticError"), + pending = Util.ui.fg("DiagnosticWarn"), } table.insert(opts.sections.lualine_x, 2, { function() diff --git a/lua/lazyvim/plugins/extras/coding/copilot.lua b/lua/lazyvim/plugins/extras/coding/copilot.lua index 38630917..279a974f 100644 --- a/lua/lazyvim/plugins/extras/coding/copilot.lua +++ b/lua/lazyvim/plugins/extras/coding/copilot.lua @@ -21,10 +21,10 @@ return { opts = function(_, opts) local Util = require("lazyvim.util") local colors = { - [""] = Util.fg("Special"), - ["Normal"] = Util.fg("Special"), - ["Warning"] = Util.fg("DiagnosticError"), - ["InProgress"] = Util.fg("DiagnosticWarn"), + [""] = Util.ui.fg("Special"), + ["Normal"] = Util.ui.fg("Special"), + ["Warning"] = Util.ui.fg("DiagnosticError"), + ["InProgress"] = Util.ui.fg("DiagnosticWarn"), } table.insert(opts.sections.lualine_x, 2, { function() @@ -36,7 +36,7 @@ return { if not package.loaded["copilot"] then return end - local ok, clients = pcall(require("lazyvim.util").get_clients, { name = "copilot", bufnr = 0 }) + local ok, clients = pcall(require("lazyvim.util").lsp.get_clients, { name = "copilot", bufnr = 0 }) if not ok then return false end @@ -66,7 +66,7 @@ return { copilot_cmp.setup(opts) -- attach cmp source whenever copilot attaches -- fixes lazy-loading issues with the copilot cmp source - require("lazyvim.util").on_attach(function(client) + require("lazyvim.util").lsp.on_attach(function(client) if client.name == "copilot" then copilot_cmp._on_insert_enter({}) end diff --git a/lua/lazyvim/plugins/extras/editor/mini-files.lua b/lua/lazyvim/plugins/extras/editor/mini-files.lua index c3ddd273..55fc768c 100644 --- a/lua/lazyvim/plugins/extras/editor/mini-files.lua +++ b/lua/lazyvim/plugins/extras/editor/mini-files.lua @@ -57,7 +57,7 @@ return { vim.api.nvim_create_autocmd("User", { pattern = "MiniFilesActionRename", callback = function(event) - require("lazyvim.util").on_rename(event.data.from, event.data.to) + require("lazyvim.util").lsp.on_rename(event.data.from, event.data.to) end, }) end, diff --git a/lua/lazyvim/plugins/extras/lang/go.lua b/lua/lazyvim/plugins/extras/lang/go.lua index b9966b7e..39410353 100644 --- a/lua/lazyvim/plugins/extras/lang/go.lua +++ b/lua/lazyvim/plugins/extras/lang/go.lua @@ -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").on_attach(function(client, _) + require("lazyvim.util").lsp.on_attach(function(client, _) if client.name == "gopls" then if not client.server_capabilities.semanticTokensProvider then local semantic = client.config.capabilities.textDocument.semanticTokens diff --git a/lua/lazyvim/plugins/extras/lang/python.lua b/lua/lazyvim/plugins/extras/lang/python.lua index ff4267fb..835c9da8 100644 --- a/lua/lazyvim/plugins/extras/lang/python.lua +++ b/lua/lazyvim/plugins/extras/lang/python.lua @@ -16,7 +16,7 @@ return { }, setup = { ruff_lsp = function() - require("lazyvim.util").on_attach(function(client, _) + require("lazyvim.util").lsp.on_attach(function(client, _) if client.name == "ruff_lsp" then -- Disable hover in favor of Pyright client.server_capabilities.hoverProvider = false diff --git a/lua/lazyvim/plugins/extras/lang/yaml.lua b/lua/lazyvim/plugins/extras/lang/yaml.lua index fdfba404..5afe1b83 100644 --- a/lua/lazyvim/plugins/extras/lang/yaml.lua +++ b/lua/lazyvim/plugins/extras/lang/yaml.lua @@ -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").on_attach(function(client, _) + require("lazyvim.util").lsp.on_attach(function(client, _) if client.name == "yamlls" then client.server_capabilities.documentFormattingProvider = true end diff --git a/lua/lazyvim/plugins/lsp/init.lua b/lua/lazyvim/plugins/lsp/init.lua index bdef1a74..f18eed4f 100644 --- a/lua/lazyvim/plugins/lsp/init.lua +++ b/lua/lazyvim/plugins/lsp/init.lua @@ -1,3 +1,5 @@ +local Util = require("lazyvim.util") + return { -- lspconfig { @@ -88,6 +90,8 @@ return { require("lazyvim.plugins.lsp.format").setup(opts) -- setup formatting and keymaps Util.on_attach(function(client, buffer) + -- setup keymaps + Util.lsp.on_attach(function(client, buffer) require("lazyvim.plugins.lsp.keymaps").on_attach(client, buffer) end) @@ -112,7 +116,7 @@ return { local inlay_hint = vim.lsp.buf.inlay_hint or vim.lsp.inlay_hint if opts.inlay_hints.enabled and inlay_hint then - Util.on_attach(function(client, buffer) + Util.lsp.on_attach(function(client, buffer) if client.supports_method("textDocument/inlayHint") then inlay_hint(buffer, true) end @@ -184,10 +188,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 Util.lsp.get_config("denols") and Util.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) + Util.lsp.disable("tsserver", is_deno) + Util.lsp.disable("denols", function(root_dir) return not is_deno(root_dir) end) end @@ -208,7 +212,6 @@ return { nls.builtins.diagnostics.fish, nls.builtins.formatting.stylua, nls.builtins.formatting.shfmt, - -- nls.builtins.diagnostics.flake8, }, } end, diff --git a/lua/lazyvim/plugins/lsp/keymaps.lua b/lua/lazyvim/plugins/lsp/keymaps.lua index ad05b334..7b9c2189 100644 --- a/lua/lazyvim/plugins/lsp/keymaps.lua +++ b/lua/lazyvim/plugins/lsp/keymaps.lua @@ -66,7 +66,7 @@ end ---@param method string function M.has(buffer, method) method = method:find("/") and method or "textDocument/" .. method - local clients = require("lazyvim.util").get_clients({ bufnr = buffer }) + local clients = require("lazyvim.util").lsp.get_clients({ bufnr = buffer }) for _, client in ipairs(clients) do if client.supports_method(method) then return true @@ -83,7 +83,7 @@ function M.resolve(buffer) end local spec = M.get() local opts = require("lazyvim.util").opts("nvim-lspconfig") - local clients = require("lazyvim.util").get_clients({ bufnr = buffer }) + local clients = require("lazyvim.util").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) diff --git a/lua/lazyvim/plugins/ui.lua b/lua/lazyvim/plugins/ui.lua index d4e8859b..f1bac031 100644 --- a/lua/lazyvim/plugins/ui.lua +++ b/lua/lazyvim/plugins/ui.lua @@ -141,21 +141,21 @@ return { { 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.fg("Statement"), + color = Util.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.fg("Constant"), + color = Util.ui.fg("Constant"), }, -- stylua: ignore { function() return " " .. require("dap").status() end, cond = function () return package.loaded["dap"] and require("dap").status() ~= "" end, - color = Util.fg("Debug"), + color = Util.ui.fg("Debug"), }, - { require("lazy.status").updates, cond = require("lazy.status").has_updates, color = Util.fg("Special") }, + { require("lazy.status").updates, cond = require("lazy.status").has_updates, color = Util.ui.fg("Special") }, { "diff", symbols = { @@ -374,8 +374,8 @@ return { lazy = true, init = function() vim.g.navic_silence = true - require("lazyvim.util").on_attach(function(client, buffer) - if client.server_capabilities.documentSymbolProvider then + require("lazyvim.util").lsp.on_attach(function(client, buffer) + if client.supports_method("textDocument/documentSymbol") then require("nvim-navic").attach(client, buffer) end end) diff --git a/lua/lazyvim/util/init.lua b/lua/lazyvim/util/init.lua index 05bc8154..146e73e2 100644 --- a/lua/lazyvim/util/init.lua +++ b/lua/lazyvim/util/init.lua @@ -1,38 +1,54 @@ -local Util = require("lazy.core.util") +local LazyUtil = require("lazy.core.util") +---@class lazyvim.util: LazyUtilCore +---@field ui lazyvim.util.ui +---@field lsp lazyvim.util.lsp +---@field root lazyvim.util.root +---@field telescope lazyvim.util.telescope +---@field terminal lazyvim.util.terminal +---@field toggle lazyvim.util.toggle +---@field format lazyvim.util.format local M = {} -M.root_patterns = { ".git", "lua" } -function M.get_clients(...) - local fn = vim.lsp.get_clients or vim.lsp.get_active_clients - return fn(...) -end +---@type table +local deprecated = { + get_clients = "lsp", + on_attach = "lsp", + on_rename = "lsp", + root_patterns = { "root", "patterns" }, + get_root = { "root", "get" }, + float_term = { "terminal", "open" }, + toggle = { "toggle", "option" }, + toggle_diagnostics = { "toggle", "diagnostics" }, + toggle_number = { "toggle", "number" }, + fg = "ui", +} ----@param on_attach fun(client, buffer) -function M.on_attach(on_attach) - vim.api.nvim_create_autocmd("LspAttach", { - callback = function(args) - local buffer = args.buf ---@type number - local client = vim.lsp.get_client_by_id(args.data.client_id) - on_attach(client, buffer) - end, - }) -end +setmetatable(M, { + __index = function(t, k) + if LazyUtil[k] then + return LazyUtil[k] + end + local dep = deprecated[k] + 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) + ---@diagnostic disable-next-line: no-unknown + t[mod] = require("lazyvim.util." .. mod) -- load here to prevent loops + return t[mod][key] + end + ---@diagnostic disable-next-line: no-unknown + t[k] = require("lazyvim.util." .. k) + return t[k] + end, +}) ---@param plugin string function M.has(plugin) return require("lazy.core.config").spec.plugins[plugin] ~= nil end -function M.fg(name) - ---@type {foreground?:number}? - ---@diagnostic disable-next-line: deprecated - local hl = vim.api.nvim_get_hl and vim.api.nvim_get_hl(0, { name = name }) or vim.api.nvim_get_hl_by_name(name, true) - ---@diagnostic disable-next-line: undefined-field - local fg = hl and (hl.fg or hl.foreground) - return fg and { fg = string.format("#%06x", fg) } or nil -end - ---@param fn fun() function M.on_very_lazy(fn) vim.api.nvim_create_autocmd("User", { @@ -53,173 +69,13 @@ function M.opts(name) return Plugin.values(plugin, "opts", false) end --- returns the root directory based on: --- * lsp workspace folders --- * lsp root_dir --- * root pattern of filename of the current buffer --- * root pattern of cwd ----@return string -function M.get_root() - ---@type string? - local path = vim.api.nvim_buf_get_name(0) - path = path ~= "" and vim.loop.fs_realpath(path) or nil - ---@type string[] - local roots = {} - if path then - for _, client in pairs(M.get_clients({ bufnr = 0 })) do - local workspace = client.config.workspace_folders - local paths = workspace and vim.tbl_map(function(ws) - return vim.uri_to_fname(ws.uri) - end, workspace) or client.config.root_dir and { client.config.root_dir } or {} - for _, p in ipairs(paths) do - local r = vim.loop.fs_realpath(p) - if path:find(r, 1, true) then - roots[#roots + 1] = r - end - end - end - end - table.sort(roots, function(a, b) - return #a > #b - end) - ---@type string? - local root = roots[1] - if not root then - path = path and vim.fs.dirname(path) or vim.loop.cwd() - ---@type string? - root = vim.fs.find(M.root_patterns, { path = path, upward = true })[1] - root = root and vim.fs.dirname(root) or vim.loop.cwd() - end - ---@cast root string - return root -end - --- this will return a function that calls telescope. --- cwd will default to lazyvim.util.get_root --- for `files`, git_files or find_files will be chosen depending on .git -function M.telescope(builtin, opts) - local params = { builtin = builtin, opts = opts } - return function() - builtin = params.builtin - opts = params.opts - opts = vim.tbl_deep_extend("force", { cwd = M.get_root() }, opts or {}) - if builtin == "files" then - if vim.loop.fs_stat((opts.cwd or vim.loop.cwd()) .. "/.git") then - opts.show_untracked = true - builtin = "git_files" - else - builtin = "find_files" - end - end - if opts.cwd and opts.cwd ~= vim.loop.cwd() then - opts.attach_mappings = function(_, map) - map("i", "", function() - local action_state = require("telescope.actions.state") - local line = action_state.get_current_line() - M.telescope( - params.builtin, - vim.tbl_deep_extend("force", {}, params.opts or {}, { cwd = false, default_text = line }) - )() - end) - return true - end - end - - require("telescope.builtin")[builtin](opts) - end -end - ----@type table -local terminals = {} - --- Opens a floating terminal (interactive by default) ----@param cmd? string[]|string ----@param opts? LazyCmdOptions|{interactive?:boolean, esc_esc?:false, ctrl_hjkl?:false} -function M.float_term(cmd, opts) - opts = vim.tbl_deep_extend("force", { - ft = "lazyterm", - size = { width = 0.9, height = 0.9 }, - }, opts or {}, { persistent = true }) - ---@cast opts LazyCmdOptions|{interactive?:boolean, esc_esc?:false} - - local termkey = vim.inspect({ cmd = cmd or "shell", cwd = opts.cwd, env = opts.env, count = vim.v.count1 }) - - if terminals[termkey] and terminals[termkey]:buf_valid() then - terminals[termkey]:toggle() - else - terminals[termkey] = require("lazy.util").float_term(cmd, opts) - local buf = terminals[termkey].buf - vim.b[buf].lazyterm_cmd = cmd - if opts.esc_esc == false then - vim.keymap.set("t", "", "", { buffer = buf, nowait = true }) - end - if opts.ctrl_hjkl == false then - vim.keymap.set("t", "", "", { buffer = buf, nowait = true }) - vim.keymap.set("t", "", "", { buffer = buf, nowait = true }) - vim.keymap.set("t", "", "", { buffer = buf, nowait = true }) - vim.keymap.set("t", "", "", { buffer = buf, nowait = true }) - end - - vim.api.nvim_create_autocmd("BufEnter", { - buffer = buf, - callback = function() - vim.cmd.startinsert() - end, - }) - end - - return terminals[termkey] -end - ----@param silent boolean? ----@param values? {[1]:any, [2]:any} -function M.toggle(option, silent, values) - if values then - if vim.opt_local[option]:get() == values[1] then - vim.opt_local[option] = values[2] - else - vim.opt_local[option] = values[1] - end - return Util.info("Set " .. option .. " to " .. vim.opt_local[option]:get(), { title = "Option" }) - end - 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" }) - else - Util.warn("Disabled " .. option, { title = "Option" }) - end - end -end - -local nu = { number = true, relativenumber = true } -function M.toggle_number() - if vim.opt_local.number:get() or vim.opt_local.relativenumber:get() then - 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" }) - else - vim.opt_local.number = nu.number - vim.opt_local.relativenumber = nu.relativenumber - Util.info("Enabled line numbers", { title = "Option" }) - end -end - -local enabled = true -function M.toggle_diagnostics() - enabled = not enabled - if enabled then - vim.diagnostic.enable() - Util.info("Enabled diagnostics", { title = "Diagnostics" }) - else - vim.diagnostic.disable() - Util.warn("Disabled diagnostics", { title = "Diagnostics" }) - end -end - function M.deprecate(old, new) - Util.warn(("`%s` is deprecated. Please use `%s` instead"):format(old, new), { title = "LazyVim" }) + M.warn(("`%s` is deprecated. Please use `%s` instead"):format(old, new), { + title = "LazyVim", + once = true, + stacktrace = true, + stacklevel = 6, + }) end -- delay notifications till vim.notify was replaced or after 500ms @@ -259,25 +115,6 @@ function M.lazy_notify() timer:start(500, 0, replay) end ----@return _.lspconfig.options -function M.lsp_get_config(server) - local configs = require("lspconfig.configs") - return rawget(configs, server) -end - ----@param server string ----@param cond fun( root_dir, config): boolean -function M.lsp_disable(server, cond) - local util = require("lspconfig.util") - local def = M.lsp_get_config(server) - ---@diagnostic disable-next-line: undefined-field - def.document_config.on_new_config = util.add_hook_before(def.document_config.on_new_config, function(config, root_dir) - if cond(root_dir, config) then - config.enabled = false - end - end) -end - ---@param name string ---@param fn fun(name:string) function M.on_load(name, fn) @@ -305,28 +142,6 @@ function M.changelog() vim.diagnostic.disable(float.buf) end ----@param from string ----@param to string -function M.on_rename(from, to) - local clients = M.get_clients() - for _, client in ipairs(clients) do - if client.supports_method("workspace/willRenameFiles") then - ---@diagnostic disable-next-line: invisible - local resp = client.request_sync("workspace/willRenameFiles", { - files = { - { - oldUri = vim.uri_from_fname(from), - newUri = vim.uri_from_fname(to), - }, - }, - }, 1000, 0) - if resp and resp.result ~= nil then - vim.lsp.util.apply_workspace_edit(resp.result, client.offset_encoding) - end - end - end -end - -- Wrapper around vim.keymap.set that will -- not create a keymap if a lazy key handler exists. -- It will also set `silent` to true by default. @@ -345,6 +160,7 @@ function M.safe_keymap_set(mode, lhs, rhs, opts) opts = opts or {} opts.silent = opts.silent ~= false if opts.remap and not vim.g.vscode then + ---@diagnostic disable-next-line: no-unknown opts.remap = nil end vim.keymap.set(modes, lhs, rhs, opts) diff --git a/lua/lazyvim/util/lsp.lua b/lua/lazyvim/util/lsp.lua new file mode 100644 index 00000000..d5903cd8 --- /dev/null +++ b/lua/lazyvim/util/lsp.lua @@ -0,0 +1,112 @@ +---@class lazyvim.util.lsp +local M = {} + +function M.get_clients(...) + ---@diagnostic disable-next-line: deprecated + local fn = vim.lsp.get_clients or vim.lsp.get_active_clients + return fn(...) +end + +---@param on_attach fun(client, buffer) +function M.on_attach(on_attach) + vim.api.nvim_create_autocmd("LspAttach", { + callback = function(args) + local buffer = args.buf ---@type number + local client = vim.lsp.get_client_by_id(args.data.client_id) + on_attach(client, buffer) + end, + }) +end + +---@param from string +---@param to string +function M.on_rename(from, to) + local clients = M.get_clients() + for _, client in ipairs(clients) do + if client.supports_method("workspace/willRenameFiles") then + ---@diagnostic disable-next-line: invisible + local resp = client.request_sync("workspace/willRenameFiles", { + files = { + { + oldUri = vim.uri_from_fname(from), + newUri = vim.uri_from_fname(to), + }, + }, + }, 1000, 0) + if resp and resp.result ~= nil then + vim.lsp.util.apply_workspace_edit(resp.result, client.offset_encoding) + end + end + end +end + +---@return _.lspconfig.options +function M.get_config(server) + local configs = require("lspconfig.configs") + return rawget(configs, server) +end + +---@param server string +---@param cond fun( root_dir, config): boolean +function M.disable(server, cond) + local util = require("lspconfig.util") + local def = M.get_config(server) + ---@diagnostic disable-next-line: undefined-field + def.document_config.on_new_config = util.add_hook_before(def.document_config.on_new_config, function(config, root_dir) + if cond(root_dir, config) then + config.enabled = false + end + end) +end + +---@alias lsp.Client.filter fun(client: lsp.Client): boolean + +---@param name string +---@return lsp.Client.filter +function M.filter(name) + return function(client) + return client.name == name + end +end + +---@param opts? LazyFormatter| {filter?: (string|lsp.Client.filter), bufnr?: number} +function M.formatter(opts) + opts = opts or {} + local filter = opts.filter + filter = type(filter) == "string" and M.filter(filter) or filter + ---@cast filter lsp.Client.filter? + ---@type LazyFormatter + local ret = { + name = "LSP", + primary = true, + priority = 1, + format = function(buf) + M.format({ bufnr = buf, filter = filter }) + end, + sources = function(buf) + local clients = M.get_clients({ bufnr = buf }) + ---@param client lsp.Client + local ret = vim.tbl_filter(function(client) + return (not filter or filter(client)) + and ( + client.supports_method("textDocument/formatting") + or client.supports_method("textDocument/rangeFormatting") + ) + end, clients) + ---@param client lsp.Client + return vim.tbl_map(function(client) + return client.name + end, ret) + end, + } + return vim.tbl_deep_extend("force", ret, opts) --[[@as LazyFormatter]] +end + +---@param opts? {filter?: lsp.Client.filter, bufnr?: number} +function M.format(opts) + vim.lsp.buf.format( + vim.tbl_deep_extend("force", opts or {}, require("lazyvim.util").opts("nvim-lspconfig").format or {}) + ) +end + +return M diff --git a/lua/lazyvim/util/root.lua b/lua/lazyvim/util/root.lua new file mode 100644 index 00000000..296e045b --- /dev/null +++ b/lua/lazyvim/util/root.lua @@ -0,0 +1,49 @@ +local Util = require("lazyvim.util") + +---@class lazyvim.util.root +local M = {} + +M.patterns = { ".git", "lua" } + +-- returns the root directory based on: +-- * lsp workspace folders +-- * lsp root_dir +-- * root pattern of filename of the current buffer +-- * root pattern of cwd +---@return string +function M.get() + ---@type string? + local path = vim.api.nvim_buf_get_name(0) + path = path ~= "" and vim.loop.fs_realpath(path) or nil + ---@type string[] + local roots = {} + if path then + for _, client in pairs(Util.lsp.get_clients({ bufnr = 0 })) do + local workspace = client.config.workspace_folders + local paths = workspace and vim.tbl_map(function(ws) + return vim.uri_to_fname(ws.uri) + end, workspace) or client.config.root_dir and { client.config.root_dir } or {} + for _, p in ipairs(paths) do + local r = vim.loop.fs_realpath(p) + if path:find(r, 1, true) then + roots[#roots + 1] = r + end + end + end + end + table.sort(roots, function(a, b) + return #a > #b + end) + ---@type string? + local root = roots[1] + if not root then + path = path and vim.fs.dirname(path) or vim.loop.cwd() + ---@type string? + root = vim.fs.find(M.patterns, { path = path, upward = true })[1] + root = root and vim.fs.dirname(root) or vim.loop.cwd() + end + ---@cast root string + return root +end + +return M diff --git a/lua/lazyvim/util/telescope.lua b/lua/lazyvim/util/telescope.lua new file mode 100644 index 00000000..2aae403d --- /dev/null +++ b/lua/lazyvim/util/telescope.lua @@ -0,0 +1,53 @@ +local Util = require("lazyvim.util") + +---@class lazyvim.util.telescope.opts +---@field cwd? string|boolean +---@field show_untracked? boolean + +---@class lazyvim.util.telescope +---@overload fun(builtin:string, opts?:lazyvim.util.telescope.opts) +local M = setmetatable({}, { + __call = function(m, ...) + return m.telescope(...) + end, +}) + +-- this will return a function that calls telescope. +-- cwd will default to lazyvim.util.get_root +-- for `files`, git_files or find_files will be chosen depending on .git +---@param builtin string +---@param opts? lazyvim.util.telescope.opts +function M.telescope(builtin, opts) + local params = { builtin = builtin, opts = opts } + return function() + builtin = params.builtin + opts = params.opts + opts = vim.tbl_deep_extend("force", { cwd = Util.root.get() }, opts or {}) --[[@as lazyvim.util.telescope.opts]] + if builtin == "files" then + if vim.loop.fs_stat((opts.cwd or vim.loop.cwd()) .. "/.git") then + opts.show_untracked = true + builtin = "git_files" + else + builtin = "find_files" + end + end + if opts.cwd and opts.cwd ~= vim.loop.cwd() then + ---@diagnostic disable-next-line: inject-field + opts.attach_mappings = function(_, map) + map("i", "", function() + local action_state = require("telescope.actions.state") + local line = action_state.get_current_line() + M.telescope( + params.builtin, + vim.tbl_deep_extend("force", {}, params.opts or {}, { cwd = false, default_text = line }) + )() + end) + return true + end + end + + require("telescope.builtin")[builtin](opts) + end +end + +return M diff --git a/lua/lazyvim/util/terminal.lua b/lua/lazyvim/util/terminal.lua new file mode 100644 index 00000000..7787615b --- /dev/null +++ b/lua/lazyvim/util/terminal.lua @@ -0,0 +1,55 @@ +---@class lazyvim.util.terminal +---@overload fun(cmd: string|string[], opts: LazyTermOpts): LazyFloat +local M = setmetatable({}, { + __call = function(m, ...) + return m.open(...) + end, +}) + +---@type table +local terminals = {} + +---@class LazyTermOpts: LazyCmdOptions +---@field interactive? boolean +---@field esc_esc? boolean +---@field ctrl_hjkl? boolean + +-- Opens a floating terminal (interactive by default) +---@param cmd? string[]|string +---@param opts? LazyTermOpts +function M.open(cmd, opts) + opts = vim.tbl_deep_extend("force", { + ft = "lazyterm", + size = { width = 0.9, height = 0.9 }, + }, opts or {}, { persistent = true }) --[[@as LazyTermOpts]] + + local termkey = vim.inspect({ cmd = cmd or "shell", cwd = opts.cwd, env = opts.env, count = vim.v.count1 }) + + if terminals[termkey] and terminals[termkey]:buf_valid() then + terminals[termkey]:toggle() + else + terminals[termkey] = require("lazy.util").float_term(cmd, opts) + local buf = terminals[termkey].buf + vim.b[buf].lazyterm_cmd = cmd + if opts.esc_esc == false then + vim.keymap.set("t", "", "", { buffer = buf, nowait = true }) + end + if opts.ctrl_hjkl == false then + vim.keymap.set("t", "", "", { buffer = buf, nowait = true }) + vim.keymap.set("t", "", "", { buffer = buf, nowait = true }) + vim.keymap.set("t", "", "", { buffer = buf, nowait = true }) + vim.keymap.set("t", "", "", { buffer = buf, nowait = true }) + end + + vim.api.nvim_create_autocmd("BufEnter", { + buffer = buf, + callback = function() + vim.cmd.startinsert() + end, + }) + end + + return terminals[termkey] +end + +return M diff --git a/lua/lazyvim/util/toggle.lua b/lua/lazyvim/util/toggle.lua new file mode 100644 index 00000000..b520070b --- /dev/null +++ b/lua/lazyvim/util/toggle.lua @@ -0,0 +1,62 @@ +local Util = require("lazyvim.util") + +---@class lazyvim.util.toggle +local M = {} + +---@param silent boolean? +---@param values? {[1]:any, [2]:any} +function M.option(option, silent, values) + if values then + if vim.opt_local[option]:get() == values[1] then + ---@diagnostic disable-next-line: no-unknown + vim.opt_local[option] = values[2] + else + ---@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" }) + 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" }) + else + Util.warn("Disabled " .. option, { title = "Option" }) + end + end +end + +local nu = { number = true, relativenumber = true } +function M.number() + if vim.opt_local.number:get() or vim.opt_local.relativenumber:get() then + 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" }) + else + vim.opt_local.number = nu.number + vim.opt_local.relativenumber = nu.relativenumber + Util.info("Enabled line numbers", { title = "Option" }) + end +end + +local enabled = true +function M.diagnostics() + enabled = not enabled + if enabled then + vim.diagnostic.enable() + Util.info("Enabled diagnostics", { title = "Diagnostics" }) + else + vim.diagnostic.disable() + Util.warn("Disabled diagnostics", { title = "Diagnostics" }) + end +end + +setmetatable(M, { + __call = function(m, ...) + return m.option(...) + end, +}) + +return M diff --git a/lua/lazyvim/util/ui.lua b/lua/lazyvim/util/ui.lua index 66ec4bca..22b70e4b 100644 --- a/lua/lazyvim/util/ui.lua +++ b/lua/lazyvim/util/ui.lua @@ -1,3 +1,4 @@ +---@class lazyvim.util.ui local M = {} ---@alias Sign {name:string, text:string, texthl:string, priority:number} @@ -119,4 +120,13 @@ function M.statuscolumn() }, "") end +function M.fg(name) + ---@type {foreground?:number}? + ---@diagnostic disable-next-line: deprecated + local hl = vim.api.nvim_get_hl and vim.api.nvim_get_hl(0, { name = name }) or vim.api.nvim_get_hl_by_name(name, true) + ---@diagnostic disable-next-line: undefined-field + local fg = hl and (hl.fg or hl.foreground) + return fg and { fg = string.format("#%06x", fg) } or nil +end + return M From f1a8f24a361d0de198f6b1458168652a6835c932 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Tue, 10 Oct 2023 19:31:08 +0200 Subject: [PATCH 07/83] feat(format): new LazyVim formatter with integrations for lsp/none-ls/conform/eslint/... --- lua/lazyvim/config/keymaps.lua | 5 +- lua/lazyvim/config/options.lua | 3 + .../plugins/extras/formatting/conform.lua | 17 +- lua/lazyvim/plugins/extras/linting/eslint.lua | 35 +++-- lua/lazyvim/plugins/lsp/format.lua | 126 --------------- lua/lazyvim/plugins/lsp/init.lua | 40 ++++- lua/lazyvim/util/format.lua | 147 ++++++++++++++++++ 7 files changed, 225 insertions(+), 148 deletions(-) delete mode 100644 lua/lazyvim/plugins/lsp/format.lua create mode 100644 lua/lazyvim/util/format.lua diff --git a/lua/lazyvim/config/keymaps.lua b/lua/lazyvim/config/keymaps.lua index b60aa43e..ced9cdf7 100644 --- a/lua/lazyvim/config/keymaps.lua +++ b/lua/lazyvim/config/keymaps.lua @@ -95,13 +95,14 @@ end -- formatting map({ "n", "v" }, "cf", function() - require("lazyvim.plugins.lsp.format").format({ force = true }) + Util.format({ force = true }) end, { desc = "Format" }) -- stylua: ignore start -- toggle options -map("n", "uf", require("lazyvim.plugins.lsp.format").toggle, { desc = "Toggle format on Save" }) +map("n", "uf", function() Util.format.toggle() end, { desc = "Toggle auto format (global)" }) +map("n", "uF", function() Util.format.toggle(true) end, { desc = "Toggle auto format (buffer)" }) map("n", "us", function() Util.toggle("spell") end, { desc = "Toggle Spelling" }) map("n", "uw", function() Util.toggle("wrap") end, { desc = "Toggle Word Wrap" }) map("n", "uL", function() Util.toggle("relativenumber") end, { desc = "Toggle Relative Line Numbers" }) diff --git a/lua/lazyvim/config/options.lua b/lua/lazyvim/config/options.lua index e2ae9485..1649896b 100644 --- a/lua/lazyvim/config/options.lua +++ b/lua/lazyvim/config/options.lua @@ -2,6 +2,9 @@ vim.g.mapleader = " " vim.g.maplocalleader = "\\" +-- Enable LazyVim auto format +vim.g.autoformat = true + local opt = vim.opt opt.autowrite = true -- Enable auto write diff --git a/lua/lazyvim/plugins/extras/formatting/conform.lua b/lua/lazyvim/plugins/extras/formatting/conform.lua index 601967c5..855e356e 100644 --- a/lua/lazyvim/plugins/extras/formatting/conform.lua +++ b/lua/lazyvim/plugins/extras/formatting/conform.lua @@ -18,9 +18,20 @@ return { vim.o.formatexpr = "v:lua.require'conform'.formatexpr()" -- Install the conform formatter on VeryLazy require("lazyvim.util").on_very_lazy(function() - require("lazyvim.plugins.lsp.format").custom_format = function(buf) - return require("conform").format({ bufnr = buf }) - end + require("lazyvim.util").format.register({ + name = "conform.nvim", + priority = 100, + primary = true, + format = function(buf) + require("conform").format({ bufnr = buf }) + end, + sources = function(buf) + local ret = require("conform").list_formatters(buf) + return vim.tbl_map(function(v) + return v.name + end, ret) + end, + }) end) end, opts = { diff --git a/lua/lazyvim/plugins/extras/linting/eslint.lua b/lua/lazyvim/plugins/extras/linting/eslint.lua index 1fea3c8c..9537303d 100644 --- a/lua/lazyvim/plugins/extras/linting/eslint.lua +++ b/lua/lazyvim/plugins/extras/linting/eslint.lua @@ -14,22 +14,37 @@ return { }, setup = { eslint = function() - vim.api.nvim_create_autocmd("BufWritePre", { - callback = function(event) - if not require("lazyvim.plugins.lsp.format").enabled() then - -- exit early if autoformat is not enabled - return - end + local function get_client(buf) + return require("lazyvim.util").lsp.get_clients({ name = "eslint", bufnr = buf })[1] + end - local client = require("lazyvim.util").get_clients({ bufnr = event.buf, name = "eslint" })[1] + local formatter = require("lazyvim.util").lsp.formatter({ + name = "eslint: lsp", + primary = false, + priority = 200, + filter = "eslint", + }) + + -- Use EslintFixAll on Neovim < 0.10.0 + if not pcall(require, "vim.lsp._dynamic") then + formatter.name = "eslint: EslintFixAll" + formatter.sources = function(buf) + local client = get_client(buf) + return client and { "eslint" } or {} + end + formatter.format = function(buf) + local client = get_client(buf) if client then - local diag = vim.diagnostic.get(event.buf, { namespace = vim.lsp.diagnostic.get_namespace(client.id) }) + local diag = vim.diagnostic.get(buf, { namespace = vim.lsp.diagnostic.get_namespace(client.id) }) if #diag > 0 then vim.cmd("EslintFixAll") end end - end, - }) + end + end + + -- register the formatter with LazyVim + require("lazyvim.util").format.register(formatter) end, }, }, diff --git a/lua/lazyvim/plugins/lsp/format.lua b/lua/lazyvim/plugins/lsp/format.lua deleted file mode 100644 index f507a38a..00000000 --- a/lua/lazyvim/plugins/lsp/format.lua +++ /dev/null @@ -1,126 +0,0 @@ -local Util = require("lazy.core.util") - -local M = {} - ----@type PluginLspOpts -M.opts = nil - --- Allow plugins to set a custom formatter for a buffer. --- See the conform extra for an example. ----@type fun(bufnr:number):boolean -M.custom_format = nil - -function M.enabled() - return M.opts.autoformat -end - -function M.toggle() - if vim.b.autoformat == false then - vim.b.autoformat = nil - M.opts.autoformat = true - else - M.opts.autoformat = not M.opts.autoformat - end - if M.opts.autoformat then - Util.info("Enabled format on save", { title = "Format" }) - else - Util.warn("Disabled format on save", { title = "Format" }) - end -end - ----@param opts? {force?:boolean} -function M.format(opts) - local buf = vim.api.nvim_get_current_buf() - if vim.b.autoformat == false and not (opts and opts.force) then - return - end - - if - M.custom_format - and Util.try(function() - return M.custom_format(buf) - end, { msg = "Custom formatter failed" }) - then - return - end - - local formatters = M.get_formatters(buf) - local client_ids = vim.tbl_map(function(client) - return client.id - end, formatters.active) - - if #client_ids == 0 then - if opts and opts.force then - Util.warn("No formatter available", { title = "LazyVim" }) - end - return - end - - vim.lsp.buf.format(vim.tbl_deep_extend("force", { - bufnr = buf, - filter = function(client) - return vim.tbl_contains(client_ids, client.id) - end, - }, require("lazyvim.util").opts("nvim-lspconfig").format or {})) -end - --- Gets all lsp clients that support formatting. --- When a null-ls formatter is available for the current filetype, --- only null-ls formatters are returned. -function M.get_formatters(bufnr) - local ft = vim.bo[bufnr].filetype - -- check if we have any null-ls formatters for the current filetype - local null_ls = package.loaded["null-ls"] and require("null-ls.sources").get_available(ft, "NULL_LS_FORMATTING") or {} - - ---@class LazyVimFormatters - local ret = { - ---@type lsp.Client[] - active = {}, - ---@type lsp.Client[] - available = {}, - null_ls = null_ls, - } - - ---@type lsp.Client[] - local clients = require("lazyvim.util").get_clients({ bufnr = bufnr }) - for _, client in ipairs(clients) do - if M.supports_format(client) then - if (#null_ls > 0 and client.name == "null-ls") or #null_ls == 0 then - table.insert(ret.active, client) - else - table.insert(ret.available, client) - end - end - end - - return ret -end - --- Gets all lsp clients that support formatting --- and have not disabled it in their client config ----@param client lsp.Client -function M.supports_format(client) - if - client.config - and client.config.capabilities - and client.config.capabilities.documentFormattingProvider == false - then - return false - end - return client.supports_method("textDocument/formatting") or client.supports_method("textDocument/rangeFormatting") -end - ----@param opts PluginLspOpts -function M.setup(opts) - M.opts = opts - vim.api.nvim_create_autocmd("BufWritePre", { - group = vim.api.nvim_create_augroup("LazyVimFormat", {}), - callback = function() - if M.opts.autoformat then - M.format() - end - end, - }) -end - -return M diff --git a/lua/lazyvim/plugins/lsp/init.lua b/lua/lazyvim/plugins/lsp/init.lua index f18eed4f..b9e38e8b 100644 --- a/lua/lazyvim/plugins/lsp/init.lua +++ b/lua/lazyvim/plugins/lsp/init.lua @@ -35,8 +35,6 @@ return { }, -- add any global capabilities here capabilities = {}, - -- Automatically format on save - autoformat = true, -- options for vim.lsp.buf.format -- `bufnr` and `filter` is handled by the LazyVim formatter, -- but can be also overridden when specified @@ -80,16 +78,20 @@ return { }, ---@param opts PluginLspOpts config = function(_, opts) - local Util = require("lazyvim.util") - if Util.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 - require("lazyvim.plugins.lsp.format").setup(opts) - -- setup formatting and keymaps - Util.on_attach(function(client, buffer) + Util.format.register(Util.lsp.formatter()) + + -- deprectaed options + if opts.autoformat ~= nil then + vim.g.autoformat = opts.autoformat + Util.deprecate("nvim-lspconfig.opts.autoformat", "vim.g.autoformat") + end + -- setup keymaps Util.lsp.on_attach(function(client, buffer) require("lazyvim.plugins.lsp.keymaps").on_attach(client, buffer) @@ -215,6 +217,30 @@ return { }, } end, + config = function(_, opts) + require("null-ls").setup(opts) + + -- register the formatter with LazyVim + require("lazyvim.util").format.register({ + name = "none-ls.nvim", + priority = 50, + primary = true, + format = function(buf) + return Util.lsp.format({ + bufnr = buf, + filter = function(client) + return client.name == "null-ls" + end, + }) + end, + sources = function(buf) + local ret = require("null-ls.sources").get_available(vim.bo[buf].filetype, "NULL_LS_FORMATTING") or {} + return vim.tbl_map(function(source) + return source.name + end, ret) + end, + }) + end, }, -- cmdline tools and lsp servers diff --git a/lua/lazyvim/util/format.lua b/lua/lazyvim/util/format.lua new file mode 100644 index 00000000..05f5f5fd --- /dev/null +++ b/lua/lazyvim/util/format.lua @@ -0,0 +1,147 @@ +local Util = require("lazyvim.util") + +---@class lazyvim.util.format +---@overload fun(opts?: {force?:boolean}) +local M = setmetatable({}, { + __call = function(m, ...) + return m.format(...) + end, +}) + +---@class LazyFormatter +---@field name string +---@field primary? boolean +---@field format fun(bufnr:number) +---@field sources fun(bufnr:number):string[] +---@field priority number + +M.formatters = {} ---@type LazyFormatter[] + +---@param formatter LazyFormatter +function M.register(formatter) + M.formatters[#M.formatters + 1] = formatter + table.sort(M.formatters, function(a, b) + return a.priority > b.priority + end) +end + +---@param buf? number +---@return (LazyFormatter|{active:boolean,resolved:string[]})[] +function M.resolve(buf) + buf = buf or vim.api.nvim_get_current_buf() + local have_primary = false + ---@param formatter LazyFormatter + return vim.tbl_map(function(formatter) + local sources = formatter.sources(buf) + local active = #sources > 0 and (not formatter.primary or not have_primary) + have_primary = have_primary or (active and formatter.primary) or false + return setmetatable({ + active = active, + resolved = sources, + }, { __index = formatter }) + end, M.formatters) +end + +---@param buf? number +function M.info(buf) + buf = buf or vim.api.nvim_get_current_buf() + local gaf = vim.g.autoformat == nil or vim.g.autoformat + local baf = vim.b[buf].autoformat + local enabled = M.enabled(buf) + local lines = { + "# Status", + ("- [%s] global **%s**"):format(gaf and "x" or " ", gaf and "enabled" or "disabled"), + ("- [%s] buffer **%s**"):format( + enabled and "x" or " ", + baf == nil and "inherit" or baf and "enabled" or "disabled" + ), + } + local have = false + for _, formatter in ipairs(M.resolve(buf)) do + if #formatter.resolved > 0 then + have = true + lines[#lines + 1] = "\n# " .. formatter.name .. (formatter.active and " ***(active)***" or "") + for _, line in ipairs(formatter.resolved) do + lines[#lines + 1] = ("- [%s] **%s**"):format(formatter.active and "x" or " ", line) + end + end + end + if not have then + lines = { "\nNo formatters available for this buffer" } + end + Util[enabled and "info" or "warn"]( + table.concat(lines, "\n"), + { title = "LazyFormat (" .. (enabled and "enabled" or "disabled") .. ")" } + ) +end + +---@param buf? number +function M.enabled(buf) + buf = (buf == nil or buf == 0) and vim.api.nvim_get_current_buf() or buf + local gaf = vim.g.autoformat + local baf = vim.b[buf].autoformat + + -- If the buffer has a local value, use that + if baf ~= nil then + return baf + end + + -- Otherwise use the global value if set, or true by default + return gaf == nil or gaf +end + +---@param buf? boolean +function M.toggle(buf) + if buf then + vim.b.autoformat = not M.enabled() + else + vim.g.autoformat = not M.enabled() + vim.b.autoformat = nil + end + M.info() +end + +---@param opts? {force?:boolean, buf?:number} +function M.format(opts) + opts = opts or {} + local buf = opts.buf or vim.api.nvim_get_current_buf() + if not ((opts and opts.force) or M.enabled(buf)) then + return + end + + local done = false + for _, formatter in ipairs(M.resolve(buf)) do + if formatter.active then + done = true + Util.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" }) + end +end + +function M.setup() + -- Autoformat autocmd + vim.api.nvim_create_autocmd("BufWritePre", { + group = vim.api.nvim_create_augroup("LazyFormat", {}), + callback = function(event) + M.format({ buf = event.buf }) + end, + }) + + -- Manual format + vim.api.nvim_create_user_command("LazyFormat", function() + M.format({ force = true }) + end, { desc = "Format selection or buffer" }) + + -- Format info + vim.api.nvim_create_user_command("LazyFormatInfo", function() + M.info() + end, { desc = "Show info about the formatters for the current buffer" }) +end + +return M From 70f91956e7f03e740b51cbc14c87df6a6f74538f Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Tue, 10 Oct 2023 21:51:09 +0200 Subject: [PATCH 08/83] perf(plugin): move all lazy.nvim related code to `lazyvim.util.plugin` --- lua/lazyvim/config/init.lua | 202 +++++------------------------------ lua/lazyvim/plugins/init.lua | 10 ++ lua/lazyvim/util/init.lua | 1 + lua/lazyvim/util/plugin.lua | 148 +++++++++++++++++++++++++ 4 files changed, 183 insertions(+), 178 deletions(-) create mode 100644 lua/lazyvim/util/plugin.lua diff --git a/lua/lazyvim/config/init.lua b/lua/lazyvim/config/init.lua index 23ca90d4..201629fa 100644 --- a/lua/lazyvim/config/init.lua +++ b/lua/lazyvim/config/init.lua @@ -3,10 +3,6 @@ local Util = require("lazyvim.util") ---@class LazyVimConfig: LazyVimOptions local M = {} -M.lazy_version = ">=10.8.0" -M.use_lazy_file = true -M.lazy_file_events = { "BufReadPost", "BufNewFile", "BufWritePre" } - ---@class LazyVimOptions local defaults = { -- colorscheme can be a string like `catppuccin` or a function that will load the colorscheme @@ -85,61 +81,13 @@ local defaults = { }, } -M.renames = { - ["windwp/nvim-spectre"] = "nvim-pack/nvim-spectre", - ["jose-elias-alvarez/null-ls.nvim"] = "nvimtools/none-ls.nvim", - ["null-ls.nvim"] = "none-ls.nvim", -} - ---@type LazyVimOptions local options ----@param lines {[1]:string, [2]:string}[] -function M.msg(lines) - vim.cmd([[clear]]) - vim.api.nvim_echo(lines, true, {}) - vim.fn.getchar() -end - ---@param opts? LazyVimOptions function M.setup(opts) options = vim.tbl_deep_extend("force", defaults, opts or {}) or {} - if vim.fn.has("nvim-0.9.0") == 0 then - M.msg({ - { - "LazyVim requires Neovim >= 0.9.0\n", - "ErrorMsg", - }, - { "Press any key to exit", "MoreMsg" }, - }) - vim.cmd([[quit]]) - return - end - - if not M.has() then - M.msg({ - { - "LazyVim requires lazy.nvim " .. M.lazy_version .. "\n", - "WarningMsg", - }, - { "Press any key to attempt an upgrade", "MoreMsg" }, - }) - - vim.api.nvim_create_autocmd("User", { - pattern = "LazyVimStarted", - callback = function() - require("lazy").update({ plugins = { "lazy.nvim" }, wait = true }) - M.msg({ - { - "**lazy.nvim** has been upgraded.\nPlease restart **Neovim**", - "WarningMsg", - }, - }) - end, - }) - end - -- autocmds can be loaded lazily when not opening a file local lazy_autocmds = vim.fn.argc(-1) == 0 if not lazy_autocmds then @@ -159,10 +107,6 @@ function M.setup(opts) end, }) - if M.use_lazy_file then - M.lazy_file() - end - Util.track("colorscheme") Util.try(function() if type(M.colorscheme) == "function" then @@ -180,64 +124,6 @@ function M.setup(opts) Util.track() end --- Properly load file based plugins without blocking the UI -function M.lazy_file() - local events = {} ---@type {event: string, buf: number, data?: any}[] - - local function load() - if #events == 0 then - return - end - local Event = require("lazy.core.handler.event") - vim.api.nvim_del_augroup_by_name("lazy_file") - - Util.track({ event = "LazyVim.lazy_file" }) - - ---@type table - local skips = {} - for _, event in ipairs(events) do - skips[event.event] = skips[event.event] or Event.get_augroups(event.event) - end - - vim.api.nvim_exec_autocmds("User", { pattern = "LazyFile", modeline = false }) - for _, event in ipairs(events) do - Event.trigger({ - event = event.event, - exclude = skips[event.event], - data = event.data, - buf = event.buf, - }) - if vim.bo[event.buf].filetype then - Event.trigger({ - event = "FileType", - buf = event.buf, - }) - end - end - vim.api.nvim_exec_autocmds("CursorMoved", { modeline = false }) - events = {} - Util.track() - end - - -- schedule wrap so that nested autocmds are executed - -- and the UI can continue rendering without blocking - load = vim.schedule_wrap(load) - - vim.api.nvim_create_autocmd(M.lazy_file_events, { - group = vim.api.nvim_create_augroup("lazy_file", { clear = true }), - callback = function(event) - table.insert(events, event) - load() - end, - }) -end - ----@param range? string -function M.has(range) - local Semver = require("lazy.manage.semver") - return Semver.range(range or M.lazy_version):matches(require("lazy.core.config").version or "0.0.0") -end - ---@param name "autocmds" | "options" | "keymaps" function M.load(name) local function _load(mod) @@ -262,71 +148,31 @@ end M.did_init = false function M.init() - if not M.did_init then - M.did_init = true - local plugin = require("lazy.core.config").spec.plugins.LazyVim - if plugin then - vim.opt.rtp:append(plugin.dir) - end - - package.preload["lazyvim.plugins.lsp.format"] = function() - Util.deprecate([[require("lazyvim.plugins.lsp.format")]], [[require("lazyvim.util").format]]) - return Util.format - end - - M.use_lazy_file = M.use_lazy_file and vim.fn.argc(-1) > 0 - ---@diagnostic disable-next-line: undefined-field - M.use_lazy_file = M.use_lazy_file and require("lazy.core.handler.event").trigger_events == nil - - -- delay notifications till vim.notify was replaced or after 500ms - require("lazyvim.util").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") - local Plugin = require("lazy.core.plugin") - local add = Plugin.Spec.add - ---@diagnostic disable-next-line: duplicate-set-field - Plugin.Spec.add = function(self, plugin, ...) - if type(plugin) == "table" then - if M.renames[plugin[1]] then - Util.warn( - ("Plugin `%s` was renamed to `%s`.\nPlease update your config for `%s`"):format( - plugin[1], - M.renames[plugin[1]], - self.importing or "LazyVim" - ), - { title = "LazyVim" } - ) - plugin[1] = M.renames[plugin[1]] - end - if not M.use_lazy_file and plugin.event then - if plugin.event == "LazyFile" then - plugin.event = M.lazy_file_events - elseif type(plugin.event) == "table" then - local events = {} ---@type string[] - for _, event in ipairs(plugin.event) do - if event == "LazyFile" then - vim.list_extend(events, M.lazy_file_events) - else - events[#events + 1] = event - end - end - end - end - end - return add(self, plugin, ...) - end - - -- Add support for the LazyFile event - local Event = require("lazy.core.handler.event") - local _event = Event._event - ---@diagnostic disable-next-line: duplicate-set-field - Event._event = function(self, value) - return value == "LazyFile" and "User LazyFile" or _event(self, value) - end + if M.did_init then + return end + M.did_init = true + local plugin = require("lazy.core.config").spec.plugins.LazyVim + if plugin then + vim.opt.rtp:append(plugin.dir) + end + + package.preload["lazyvim.plugins.lsp.format"] = function() + Util.deprecate([[require("lazyvim.plugins.lsp.format")]], [[require("lazyvim.util").format]]) + return Util.format + end + + -- delay notifications till vim.notify was replaced or after 500ms + require("lazyvim.util").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.fix_imports() + Util.plugin.fix_renames() + Util.plugin.lazy_file() end setmetatable(M, { diff --git a/lua/lazyvim/plugins/init.lua b/lua/lazyvim/plugins/init.lua index 847d8470..8c7b5fa1 100644 --- a/lua/lazyvim/plugins/init.lua +++ b/lua/lazyvim/plugins/init.lua @@ -1,3 +1,13 @@ +if vim.fn.has("nvim-0.9.0") == 0 then + vim.api.nvim_echo({ + { "LazyVim requires Neovim >= 0.9.0\n", "ErrorMsg" }, + { "Press any key to exit", "MoreMsg" }, + }, true, {}) + vim.fn.getchar() + vim.cmd([[quit]]) + return {} +end + require("lazyvim.config").init() return { diff --git a/lua/lazyvim/util/init.lua b/lua/lazyvim/util/init.lua index 146e73e2..c46ac22e 100644 --- a/lua/lazyvim/util/init.lua +++ b/lua/lazyvim/util/init.lua @@ -8,6 +8,7 @@ local LazyUtil = require("lazy.core.util") ---@field terminal lazyvim.util.terminal ---@field toggle lazyvim.util.toggle ---@field format lazyvim.util.format +---@field plugin lazyvim.util.plugin local M = {} ---@type table diff --git a/lua/lazyvim/util/plugin.lua b/lua/lazyvim/util/plugin.lua new file mode 100644 index 00000000..a9d6ccd2 --- /dev/null +++ b/lua/lazyvim/util/plugin.lua @@ -0,0 +1,148 @@ +local Plugin = require("lazy.core.plugin") +local Util = require("lazyvim.util") + +---@class lazyvim.util.plugin +local M = {} + +M.use_lazy_file = true +M.lazy_file_events = { "BufReadPost", "BufNewFile", "BufWritePre" } + +---@type table +M.deprecated_extras = { + ["lazyvim.plugins.extras.formatting.conform"] = "`conform.nvim` is now the default **LazyVim** formatter.", + ["lazyvim.plugins.extras.linting.nvim-lint"] = "`nvim-lint` is now the default **LazyVim** linter.", +} + +---@type table +M.renames = { + ["windwp/nvim-spectre"] = "nvim-pack/nvim-spectre", + ["jose-elias-alvarez/null-ls.nvim"] = "nvimtools/none-ls.nvim", + ["null-ls.nvim"] = "none-ls.nvim", +} + +-- Properly load file based plugins without blocking the UI +function M.lazy_file() + M.use_lazy_file = M.use_lazy_file and vim.fn.argc(-1) > 0 + ---@diagnostic disable-next-line: undefined-field + M.use_lazy_file = M.use_lazy_file and require("lazy.core.handler.event").trigger_events == nil + M.use_lazy_file = false + + M.fix_lazy_file() + + if not M.use_lazy_file then + return + end + + local events = {} ---@type {event: string, buf: number, data?: any}[] + + local function load() + if #events == 0 then + return + end + local Event = require("lazy.core.handler.event") + vim.api.nvim_del_augroup_by_name("lazy_file") + + Util.track({ event = "LazyVim.lazy_file" }) + + ---@type table + local skips = {} + for _, event in ipairs(events) do + skips[event.event] = skips[event.event] or Event.get_augroups(event.event) + end + + vim.api.nvim_exec_autocmds("User", { pattern = "LazyFile", modeline = false }) + for _, event in ipairs(events) do + Event.trigger({ + event = event.event, + exclude = skips[event.event], + data = event.data, + buf = event.buf, + }) + if vim.bo[event.buf].filetype then + Event.trigger({ + event = "FileType", + buf = event.buf, + }) + end + end + vim.api.nvim_exec_autocmds("CursorMoved", { modeline = false }) + events = {} + Util.track() + end + + -- schedule wrap so that nested autocmds are executed + -- and the UI can continue rendering without blocking + load = vim.schedule_wrap(load) + + vim.api.nvim_create_autocmd(M.lazy_file_events, { + group = vim.api.nvim_create_augroup("lazy_file", { clear = true }), + callback = function(event) + table.insert(events, event) + load() + end, + }) +end + +function M.fix_imports() + local import = Plugin.Spec.import + ---@diagnostic disable-next-line: duplicate-set-field + function Plugin.Spec:import(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 }) + return + end + return import(self, spec) + end +end + +function M.fix_renames() + local add = Plugin.Spec.add + ---@diagnostic disable-next-line: duplicate-set-field + Plugin.Spec.add = function(self, plugin, ...) + if type(plugin) == "table" then + if M.renames[plugin[1]] then + Util.warn( + ("Plugin `%s` was renamed to `%s`.\nPlease update your config for `%s`"):format( + plugin[1], + M.renames[plugin[1]], + self.importing or "LazyVim" + ), + { title = "LazyVim" } + ) + plugin[1] = M.renames[plugin[1]] + end + end + return add(self, plugin, ...) + end +end + +function M.fix_lazy_file() + local Config = require("lazyvim.config") + -- Add support for the LazyFile event + local Handler = require("lazy.core.handler") + local Event = require("lazy.core.handler.event") + if M.use_lazy_file then + local _event = Event._event + ---@diagnostic disable-next-line: duplicate-set-field + Event._event = function(self, value) + return value == "LazyFile" and "User LazyFile" or _event(self, value) + end + else + ---@param plugin LazyPlugin + function Event:values(plugin) + local ret = Handler.values(self, plugin) + if ret["LazyFile"] or ret["User LazyFile"] then + for _, event in ipairs(M.lazy_file_events) do + ret[event] = event + end + ret["LazyFile"] = nil + ret["User LazyFile"] = nil + end + return ret + end + end +end + +return M From 14c091b1fc6b0dc0b22ac49ccac69f8a02e3844c Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Tue, 10 Oct 2023 22:12:33 +0200 Subject: [PATCH 09/83] feat!: make `conform.nvim` and `nvim-lint` the default formatters/linters --- .../plugins/extras/formatting/black.lua | 1 + .../plugins/extras/formatting/prettier.lua | 1 + lua/lazyvim/plugins/extras/lang/cmake.lua | 3 +- lua/lazyvim/plugins/extras/lang/docker.lua | 3 +- lua/lazyvim/plugins/extras/lang/elixir.lua | 3 +- lua/lazyvim/plugins/extras/lang/go.lua | 14 ++-- lua/lazyvim/plugins/extras/lang/omnisharp.lua | 1 + lua/lazyvim/plugins/extras/lang/terraform.lua | 12 ++-- lua/lazyvim/plugins/extras/lsp/none-ls.lua | 45 +++++++++++++ .../formatting/conform.lua => formatting.lua} | 0 lua/lazyvim/plugins/linting.lua | 67 +++++++++++++++++++ lua/lazyvim/plugins/lsp/init.lua | 43 ------------ lua/lazyvim/util/format.lua | 19 ++++++ 13 files changed, 148 insertions(+), 64 deletions(-) create mode 100644 lua/lazyvim/plugins/extras/lsp/none-ls.lua rename lua/lazyvim/plugins/{extras/formatting/conform.lua => formatting.lua} (100%) create mode 100644 lua/lazyvim/plugins/linting.lua diff --git a/lua/lazyvim/plugins/extras/formatting/black.lua b/lua/lazyvim/plugins/extras/formatting/black.lua index bfa383a8..769c3009 100644 --- a/lua/lazyvim/plugins/extras/formatting/black.lua +++ b/lua/lazyvim/plugins/extras/formatting/black.lua @@ -10,6 +10,7 @@ return { optional = true, opts = function(_, opts) local nls = require("null-ls") + opts.sources = opts.sources or {} table.insert(opts.sources, nls.builtins.formatting.black) end, }, diff --git a/lua/lazyvim/plugins/extras/formatting/prettier.lua b/lua/lazyvim/plugins/extras/formatting/prettier.lua index 81fc1939..6f1f3b58 100644 --- a/lua/lazyvim/plugins/extras/formatting/prettier.lua +++ b/lua/lazyvim/plugins/extras/formatting/prettier.lua @@ -10,6 +10,7 @@ return { optional = true, opts = function(_, opts) local nls = require("null-ls") + opts.sources = opts.sources or {} table.insert(opts.sources, nls.builtins.formatting.prettierd) end, }, diff --git a/lua/lazyvim/plugins/extras/lang/cmake.lua b/lua/lazyvim/plugins/extras/lang/cmake.lua index bc7b235a..404a072a 100644 --- a/lua/lazyvim/plugins/extras/lang/cmake.lua +++ b/lua/lazyvim/plugins/extras/lang/cmake.lua @@ -12,8 +12,7 @@ return { optional = true, opts = function(_, opts) local nls = require("null-ls") - opts.sources = opts.sources or {} - vim.list_extend(opts.sources, { + opts.sources = vim.list_extend(opts.sources or {}, { nls.builtins.diagnostics.cmake_lint, }) end, diff --git a/lua/lazyvim/plugins/extras/lang/docker.lua b/lua/lazyvim/plugins/extras/lang/docker.lua index 86c7175b..da9605ec 100644 --- a/lua/lazyvim/plugins/extras/lang/docker.lua +++ b/lua/lazyvim/plugins/extras/lang/docker.lua @@ -19,8 +19,7 @@ return { optional = true, opts = function(_, opts) local nls = require("null-ls") - opts.sources = opts.sources or {} - vim.list_extend(opts.sources, { + opts.sources = vim.list_extend(opts.sources or {}, { nls.builtins.diagnostics.hadolint, }) end, diff --git a/lua/lazyvim/plugins/extras/lang/elixir.lua b/lua/lazyvim/plugins/extras/lang/elixir.lua index 53454c37..f60dc18e 100644 --- a/lua/lazyvim/plugins/extras/lang/elixir.lua +++ b/lua/lazyvim/plugins/extras/lang/elixir.lua @@ -37,8 +37,7 @@ return { return end local nls = require("null-ls") - opts.sources = opts.sources or {} - vim.list_extend(opts.sources, { + opts.sources = vim.list_extend(opts.sources or {}, { nls.builtins.diagnostics.credo, }) end, diff --git a/lua/lazyvim/plugins/extras/lang/go.lua b/lua/lazyvim/plugins/extras/lang/go.lua index 39410353..7e87678b 100644 --- a/lua/lazyvim/plugins/extras/lang/go.lua +++ b/lua/lazyvim/plugins/extras/lang/go.lua @@ -86,14 +86,12 @@ return { "nvimtools/none-ls.nvim", optional = true, opts = function(_, opts) - if type(opts.sources) == "table" then - local nls = require("null-ls") - vim.list_extend(opts.sources, { - nls.builtins.code_actions.gomodifytags, - nls.builtins.code_actions.impl, - nls.builtins.formatting.goimports, - }) - end + local nls = require("null-ls") + opts.sources = vim.list_extend(opts.sources or {}, { + nls.builtins.code_actions.gomodifytags, + nls.builtins.code_actions.impl, + nls.builtins.formatting.goimports, + }) end, }, { diff --git a/lua/lazyvim/plugins/extras/lang/omnisharp.lua b/lua/lazyvim/plugins/extras/lang/omnisharp.lua index d244fd77..31162e0c 100644 --- a/lua/lazyvim/plugins/extras/lang/omnisharp.lua +++ b/lua/lazyvim/plugins/extras/lang/omnisharp.lua @@ -13,6 +13,7 @@ return { optional = true, opts = function(_, opts) local nls = require("null-ls") + opts.sources = opts.sources or {} table.insert(opts.sources, nls.builtins.formatting.csharpier) end, }, diff --git a/lua/lazyvim/plugins/extras/lang/terraform.lua b/lua/lazyvim/plugins/extras/lang/terraform.lua index 6e368ff3..ea7bd5de 100644 --- a/lua/lazyvim/plugins/extras/lang/terraform.lua +++ b/lua/lazyvim/plugins/extras/lang/terraform.lua @@ -28,13 +28,11 @@ return { "nvimtools/none-ls.nvim", optional = true, opts = function(_, opts) - if type(opts.sources) == "table" then - local null_ls = require("null-ls") - vim.list_extend(opts.sources, { - null_ls.builtins.formatting.terraform_fmt, - null_ls.builtins.diagnostics.terraform_validate, - }) - end + local null_ls = require("null-ls") + opts.sources = vim.list_extend(opts.sources or {}, { + null_ls.builtins.formatting.terraform_fmt, + null_ls.builtins.diagnostics.terraform_validate, + }) end, }, { diff --git a/lua/lazyvim/plugins/extras/lsp/none-ls.lua b/lua/lazyvim/plugins/extras/lsp/none-ls.lua new file mode 100644 index 00000000..aa907b8e --- /dev/null +++ b/lua/lazyvim/plugins/extras/lsp/none-ls.lua @@ -0,0 +1,45 @@ +local Util = require("lazyvim.util") + +return { + -- none-ls + { + "nvimtools/none-ls.nvim", + event = "LazyFile", + dependencies = { "mason.nvim" }, + init = function() + Util.on_very_lazy(function() + -- register the formatter with LazyVim + require("lazyvim.util").format.register({ + name = "none-ls.nvim", + priority = 200, -- set higher than conform, the builtin formatter + primary = true, + format = function(buf) + return Util.lsp.format({ + bufnr = buf, + filter = function(client) + return client.name == "null-ls" + end, + }) + end, + sources = function(buf) + local ret = require("null-ls.sources").get_available(vim.bo[buf].filetype, "NULL_LS_FORMATTING") or {} + return vim.tbl_map(function(source) + return source.name + end, ret) + end, + }) + end) + end, + opts = function(_, opts) + local nls = require("null-ls") + opts.root_dir = opts.root_dir + or require("null-ls.utils").root_pattern(".null-ls-root", ".neoconf.json", "Makefile", ".git") + opts.sources = vim.list_extend(opts.sources or {}, { + nls.builtins.formatting.fish_indent, + nls.builtins.diagnostics.fish, + nls.builtins.formatting.stylua, + nls.builtins.formatting.shfmt, + }) + end, + }, +} diff --git a/lua/lazyvim/plugins/extras/formatting/conform.lua b/lua/lazyvim/plugins/formatting.lua similarity index 100% rename from lua/lazyvim/plugins/extras/formatting/conform.lua rename to lua/lazyvim/plugins/formatting.lua diff --git a/lua/lazyvim/plugins/linting.lua b/lua/lazyvim/plugins/linting.lua new file mode 100644 index 00000000..1fb7ab5d --- /dev/null +++ b/lua/lazyvim/plugins/linting.lua @@ -0,0 +1,67 @@ +return { + { + "mfussenegger/nvim-lint", + event = "LazyFile", + opts = { + -- Event to trigger linters + events = { "BufWritePost", "BufReadPost", "InsertLeave" }, + linters_by_ft = { + fish = { "fish" }, + }, + -- LazyVim extension to easily override linter options + -- or add custom linters. + ---@type table + linters = { + -- -- Example of using selene only when a selene.toml file is present + -- selene = { + -- -- `condition` is another LazyVim extension that allows you to + -- -- dynamically enable/disable linters based on the context. + -- condition = function(ctx) + -- return vim.fs.find({ "selene.toml" }, { path = ctx.filename, upward = true })[1] + -- end, + -- }, + }, + }, + config = function(_, opts) + local M = {} + + local lint = require("lint") + for name, linter in pairs(opts.linters) do + if type(linter) == "table" and type(lint.linters) == "table" then + lint.linters[name] = vim.tbl_deep_extend("force", lint.linters[name], linter) + end + end + lint.linters_by_ft = opts.linters_by_ft + + function M.debounce(ms, fn) + local timer = vim.loop.new_timer() + return function(...) + local argv = { ... } + timer:start(ms, 0, function() + timer:stop() + vim.schedule_wrap(fn)(unpack(argv)) + end) + end + end + + function M.lint() + local names = lint.linters_by_ft[vim.bo.filetype] or {} + local ctx = { filename = vim.api.nvim_buf_get_name(0) } + ctx.dirname = vim.fn.fnamemodify(ctx.filename, ":h") + names = vim.tbl_filter(function(name) + local linter = lint.linters[name] + return linter and not (type(linter) == "table" and linter.condition and not linter.condition(ctx)) + end, names) + + if #names > 0 then + lint.try_lint(names) + end + end + + vim.api.nvim_create_autocmd(opts.events, { + group = vim.api.nvim_create_augroup("nvim-lint", { clear = true }), + callback = M.debounce(100, M.lint), + }) + end, + }, +} diff --git a/lua/lazyvim/plugins/lsp/init.lua b/lua/lazyvim/plugins/lsp/init.lua index b9e38e8b..165367bf 100644 --- a/lua/lazyvim/plugins/lsp/init.lua +++ b/lua/lazyvim/plugins/lsp/init.lua @@ -200,49 +200,6 @@ return { end, }, - -- formatters - { - "nvimtools/none-ls.nvim", - event = "LazyFile", - dependencies = { "mason.nvim" }, - opts = function() - local nls = require("null-ls") - return { - root_dir = require("null-ls.utils").root_pattern(".null-ls-root", ".neoconf.json", "Makefile", ".git"), - sources = { - nls.builtins.formatting.fish_indent, - nls.builtins.diagnostics.fish, - nls.builtins.formatting.stylua, - nls.builtins.formatting.shfmt, - }, - } - end, - config = function(_, opts) - require("null-ls").setup(opts) - - -- register the formatter with LazyVim - require("lazyvim.util").format.register({ - name = "none-ls.nvim", - priority = 50, - primary = true, - format = function(buf) - return Util.lsp.format({ - bufnr = buf, - filter = function(client) - return client.name == "null-ls" - end, - }) - end, - sources = function(buf) - local ret = require("null-ls.sources").get_available(vim.bo[buf].filetype, "NULL_LS_FORMATTING") or {} - return vim.tbl_map(function(source) - return source.name - end, ret) - end, - }) - end, - }, - -- cmdline tools and lsp servers { diff --git a/lua/lazyvim/util/format.lua b/lua/lazyvim/util/format.lua index 05f5f5fd..b9822a95 100644 --- a/lua/lazyvim/util/format.lua +++ b/lua/lazyvim/util/format.lua @@ -124,7 +124,26 @@ function M.format(opts) end end +function M.health() + local Config = require("lazy.core.config") + 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({ + "`conform.nvim` and `nvim-lint` are now the default forrmatters and linters in LazyVim.", + "", + "You can use those plugins together with `none-ls.nvim`,", + "but you need to enable the `lazyvim.plugins.extras.lsp.none-ls` extra,", + "for formatting to work correctly.", + "", + "In case you no longer want to use `none-ls.nvim`, just remove the spec from your config.", + }) + end +end + function M.setup() + M.health() + -- Autoformat autocmd vim.api.nvim_create_autocmd("BufWritePre", { group = vim.api.nvim_create_augroup("LazyFormat", {}), From 4cbe42cd247c72dfc70c3fcddfa3fb6b5e6485e0 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Tue, 10 Oct 2023 22:41:34 +0200 Subject: [PATCH 10/83] feat(starter)!: `dashboard.nvim` is now the default starter. To keep using `alpha.nvim`, enable the extra. --- lua/lazyvim/plugins/extras/ui/alpha.lua | 77 ++++++++++ lua/lazyvim/plugins/extras/ui/dashboard.lua | 64 --------- lua/lazyvim/plugins/ui.lua | 151 ++++++++++---------- lua/lazyvim/util/plugin.lua | 1 + 4 files changed, 157 insertions(+), 136 deletions(-) create mode 100644 lua/lazyvim/plugins/extras/ui/alpha.lua delete mode 100644 lua/lazyvim/plugins/extras/ui/dashboard.lua diff --git a/lua/lazyvim/plugins/extras/ui/alpha.lua b/lua/lazyvim/plugins/extras/ui/alpha.lua new file mode 100644 index 00000000..38019498 --- /dev/null +++ b/lua/lazyvim/plugins/extras/ui/alpha.lua @@ -0,0 +1,77 @@ +return { + + { "glepnir/dashboard-nvim", enabled = false }, + { "echasnovski/mini.starter", enabled = false }, + -- Dashboard. This runs when neovim starts, and is what displays + -- the "LAZYVIM" banner. + { + "goolord/alpha-nvim", + event = "VimEnter", + enabled = true, + init = false, + opts = function() + local dashboard = require("alpha.themes.dashboard") + local logo = [[ + ██╗ █████╗ ███████╗██╗ ██╗██╗ ██╗██╗███╗ ███╗ Z + ██║ ██╔══██╗╚══███╔╝╚██╗ ██╔╝██║ ██║██║████╗ ████║ Z + ██║ ███████║ ███╔╝ ╚████╔╝ ██║ ██║██║██╔████╔██║ z + ██║ ██╔══██║ ███╔╝ ╚██╔╝ ╚██╗ ██╔╝██║██║╚██╔╝██║ z + ███████╗██║ ██║███████╗ ██║ ╚████╔╝ ██║██║ ╚═╝ ██║ + ╚══════╝╚═╝ ╚═╝╚══════╝ ╚═╝ ╚═══╝ ╚═╝╚═╝ ╚═╝ + ]] + + dashboard.section.header.val = vim.split(logo, "\n") + dashboard.section.buttons.val = { + dashboard.button("f", " " .. " Find file", " Telescope find_files "), + dashboard.button("n", " " .. " New file", " ene startinsert "), + dashboard.button("r", " " .. " Recent files", " Telescope oldfiles "), + dashboard.button("g", " " .. " Find text", " Telescope live_grep "), + dashboard.button("c", " " .. " Config", " e $MYVIMRC "), + dashboard.button("s", " " .. " Restore Session", [[ lua require("persistence").load() ]]), + dashboard.button("l", "󰒲 " .. " Lazy", " Lazy "), + dashboard.button("q", " " .. " Quit", " qa "), + } + for _, button in ipairs(dashboard.section.buttons.val) do + button.opts.hl = "AlphaButtons" + button.opts.hl_shortcut = "AlphaShortcut" + end + dashboard.section.header.opts.hl = "AlphaHeader" + dashboard.section.buttons.opts.hl = "AlphaButtons" + dashboard.section.footer.opts.hl = "AlphaFooter" + dashboard.opts.layout[1].val = 8 + return dashboard + end, + config = function(_, dashboard) + -- close Lazy and re-open when the dashboard is ready + if vim.o.filetype == "lazy" then + vim.cmd.close() + vim.api.nvim_create_autocmd("User", { + once = true, + pattern = "AlphaReady", + callback = function() + require("lazy").show() + end, + }) + end + + require("alpha").setup(dashboard.opts) + + vim.api.nvim_create_autocmd("User", { + once = true, + pattern = "LazyVimStarted", + callback = function() + local stats = require("lazy").stats() + local ms = (math.floor(stats.startuptime * 100 + 0.5) / 100) + dashboard.section.footer.val = "⚡ Neovim loaded " + .. stats.loaded + .. "/" + .. stats.count + .. " plugins in " + .. ms + .. "ms" + pcall(vim.cmd.AlphaRedraw) + end, + }) + end, + }, +} diff --git a/lua/lazyvim/plugins/extras/ui/dashboard.lua b/lua/lazyvim/plugins/extras/ui/dashboard.lua deleted file mode 100644 index 2c678f36..00000000 --- a/lua/lazyvim/plugins/extras/ui/dashboard.lua +++ /dev/null @@ -1,64 +0,0 @@ -return { - { "goolord/alpha-nvim", enabled = false }, - { "echasnovski/mini.starter", enabled = false }, - { - "glepnir/dashboard-nvim", - event = "VimEnter", - opts = function() - local logo = [[ - ██╗ █████╗ ███████╗██╗ ██╗██╗ ██╗██╗███╗ ███╗ Z - ██║ ██╔══██╗╚══███╔╝╚██╗ ██╔╝██║ ██║██║████╗ ████║ Z - ██║ ███████║ ███╔╝ ╚████╔╝ ██║ ██║██║██╔████╔██║ z - ██║ ██╔══██║ ███╔╝ ╚██╔╝ ╚██╗ ██╔╝██║██║╚██╔╝██║ z - ███████╗██║ ██║███████╗ ██║ ╚████╔╝ ██║██║ ╚═╝ ██║ - ╚══════╝╚═╝ ╚═╝╚══════╝ ╚═╝ ╚═══╝ ╚═╝╚═╝ ╚═╝ - ]] - - logo = string.rep("\n", 8) .. logo .. "\n\n" - - local opts = { - theme = "doom", - hide = { - -- this is taken care of by lualine - -- enabling this messes up the actual laststatus setting after loading a file - statusline = false, - }, - config = { - header = vim.split(logo, "\n"), - center = { - { action = "Telescope find_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 = "e $MYVIMRC", desc = " Config", icon = " ", key = "c" }, - { action = 'lua require("persistence").load()', desc = " Restore Session", icon = " ", key = "s" }, - { action = "Lazy", desc = " Lazy", icon = "󰒲 ", key = "l" }, - { action = "qa", desc = " Quit", icon = " ", key = "q" }, - }, - footer = function() - local stats = require("lazy").stats() - local ms = (math.floor(stats.startuptime * 100 + 0.5) / 100) - return { "⚡ Neovim loaded " .. stats.loaded .. "/" .. stats.count .. " plugins in " .. ms .. "ms" } - end, - }, - } - - for _, button in ipairs(opts.config.center) do - button.desc = button.desc .. string.rep(" ", 43 - #button.desc) - end - - -- close Lazy and re-open when the dashboard is ready - if vim.o.filetype == "lazy" then - vim.cmd.close() - vim.api.nvim_create_autocmd("User", { - pattern = "DashboardLoaded", - callback = function() - require("lazy").show() - end, - }) - end - - return opts - end, - }, -} diff --git a/lua/lazyvim/plugins/ui.lua b/lua/lazyvim/plugins/ui.lua index f1bac031..9cb5237b 100644 --- a/lua/lazyvim/plugins/ui.lua +++ b/lua/lazyvim/plugins/ui.lua @@ -155,7 +155,11 @@ return { cond = function () return package.loaded["dap"] and require("dap").status() ~= "" end, color = Util.ui.fg("Debug"), }, - { require("lazy.status").updates, cond = require("lazy.status").has_updates, color = Util.ui.fg("Special") }, + { + require("lazy.status").updates, + cond = require("lazy.status").has_updates, + color = Util.ui.fg("Special"), + }, { "diff", symbols = { @@ -295,77 +299,6 @@ return { }, }, - -- Dashboard. This runs when neovim starts, and is what displays - -- the "LAZYVIM" banner. - { - "goolord/alpha-nvim", - event = "VimEnter", - opts = function() - local dashboard = require("alpha.themes.dashboard") - local logo = [[ - ██╗ █████╗ ███████╗██╗ ██╗██╗ ██╗██╗███╗ ███╗ Z - ██║ ██╔══██╗╚══███╔╝╚██╗ ██╔╝██║ ██║██║████╗ ████║ Z - ██║ ███████║ ███╔╝ ╚████╔╝ ██║ ██║██║██╔████╔██║ z - ██║ ██╔══██║ ███╔╝ ╚██╔╝ ╚██╗ ██╔╝██║██║╚██╔╝██║ z - ███████╗██║ ██║███████╗ ██║ ╚████╔╝ ██║██║ ╚═╝ ██║ - ╚══════╝╚═╝ ╚═╝╚══════╝ ╚═╝ ╚═══╝ ╚═╝╚═╝ ╚═╝ - ]] - - dashboard.section.header.val = vim.split(logo, "\n") - dashboard.section.buttons.val = { - dashboard.button("f", " " .. " Find file", " Telescope find_files "), - dashboard.button("n", " " .. " New file", " ene startinsert "), - dashboard.button("r", " " .. " Recent files", " Telescope oldfiles "), - dashboard.button("g", " " .. " Find text", " Telescope live_grep "), - dashboard.button("c", " " .. " Config", " e $MYVIMRC "), - dashboard.button("s", " " .. " Restore Session", [[ lua require("persistence").load() ]]), - dashboard.button("l", "󰒲 " .. " Lazy", " Lazy "), - dashboard.button("q", " " .. " Quit", " qa "), - } - for _, button in ipairs(dashboard.section.buttons.val) do - button.opts.hl = "AlphaButtons" - button.opts.hl_shortcut = "AlphaShortcut" - end - dashboard.section.header.opts.hl = "AlphaHeader" - dashboard.section.buttons.opts.hl = "AlphaButtons" - dashboard.section.footer.opts.hl = "AlphaFooter" - dashboard.opts.layout[1].val = 8 - return dashboard - end, - config = function(_, dashboard) - -- close Lazy and re-open when the dashboard is ready - if vim.o.filetype == "lazy" then - vim.cmd.close() - vim.api.nvim_create_autocmd("User", { - once = true, - pattern = "AlphaReady", - callback = function() - require("lazy").show() - end, - }) - end - - require("alpha").setup(dashboard.opts) - - vim.api.nvim_create_autocmd("User", { - once = true, - pattern = "LazyVimStarted", - callback = function() - local stats = require("lazy").stats() - local ms = (math.floor(stats.startuptime * 100 + 0.5) / 100) - dashboard.section.footer.val = "⚡ Neovim loaded " - .. stats.loaded - .. "/" - .. stats.count - .. " plugins in " - .. ms - .. "ms" - pcall(vim.cmd.AlphaRedraw) - end, - }) - end, - }, - -- lsp symbol navigation for lualine. This shows where -- in the code structure you are - within functions, classes, -- etc - in the statusline. @@ -396,4 +329,78 @@ return { -- ui components { "MunifTanjim/nui.nvim", lazy = true }, + + { + "goolord/alpha-nvim", + optional = true, + enabled = function() + require("lazyvim.util").warn({ + "`dashboard.nvim` is now the default LazyVim starter plugin.", + "", + "To keep using `alpha.nvim`, please enable the `lazyvim.plugins.extras.ui.alpha` extra.", + "Or to hide this message, remove the alpha spec from your config.", + }) + return false + end, + }, + { + "glepnir/dashboard-nvim", + event = "VimEnter", + opts = function() + local logo = [[ + ██╗ █████╗ ███████╗██╗ ██╗██╗ ██╗██╗███╗ ███╗ Z + ██║ ██╔══██╗╚══███╔╝╚██╗ ██╔╝██║ ██║██║████╗ ████║ Z + ██║ ███████║ ███╔╝ ╚████╔╝ ██║ ██║██║██╔████╔██║ z + ██║ ██╔══██║ ███╔╝ ╚██╔╝ ╚██╗ ██╔╝██║██║╚██╔╝██║ z + ███████╗██║ ██║███████╗ ██║ ╚████╔╝ ██║██║ ╚═╝ ██║ + ╚══════╝╚═╝ ╚═╝╚══════╝ ╚═╝ ╚═══╝ ╚═╝╚═╝ ╚═╝ + ]] + + logo = string.rep("\n", 8) .. logo .. "\n\n" + + local opts = { + theme = "doom", + hide = { + -- this is taken care of by lualine + -- enabling this messes up the actual laststatus setting after loading a file + statusline = false, + }, + config = { + header = vim.split(logo, "\n"), + center = { + { action = "Telescope find_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 = "e $MYVIMRC", desc = " Config", icon = " ", key = "c" }, + { action = 'lua require("persistence").load()', desc = " Restore Session", icon = " ", key = "s" }, + { action = "Lazy", desc = " Lazy", icon = "󰒲 ", key = "l" }, + { action = "qa", desc = " Quit", icon = " ", key = "q" }, + }, + footer = function() + local stats = require("lazy").stats() + local ms = (math.floor(stats.startuptime * 100 + 0.5) / 100) + return { "⚡ Neovim loaded " .. stats.loaded .. "/" .. stats.count .. " plugins in " .. ms .. "ms" } + end, + }, + } + + for _, button in ipairs(opts.config.center) do + button.desc = button.desc .. string.rep(" ", 43 - #button.desc) + end + + -- close Lazy and re-open when the dashboard is ready + if vim.o.filetype == "lazy" then + vim.cmd.close() + vim.api.nvim_create_autocmd("User", { + pattern = "DashboardLoaded", + callback = function() + require("lazy").show() + end, + }) + end + + return opts + end, + }, } diff --git a/lua/lazyvim/util/plugin.lua b/lua/lazyvim/util/plugin.lua index a9d6ccd2..ca6a162b 100644 --- a/lua/lazyvim/util/plugin.lua +++ b/lua/lazyvim/util/plugin.lua @@ -11,6 +11,7 @@ M.lazy_file_events = { "BufReadPost", "BufNewFile", "BufWritePre" } M.deprecated_extras = { ["lazyvim.plugins.extras.formatting.conform"] = "`conform.nvim` is now the default **LazyVim** formatter.", ["lazyvim.plugins.extras.linting.nvim-lint"] = "`nvim-lint` is now the default **LazyVim** linter.", + ["lazyvim.plugins.extras.ui.dashboard"] = "`dashboard.nvim` is now the default **LazyVim** starter.", } ---@type table From e6d294df6fbd973644d4b7f9691d5f48cc5efdde Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Tue, 10 Oct 2023 23:02:59 +0200 Subject: [PATCH 11/83] fix(ui): dont show left signs on virtual line numbers (wrap). Fixes #1654 --- lua/lazyvim/util/ui.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lua/lazyvim/util/ui.lua b/lua/lazyvim/util/ui.lua index 22b70e4b..6c5a3c1f 100644 --- a/lua/lazyvim/util/ui.lua +++ b/lua/lazyvim/util/ui.lua @@ -101,6 +101,10 @@ function M.statuscolumn() end end + if vim.v.virtnum ~= 0 then + left = nil + end + vim.api.nvim_win_call(win, function() if vim.fn.foldclosed(vim.v.lnum) >= 0 then fold = { text = vim.opt.fillchars:get().foldclose or "", texthl = "Folded" } From a2d604928b5629d14797437a26022065f7385216 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Wed, 11 Oct 2023 08:59:18 +0200 Subject: [PATCH 12/83] feat(root): customizable root detection and `:LazyRoot` command --- lua/lazyvim/config/init.lua | 1 + lua/lazyvim/config/keymaps.lua | 4 +- lua/lazyvim/config/options.lua | 4 + lua/lazyvim/plugins/editor.lua | 2 +- lua/lazyvim/util/root.lua | 151 +++++++++++++++++++++++++-------- lua/lazyvim/util/telescope.lua | 2 +- 6 files changed, 126 insertions(+), 38 deletions(-) diff --git a/lua/lazyvim/config/init.lua b/lua/lazyvim/config/init.lua index 201629fa..9319a67d 100644 --- a/lua/lazyvim/config/init.lua +++ b/lua/lazyvim/config/init.lua @@ -104,6 +104,7 @@ function M.setup(opts) end M.load("keymaps") Util.format.setup() + Util.root.setup() end, }) diff --git a/lua/lazyvim/config/keymaps.lua b/lua/lazyvim/config/keymaps.lua index ced9cdf7..79c0ee06 100644 --- a/lua/lazyvim/config/keymaps.lua +++ b/lua/lazyvim/config/keymaps.lua @@ -115,7 +115,7 @@ if vim.lsp.inlay_hint then end -- lazygit -map("n", "gg", function() Util.terminal({ "lazygit" }, { cwd = Util.root.get(), esc_esc = false, ctrl_hjkl = false }) end, { desc = "Lazygit (root dir)" }) +map("n", "gg", function() Util.terminal({ "lazygit" }, { cwd = Util.root(), esc_esc = false, ctrl_hjkl = false }) end, { desc = "Lazygit (root dir)" }) map("n", "gG", function() Util.terminal({ "lazygit" }, {esc_esc = false, ctrl_hjkl = false}) end, { desc = "Lazygit (cwd)" }) -- quit @@ -128,7 +128,7 @@ map("n", "ui", vim.show_pos, { desc = "Inspect Pos" }) map("n", "L", Util.changelog, {desc = "LazyVim Changelog"}) -- floating terminal -local lazyterm = function() Util.terminal(nil, { cwd = Util.root.get() }) end +local lazyterm = function() Util.terminal(nil, { cwd = Util.root() }) end map("n", "ft", lazyterm, { desc = "Terminal (root dir)" }) map("n", "fT", function() Util.terminal() end, { desc = "Terminal (cwd)" }) map("n", "", lazyterm, { desc = "Terminal (root dir)" }) diff --git a/lua/lazyvim/config/options.lua b/lua/lazyvim/config/options.lua index 1649896b..630fce42 100644 --- a/lua/lazyvim/config/options.lua +++ b/lua/lazyvim/config/options.lua @@ -5,6 +5,10 @@ vim.g.maplocalleader = "\\" -- Enable LazyVim auto format vim.g.autoformat = true +-- LazyVim root dir detection +-- Each entry can be a detector function like `lsp` or `cwd`, or a pattern like `.git` or `lua`. +vim.g.root_spec = { "lsp", { ".git", "lua" }, "cwd" } + local opt = vim.opt opt.autowrite = true -- Enable auto write diff --git a/lua/lazyvim/plugins/editor.lua b/lua/lazyvim/plugins/editor.lua index 0fb63944..dabcb8de 100644 --- a/lua/lazyvim/plugins/editor.lua +++ b/lua/lazyvim/plugins/editor.lua @@ -11,7 +11,7 @@ return { { "fe", function() - require("neo-tree.command").execute({ toggle = true, dir = Util.root.get() }) + require("neo-tree.command").execute({ toggle = true, dir = Util.root() }) end, desc = "Explorer NeoTree (root dir)", }, diff --git a/lua/lazyvim/util/root.lua b/lua/lazyvim/util/root.lua index 296e045b..c97ecf88 100644 --- a/lua/lazyvim/util/root.lua +++ b/lua/lazyvim/util/root.lua @@ -1,9 +1,122 @@ local Util = require("lazyvim.util") ---@class lazyvim.util.root -local M = {} +---@overload fun(): string +local M = setmetatable({}, { + __call = function(m) + return m.get() + end, +}) -M.patterns = { ".git", "lua" } +---@class LazyRoot +---@field paths string[] +---@field spec LazyRootSpec + +---@alias LazyRootSpec string|string[] + +---@type LazyRootSpec[] +M.spec = { "lsp", { ".git", "lua" }, "cwd" } + +M.detectors = {} + +function M.detectors.cwd() + return { vim.loop.cwd() } +end + +function M.detectors.lsp(buf) + if not M.bufpath(buf) then + return {} + end + local roots = {} ---@type string[] + for _, client in pairs(Util.lsp.get_clients({ bufnr = buf })) do + local workspace = client.config.workspace_folders + for _, ws in pairs(workspace or {}) do + roots[#roots + 1] = vim.uri_to_fname(ws.uri) + end + if client.config.root_dir then + roots[#roots + 1] = client.config.root_dir + end + end + return roots +end + +---@param patterns string[]|string +function M.detectors.pattern(buf, patterns) + patterns = type(patterns) == "string" and { patterns } or patterns + local path = M.bufpath(buf) or vim.loop.cwd() + local pattern = vim.fs.find(patterns, { path = path, upward = true })[1] + return pattern and { vim.fs.dirname(pattern) } or {} +end + +function M.bufpath(buf) + return M.realpath(vim.api.nvim_buf_get_name(assert(buf))) +end + +function M.realpath(path) + if path == "" or path == nil then + return nil + end + path = vim.loop.fs_realpath(path) or path + return Util.norm(path) +end + +---@param opts? { buf?: number, spec?: LazyRootSpec[], all?: boolean } +function M.detect(opts) + opts = opts or {} + opts.spec = opts.spec or type(vim.g.root_spec) == "table" and vim.g.root_spec or M.spec + opts.buf = (opts.buf == nil or opts.buf == 0) and vim.api.nvim_get_current_buf() or opts.buf + + local ret = {} ---@type LazyRoot[] + for _, spec in ipairs(opts.spec) do + local paths = M.detectors[spec] and M.detectors[spec](opts.buf) or M.detectors.pattern(opts.buf, spec) + local roots = {} ---@type string[] + for _, p in ipairs(paths) do + local pp = M.realpath(p) + if pp and not vim.tbl_contains(roots, pp) then + roots[#roots + 1] = pp + end + end + table.sort(roots, function(a, b) + return #a > #b + end) + if #roots > 0 then + ret[#ret + 1] = { spec = spec, paths = roots } + if opts.all == false then + break + end + end + end + return ret +end + +function M.setup() + vim.api.nvim_create_user_command("LazyRoot", function() + M.info() + end, { desc = "LazyVim roots for the current buffer" }) +end + +function M.info() + local spec = type(vim.g.root_spec) == "table" and vim.g.root_spec or M.spec + + local roots = M.detect({ all = true }) + local lines = {} ---@type string[] + local first = true + for _, root in ipairs(roots) do + for _, path in ipairs(root.paths) do + lines[#lines + 1] = ("- [%s] `%s` **(%s)**"):format( + first and "x" or " ", + path, + type(root.spec) == "table" and table.concat(root.spec, ", ") or root.spec + ) + first = false + end + end + 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" }) + return roots[1] and roots[1].paths[1] or vim.loop.cwd() +end -- returns the root directory based on: -- * lsp workspace folders @@ -12,38 +125,8 @@ M.patterns = { ".git", "lua" } -- * root pattern of cwd ---@return string function M.get() - ---@type string? - local path = vim.api.nvim_buf_get_name(0) - path = path ~= "" and vim.loop.fs_realpath(path) or nil - ---@type string[] - local roots = {} - if path then - for _, client in pairs(Util.lsp.get_clients({ bufnr = 0 })) do - local workspace = client.config.workspace_folders - local paths = workspace and vim.tbl_map(function(ws) - return vim.uri_to_fname(ws.uri) - end, workspace) or client.config.root_dir and { client.config.root_dir } or {} - for _, p in ipairs(paths) do - local r = vim.loop.fs_realpath(p) - if path:find(r, 1, true) then - roots[#roots + 1] = r - end - end - end - end - table.sort(roots, function(a, b) - return #a > #b - end) - ---@type string? - local root = roots[1] - if not root then - path = path and vim.fs.dirname(path) or vim.loop.cwd() - ---@type string? - root = vim.fs.find(M.patterns, { path = path, upward = true })[1] - root = root and vim.fs.dirname(root) or vim.loop.cwd() - end - ---@cast root string - return root + local roots = M.detect({ all = false }) + return roots[1] and roots[1].paths[1] or vim.loop.cwd() end return M diff --git a/lua/lazyvim/util/telescope.lua b/lua/lazyvim/util/telescope.lua index 2aae403d..68916341 100644 --- a/lua/lazyvim/util/telescope.lua +++ b/lua/lazyvim/util/telescope.lua @@ -22,7 +22,7 @@ function M.telescope(builtin, opts) return function() builtin = params.builtin opts = params.opts - opts = vim.tbl_deep_extend("force", { cwd = Util.root.get() }, opts or {}) --[[@as lazyvim.util.telescope.opts]] + opts = vim.tbl_deep_extend("force", { cwd = Util.root() }, opts or {}) --[[@as lazyvim.util.telescope.opts]] if builtin == "files" then if vim.loop.fs_stat((opts.cwd or vim.loop.cwd()) .. "/.git") then opts.show_untracked = true From f59cdff4d9f04ff349cefdee0b363d573954ce0d Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Wed, 11 Oct 2023 09:15:50 +0200 Subject: [PATCH 13/83] fix(plugin): enable lazy_file --- lua/lazyvim/util/plugin.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/lua/lazyvim/util/plugin.lua b/lua/lazyvim/util/plugin.lua index ca6a162b..d22e7cb0 100644 --- a/lua/lazyvim/util/plugin.lua +++ b/lua/lazyvim/util/plugin.lua @@ -26,7 +26,6 @@ function M.lazy_file() M.use_lazy_file = M.use_lazy_file and vim.fn.argc(-1) > 0 ---@diagnostic disable-next-line: undefined-field M.use_lazy_file = M.use_lazy_file and require("lazy.core.handler.event").trigger_events == nil - M.use_lazy_file = false M.fix_lazy_file() From c33e7489ecdaef7295a63079410f2f24a1cbc9b6 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Wed, 11 Oct 2023 09:38:34 +0200 Subject: [PATCH 14/83] feat(root): allow custom functions as part of `vim.g.root_spec` --- lua/lazyvim/config/options.lua | 5 ++++- lua/lazyvim/util/root.lua | 21 +++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/lua/lazyvim/config/options.lua b/lua/lazyvim/config/options.lua index 630fce42..5a071a15 100644 --- a/lua/lazyvim/config/options.lua +++ b/lua/lazyvim/config/options.lua @@ -6,7 +6,10 @@ vim.g.maplocalleader = "\\" vim.g.autoformat = true -- LazyVim root dir detection --- Each entry can be a detector function like `lsp` or `cwd`, or a pattern like `.git` or `lua`. +-- Each entry can be: +-- * the name of a detector function like `lsp` or `cwd` +-- * a pattern or array of patterns like `.git` or `lua`. +-- * a function with signature `function(buf) -> string|string[]` vim.g.root_spec = { "lsp", { ".git", "lua" }, "cwd" } local opt = vim.opt diff --git a/lua/lazyvim/util/root.lua b/lua/lazyvim/util/root.lua index c97ecf88..fe263a7c 100644 --- a/lua/lazyvim/util/root.lua +++ b/lua/lazyvim/util/root.lua @@ -12,7 +12,9 @@ local M = setmetatable({}, { ---@field paths string[] ---@field spec LazyRootSpec ----@alias LazyRootSpec string|string[] +---@alias LazyRootFn fun(buf: number): (string|string[]) + +---@alias LazyRootSpec string|string[]|LazyRootFn ---@type LazyRootSpec[] M.spec = { "lsp", { ".git", "lua" }, "cwd" } @@ -60,6 +62,19 @@ function M.realpath(path) return Util.norm(path) end +---@param spec LazyRootSpec +---@return LazyRootFn +function M.resolve(spec) + if M.detectors[spec] then + return M.detectors[spec] + elseif type(spec) == "function" then + return spec + end + return function(buf) + return M.detectors.pattern(buf, spec) + end +end + ---@param opts? { buf?: number, spec?: LazyRootSpec[], all?: boolean } function M.detect(opts) opts = opts or {} @@ -68,7 +83,9 @@ function M.detect(opts) local ret = {} ---@type LazyRoot[] for _, spec in ipairs(opts.spec) do - local paths = M.detectors[spec] and M.detectors[spec](opts.buf) or M.detectors.pattern(opts.buf, spec) + local paths = M.resolve(spec)(opts.buf) + paths = paths or {} + paths = type(paths) == "table" and paths or { paths } local roots = {} ---@type string[] for _, p in ipairs(paths) do local pp = M.realpath(p) From a4abbdc89bd1d49378ac5873db1279e7e5398927 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Wed, 11 Oct 2023 09:51:12 +0200 Subject: [PATCH 15/83] fix(format): always show formatter status even when no sources available --- lua/lazyvim/util/format.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/lazyvim/util/format.lua b/lua/lazyvim/util/format.lua index b9822a95..af64a6f5 100644 --- a/lua/lazyvim/util/format.lua +++ b/lua/lazyvim/util/format.lua @@ -67,7 +67,7 @@ function M.info(buf) end end if not have then - lines = { "\nNo formatters available for this buffer" } + lines[#lines+1] = "\n***No formatters available for this buffer.***" end Util[enabled and "info" or "warn"]( table.concat(lines, "\n"), From 83734675b0f93fbd11a350ee0662c09995836b59 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Wed, 11 Oct 2023 14:26:16 +0200 Subject: [PATCH 16/83] fix(lualine): when opening nvim with a file, show an empty statusline till lualine loads --- lua/lazyvim/plugins/ui.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lua/lazyvim/plugins/ui.lua b/lua/lazyvim/plugins/ui.lua index 9cb5237b..3259b4eb 100644 --- a/lua/lazyvim/plugins/ui.lua +++ b/lua/lazyvim/plugins/ui.lua @@ -101,7 +101,13 @@ return { event = "VeryLazy", init = function() vim.g.lualine_laststatus = vim.o.laststatus - vim.o.laststatus = 0 + if vim.fn.argc(-1) > 0 then + -- set an empty statusline till lualine loads + vim.o.statusline = " " + else + -- hide the statusline on the starter page + vim.o.laststatus = 0 + end end, opts = function() local icons = require("lazyvim.config").icons From 4ea1c6865e6d877207de8626e11a5a863950ae55 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Wed, 11 Oct 2023 14:27:10 +0200 Subject: [PATCH 17/83] feat(config): use lazy's new custom events (`Event.mappings`) for a better `LazyFile` --- lua/lazyvim/util/plugin.lua | 45 +++++++++---------------------------- 1 file changed, 10 insertions(+), 35 deletions(-) diff --git a/lua/lazyvim/util/plugin.lua b/lua/lazyvim/util/plugin.lua index d22e7cb0..b3650eaa 100644 --- a/lua/lazyvim/util/plugin.lua +++ b/lua/lazyvim/util/plugin.lua @@ -24,12 +24,18 @@ M.renames = { -- Properly load file based plugins without blocking the UI function M.lazy_file() M.use_lazy_file = M.use_lazy_file and vim.fn.argc(-1) > 0 - ---@diagnostic disable-next-line: undefined-field - M.use_lazy_file = M.use_lazy_file and require("lazy.core.handler.event").trigger_events == nil - M.fix_lazy_file() + -- Add support for the LazyFile event + local Event = require("lazy.core.handler.event") - if not M.use_lazy_file then + if M.use_lazy_file then + -- We'll handle delayed execution of events ourselves + Event.mappings.LazyFile = { id = "LazyFile", event = "User", pattern = "LazyFile" } + Event.mappings["User LazyFile"] = Event.mappings.LazyFile + else + -- Don't delay execution of LazyFile events, but let lazy know about the mapping + Event.mappings.LazyFile = { id = "LazyFile", event = { "BufReadPost", "BufNewFile", "BufWritePre" } } + Event.mappings["User LazyFile"] = Event.mappings.LazyFile return end @@ -39,11 +45,8 @@ function M.lazy_file() if #events == 0 then return end - local Event = require("lazy.core.handler.event") vim.api.nvim_del_augroup_by_name("lazy_file") - Util.track({ event = "LazyVim.lazy_file" }) - ---@type table local skips = {} for _, event in ipairs(events) do @@ -67,7 +70,6 @@ function M.lazy_file() end vim.api.nvim_exec_autocmds("CursorMoved", { modeline = false }) events = {} - Util.track() end -- schedule wrap so that nested autocmds are executed @@ -118,31 +120,4 @@ function M.fix_renames() end end -function M.fix_lazy_file() - local Config = require("lazyvim.config") - -- Add support for the LazyFile event - local Handler = require("lazy.core.handler") - local Event = require("lazy.core.handler.event") - if M.use_lazy_file then - local _event = Event._event - ---@diagnostic disable-next-line: duplicate-set-field - Event._event = function(self, value) - return value == "LazyFile" and "User LazyFile" or _event(self, value) - end - else - ---@param plugin LazyPlugin - function Event:values(plugin) - local ret = Handler.values(self, plugin) - if ret["LazyFile"] or ret["User LazyFile"] then - for _, event in ipairs(M.lazy_file_events) do - ret[event] = event - end - ret["LazyFile"] = nil - ret["User LazyFile"] = nil - end - return ret - end - end -end - return M From 8fbde2c3668960ed085f9225bb4650aca77cc495 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Wed, 11 Oct 2023 14:27:41 +0200 Subject: [PATCH 18/83] fix(neo-tree): during init check global argslist instead of window-local --- lua/lazyvim/plugins/editor.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/lazyvim/plugins/editor.lua b/lua/lazyvim/plugins/editor.lua index dabcb8de..e2c08b98 100644 --- a/lua/lazyvim/plugins/editor.lua +++ b/lua/lazyvim/plugins/editor.lua @@ -29,7 +29,7 @@ return { vim.cmd([[Neotree close]]) end, init = function() - if vim.fn.argc() == 1 then + if vim.fn.argc(-1) == 1 then local stat = vim.loop.fs_stat(vim.fn.argv(0)) if stat and stat.type == "directory" then require("neo-tree") From 54fa9ce584b9d029fb9f016f1e3be5daca29beaa Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Wed, 11 Oct 2023 15:25:29 +0200 Subject: [PATCH 19/83] ci: let release-please manage the version in the config file --- .github/workflows/ci.yml | 2 ++ lua/lazyvim/config/init.lua | 2 ++ 2 files changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 964a780f..2ffff686 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -59,6 +59,8 @@ jobs: with: release-type: simple package-name: LazyVim + extra-files: | + lua/lazyvim/config/init.lua - uses: actions/checkout@v3 - name: tag stable versions if: ${{ steps.release.outputs.release_created }} diff --git a/lua/lazyvim/config/init.lua b/lua/lazyvim/config/init.lua index 9319a67d..5cf7feff 100644 --- a/lua/lazyvim/config/init.lua +++ b/lua/lazyvim/config/init.lua @@ -3,6 +3,8 @@ local Util = require("lazyvim.util") ---@class LazyVimConfig: LazyVimOptions local M = {} +M.version = "10.0.0" -- x-release-please-version + ---@class LazyVimOptions local defaults = { -- colorscheme can be a string like `catppuccin` or a function that will load the colorscheme From 7fb79486ed1b251b98b95a44ef50b3742edd708d Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Wed, 11 Oct 2023 17:39:46 +0200 Subject: [PATCH 20/83] fix(notify): set default zindex=100 --- lua/lazyvim/plugins/ui.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lua/lazyvim/plugins/ui.lua b/lua/lazyvim/plugins/ui.lua index 3259b4eb..c22e0791 100644 --- a/lua/lazyvim/plugins/ui.lua +++ b/lua/lazyvim/plugins/ui.lua @@ -19,6 +19,9 @@ return { max_width = function() return math.floor(vim.o.columns * 0.75) end, + on_open = function(win) + vim.api.nvim_win_set_config(win, { zindex = 100 }) + end, }, init = function() -- when noice is not enabled, install notify on VeryLazy From 11d66e713467410add9ad5a7a68a3bca0aa24082 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Wed, 11 Oct 2023 17:47:16 +0200 Subject: [PATCH 21/83] feat(config): load/save some data in lazyvim.json --- lua/lazyvim/config/init.lua | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/lua/lazyvim/config/init.lua b/lua/lazyvim/config/init.lua index 5cf7feff..92bd1f69 100644 --- a/lua/lazyvim/config/init.lua +++ b/lua/lazyvim/config/init.lua @@ -83,6 +83,35 @@ local defaults = { }, } +M.json = { + data = { + version = nil, ---@type string? + extras = {}, ---@type string[] + }, +} + +function M.json.load() + local path = vim.fn.stdpath("config") .. "/lazyvim.json" + local f = io.open(path, "r") + if f then + local data = f:read("*a") + f:close() + local ok, json = pcall(vim.json.decode, data, { luanil = { object = true, array = true } }) + if ok then + M.json.data = vim.tbl_deep_extend("force", M.json.data, json or {}) + end + end +end + +function M.json.save() + local path = vim.fn.stdpath("config") .. "/lazyvim.json" + local f = io.open(path, "w") + if f then + f:write(vim.json.encode(M.json.data)) + f:close() + end +end + ---@type LazyVimOptions local options @@ -176,6 +205,7 @@ function M.init() Util.plugin.fix_imports() Util.plugin.fix_renames() Util.plugin.lazy_file() + M.json.load() end setmetatable(M, { From c4e55e4d67a7195b7aa9160cd8ece3ddc2f6cb51 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Wed, 11 Oct 2023 17:48:40 +0200 Subject: [PATCH 22/83] feat(ui): added `:LazyExtras` to manage enabled extras in LazyVim --- lua/lazyvim/config/init.lua | 10 +- .../plugins/extras/linting/nvim-lint.lua | 67 ------ lua/lazyvim/plugins/xtras.lua | 6 + lua/lazyvim/util/extras.lua | 202 ++++++++++++++++++ lua/lazyvim/util/init.lua | 1 + lua/lazyvim/util/root.lua | 6 - 6 files changed, 218 insertions(+), 74 deletions(-) delete mode 100644 lua/lazyvim/plugins/extras/linting/nvim-lint.lua create mode 100644 lua/lazyvim/plugins/xtras.lua create mode 100644 lua/lazyvim/util/extras.lua diff --git a/lua/lazyvim/config/init.lua b/lua/lazyvim/config/init.lua index 92bd1f69..076a003e 100644 --- a/lua/lazyvim/config/init.lua +++ b/lua/lazyvim/config/init.lua @@ -134,8 +134,16 @@ function M.setup(opts) M.load("autocmds") end M.load("keymaps") + Util.format.setup() - Util.root.setup() + + vim.api.nvim_create_user_command("LazyRoot", function() + Util.root.info() + end, { desc = "LazyVim roots for the current buffer" }) + + vim.api.nvim_create_user_command("LazyExtras", function() + Util.extras.show() + end, { desc = "Manage LazyVim extras" }) end, }) diff --git a/lua/lazyvim/plugins/extras/linting/nvim-lint.lua b/lua/lazyvim/plugins/extras/linting/nvim-lint.lua deleted file mode 100644 index 1fb7ab5d..00000000 --- a/lua/lazyvim/plugins/extras/linting/nvim-lint.lua +++ /dev/null @@ -1,67 +0,0 @@ -return { - { - "mfussenegger/nvim-lint", - event = "LazyFile", - opts = { - -- Event to trigger linters - events = { "BufWritePost", "BufReadPost", "InsertLeave" }, - linters_by_ft = { - fish = { "fish" }, - }, - -- LazyVim extension to easily override linter options - -- or add custom linters. - ---@type table - linters = { - -- -- Example of using selene only when a selene.toml file is present - -- selene = { - -- -- `condition` is another LazyVim extension that allows you to - -- -- dynamically enable/disable linters based on the context. - -- condition = function(ctx) - -- return vim.fs.find({ "selene.toml" }, { path = ctx.filename, upward = true })[1] - -- end, - -- }, - }, - }, - config = function(_, opts) - local M = {} - - local lint = require("lint") - for name, linter in pairs(opts.linters) do - if type(linter) == "table" and type(lint.linters) == "table" then - lint.linters[name] = vim.tbl_deep_extend("force", lint.linters[name], linter) - end - end - lint.linters_by_ft = opts.linters_by_ft - - function M.debounce(ms, fn) - local timer = vim.loop.new_timer() - return function(...) - local argv = { ... } - timer:start(ms, 0, function() - timer:stop() - vim.schedule_wrap(fn)(unpack(argv)) - end) - end - end - - function M.lint() - local names = lint.linters_by_ft[vim.bo.filetype] or {} - local ctx = { filename = vim.api.nvim_buf_get_name(0) } - ctx.dirname = vim.fn.fnamemodify(ctx.filename, ":h") - names = vim.tbl_filter(function(name) - local linter = lint.linters[name] - return linter and not (type(linter) == "table" and linter.condition and not linter.condition(ctx)) - end, names) - - if #names > 0 then - lint.try_lint(names) - end - end - - vim.api.nvim_create_autocmd(opts.events, { - group = vim.api.nvim_create_augroup("nvim-lint", { clear = true }), - callback = M.debounce(100, M.lint), - }) - end, - }, -} diff --git a/lua/lazyvim/plugins/xtras.lua b/lua/lazyvim/plugins/xtras.lua new file mode 100644 index 00000000..0a6ed614 --- /dev/null +++ b/lua/lazyvim/plugins/xtras.lua @@ -0,0 +1,6 @@ +local Config = require("lazyvim.config") + +---@param extra string +return vim.tbl_map(function(extra) + return { import = "lazyvim.plugins.extras." .. extra } +end, Config.json.data.extras) diff --git a/lua/lazyvim/util/extras.lua b/lua/lazyvim/util/extras.lua new file mode 100644 index 00000000..6e7bb742 --- /dev/null +++ b/lua/lazyvim/util/extras.lua @@ -0,0 +1,202 @@ +local Config = require("lazyvim.config") +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 LazyExtra +---@field name string +---@field enabled boolean +---@field managed boolean +---@field row? number +---@field plugins string[] + +---@class lazyvim.util.extras +local M = {} + +M.prios = { + ["editor.aerial"] = 100, + ["test.core"] = 1, + ["dap.core"] = 1, +} + +M.ns = vim.api.nvim_create_namespace("lazyvim.extras") +---@type string[] +M.state = nil + +---@return LazyExtra[] +function M.get() + M.state = M.state or LazyConfig.spec.modules + local root = LazyConfig.plugins.LazyVim.dir .. "/lua/lazyvim/plugins/extras" + local extras = {} ---@type string[] + + Util.walk(root, function(path, name, type) + if type == "file" and name:match("%.lua$") then + local extra = path:sub(#root + 2, -5):gsub("/", ".") + extras[#extras + 1] = extra + end + end) + table.sort(extras) + + ---@param extra string + return vim.tbl_map(function(extra) + local modname = "lazyvim.plugins.extras." .. extra + local enabled = vim.tbl_contains(M.state, modname) + local spec = Plugin.Spec.new({ import = "lazyvim.plugins.extras." .. extra }, { optional = false }) + return { + name = extra, + enabled = enabled, + managed = vim.tbl_contains(Config.json.data.extras, extra) or not enabled, + plugins = vim.tbl_keys(spec.plugins), + } + end, extras) +end + +---@class LazyExtraView +---@field float LazyFloat +---@field text Text +---@field extras LazyExtra[] +---@field diag LazyDiagnostic[] +local X = {} + +---@return LazyExtraView +function X.new() + local self = setmetatable({}, { __index = X }) + self.float = Float.new({ title = "LazyVim Extras" }) + self.float:on_key("x", function() + self:toggle() + end, "Toggle extra") + self.diag = {} + self:update() + return self +end + +---@param diag LazyDiagnostic +function X:diagnostic(diag) + diag.row = diag.row or self.text:row() + diag.severity = diag.severity or vim.diagnostic.severity.INFO + table.insert(self.diag, diag) +end + +function X:toggle() + local pos = vim.api.nvim_win_get_cursor(self.float.win) + for _, extra in ipairs(self.extras) do + if extra.row == pos[1] then + if not extra.managed then + Util.error( + "Not managed by LazyExtras. Remove from your config to enable/disable here.", + { title = "LazyExtras" } + ) + return + end + extra.enabled = not extra.enabled + Config.json.data.extras = vim.tbl_filter(function(name) + return name ~= extra.name + end, Config.json.data.extras) + M.state = vim.tbl_filter(function(name) + return name ~= "lazyvim.plugins.extras." .. extra.name + end, M.state) + if extra.enabled then + table.insert(Config.json.data.extras, extra.name) + M.state[#M.state + 1] = "lazyvim.plugins.extras." .. extra.name + end + table.sort(Config.json.data.extras, function(a, b) + local pa = M.prios[a] or 10 + local pb = M.prios[b] or 10 + if pa == pb then + return a < b + end + return pa < pb + end) + Config.json.save() + Util.info( + "`" + .. extra.name + .. "`" + .. " " + .. (extra.enabled and "**enabled**" or "**disabled**") + .. "\nPlease restart LazyVim to apply the changes.", + { title = "LazyExtras" } + ) + self:update() + return + end + end +end + +function X:update() + self.diag = {} + self.extras = M.get() + self.text = Text.new() + self.text.padding = 2 + self:render() + self.text:trim() + vim.bo[self.float.buf].modifiable = true + self.text:render(self.float.buf) + vim.bo[self.float.buf].modifiable = false + vim.diagnostic.set( + M.ns, + self.float.buf, + ---@param diag LazyDiagnostic + vim.tbl_map(function(diag) + diag.col = 0 + diag.lnum = diag.row - 1 + return diag + end, self.diag), + { signs = false, virtual_text = true } + ) +end + +function X:render() + self.text:nl():nl():append("LazyVim Extras", "LazyH1"):nl():nl() + self.text + :append("Enable/disable extras with the ", "LazyComment") + :append("", "LazySpecial") + :append(" key", "LazyComment") + :nl() + self:section({ enabled = true, title = "Enabled" }) + self:section({ enabled = false, title = "Disabled" }) +end + +---@param extra LazyExtra +function X:extra(extra) + if not extra.managed then + self:diagnostic({ + message = "Not managed by LazyExtras (config)", + severity = vim.diagnostic.severity.WARN, + }) + end + extra.row = self.text:row() + local hl = extra.managed and "LazySpecial" or "LazyLocal" + if extra.enabled then + self.text:append(" " .. LazyConfig.options.ui.icons.loaded .. " ", hl) + else + self.text:append(" " .. LazyConfig.options.ui.icons.not_loaded .. " ", hl) + end + self.text:append(extra.name) + for _, plugin in ipairs(extra.plugins) do + self.text:append(" "):append(LazyConfig.options.ui.icons.plugin .. "" .. plugin, "LazyReasonPlugin") + end + self.text:nl() +end + +---@param opts {enabled?:boolean, title?:string} +function X:section(opts) + opts = opts or {} + ---@type LazyExtra[] + local extras = vim.tbl_filter(function(extra) + return opts.enabled == nil or extra.enabled == opts.enabled + end, self.extras) + + self.text:nl():append(opts.title .. ":", "LazyH2"):append(" (" .. #extras .. ")", "LazyComment"):nl() + for _, extra in ipairs(extras) do + self:extra(extra) + end +end + +function M.show() + return X.new() +end + +return M diff --git a/lua/lazyvim/util/init.lua b/lua/lazyvim/util/init.lua index c46ac22e..90f9a89e 100644 --- a/lua/lazyvim/util/init.lua +++ b/lua/lazyvim/util/init.lua @@ -9,6 +9,7 @@ local LazyUtil = require("lazy.core.util") ---@field toggle lazyvim.util.toggle ---@field format lazyvim.util.format ---@field plugin lazyvim.util.plugin +---@field extras lazyvim.util.extras local M = {} ---@type table diff --git a/lua/lazyvim/util/root.lua b/lua/lazyvim/util/root.lua index fe263a7c..707ba5f8 100644 --- a/lua/lazyvim/util/root.lua +++ b/lua/lazyvim/util/root.lua @@ -106,12 +106,6 @@ function M.detect(opts) return ret end -function M.setup() - vim.api.nvim_create_user_command("LazyRoot", function() - M.info() - end, { desc = "LazyVim roots for the current buffer" }) -end - function M.info() local spec = type(vim.g.root_spec) == "table" and vim.g.root_spec or M.spec From 5bb74205a06a89f048902ba142473dd679b228b8 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Wed, 11 Oct 2023 18:10:04 +0200 Subject: [PATCH 23/83] feat(dashboard): added LazyExtras shortcut to dashboard/alpha --- lua/lazyvim/plugins/extras/ui/alpha.lua | 1 + lua/lazyvim/plugins/ui.lua | 1 + 2 files changed, 2 insertions(+) diff --git a/lua/lazyvim/plugins/extras/ui/alpha.lua b/lua/lazyvim/plugins/extras/ui/alpha.lua index 38019498..8778ab35 100644 --- a/lua/lazyvim/plugins/extras/ui/alpha.lua +++ b/lua/lazyvim/plugins/extras/ui/alpha.lua @@ -28,6 +28,7 @@ return { dashboard.button("g", " " .. " Find text", " Telescope live_grep "), dashboard.button("c", " " .. " Config", " e $MYVIMRC "), dashboard.button("s", " " .. " Restore Session", [[ lua require("persistence").load() ]]), + dashboard.button("e", " " .. " LazyExtras", " LazyExtras "), dashboard.button("l", "󰒲 " .. " Lazy", " Lazy "), dashboard.button("q", " " .. " Quit", " qa "), } diff --git a/lua/lazyvim/plugins/ui.lua b/lua/lazyvim/plugins/ui.lua index c22e0791..3fff8082 100644 --- a/lua/lazyvim/plugins/ui.lua +++ b/lua/lazyvim/plugins/ui.lua @@ -383,6 +383,7 @@ return { { action = "Telescope live_grep", desc = " Find text", icon = " ", key = "g" }, { action = "e $MYVIMRC", desc = " Config", icon = " ", key = "c" }, { action = 'lua require("persistence").load()', desc = " Restore Session", icon = " ", key = "s" }, + { action = "LazyExtras", desc = " LazyExtras", icon = " ", key = "e" }, { action = "Lazy", desc = " Lazy", icon = "󰒲 ", key = "l" }, { action = "qa", desc = " Quit", icon = " ", key = "q" }, }, From 592f3b03bb3cd01df42ee5db4cd6ba43937f067e Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Wed, 11 Oct 2023 18:38:29 +0200 Subject: [PATCH 24/83] fix(root): only use workspace folders that contain the buffer --- lua/lazyvim/util/root.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lua/lazyvim/util/root.lua b/lua/lazyvim/util/root.lua index 707ba5f8..54f44169 100644 --- a/lua/lazyvim/util/root.lua +++ b/lua/lazyvim/util/root.lua @@ -26,7 +26,8 @@ function M.detectors.cwd() end function M.detectors.lsp(buf) - if not M.bufpath(buf) then + local bufpath = M.bufpath(buf) + if not bufpath then return {} end local roots = {} ---@type string[] @@ -39,7 +40,10 @@ function M.detectors.lsp(buf) roots[#roots + 1] = client.config.root_dir end end - return roots + return vim.tbl_filter(function(path) + path = Util.norm(path) + return path and bufpath:find(path, 1, true) == 1 + end, roots) end ---@param patterns string[]|string From 305e82f2cacd5d0074027ea545a87a41379afc88 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Wed, 11 Oct 2023 22:36:45 +0200 Subject: [PATCH 25/83] feat(navic): moved navic to extras --- lua/lazyvim/plugins/extras/editor/navic.lua | 42 +++++++++++++++++++++ lua/lazyvim/plugins/ui.lua | 27 ------------- 2 files changed, 42 insertions(+), 27 deletions(-) create mode 100644 lua/lazyvim/plugins/extras/editor/navic.lua diff --git a/lua/lazyvim/plugins/extras/editor/navic.lua b/lua/lazyvim/plugins/extras/editor/navic.lua new file mode 100644 index 00000000..359c42d4 --- /dev/null +++ b/lua/lazyvim/plugins/extras/editor/navic.lua @@ -0,0 +1,42 @@ +return { + -- lsp symbol navigation for lualine. This shows where + -- in the code structure you are - within functions, classes, + -- etc - in the statusline. + { + "SmiteshP/nvim-navic", + lazy = true, + init = function() + vim.g.navic_silence = true + require("lazyvim.util").lsp.on_attach(function(client, buffer) + if client.supports_method("textDocument/documentSymbol") then + require("nvim-navic").attach(client, buffer) + end + end) + end, + opts = function() + return { + separator = " ", + highlight = true, + depth_limit = 5, + icons = require("lazyvim.config").icons.kinds, + lazy_update_context = true, + } + end, + }, + + -- lualine integration + { + "nvim-lualine/lualine.nvim", + optional = true, + opts = function(_, opts) + table.insert(opts.sections.lualine_c, { + function() + return require("nvim-navic").get_location() + end, + cond = function() + return package.loaded["nvim-navic"] and require("nvim-navic").is_available() + end, + }) + end, + }, +} diff --git a/lua/lazyvim/plugins/ui.lua b/lua/lazyvim/plugins/ui.lua index 3fff8082..4ab461fa 100644 --- a/lua/lazyvim/plugins/ui.lua +++ b/lua/lazyvim/plugins/ui.lua @@ -141,8 +141,6 @@ return { { "filename", path = 1, symbols = { modified = "  ", readonly = "", unnamed = "" } }, -- stylua: ignore { - function() return require("nvim-navic").get_location() end, - cond = function() return package.loaded["nvim-navic"] and require("nvim-navic").is_available() end, }, }, lualine_x = { @@ -308,31 +306,6 @@ return { }, }, - -- lsp symbol navigation for lualine. This shows where - -- in the code structure you are - within functions, classes, - -- etc - in the statusline. - { - "SmiteshP/nvim-navic", - lazy = true, - init = function() - vim.g.navic_silence = true - require("lazyvim.util").lsp.on_attach(function(client, buffer) - if client.supports_method("textDocument/documentSymbol") then - require("nvim-navic").attach(client, buffer) - end - end) - end, - opts = function() - return { - separator = " ", - highlight = true, - depth_limit = 5, - icons = require("lazyvim.config").icons.kinds, - lazy_update_context = true, - } - end, - }, - -- icons { "nvim-tree/nvim-web-devicons", lazy = true }, From 8d7361c4602993a7ea119cb7ce78d421b6787dfb Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Wed, 11 Oct 2023 22:37:28 +0200 Subject: [PATCH 26/83] feat(root): cached pretty path function for statuslines --- lua/lazyvim/plugins/ui.lua | 5 +++-- lua/lazyvim/util/root.lua | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/lua/lazyvim/plugins/ui.lua b/lua/lazyvim/plugins/ui.lua index 4ab461fa..a364d460 100644 --- a/lua/lazyvim/plugins/ui.lua +++ b/lua/lazyvim/plugins/ui.lua @@ -138,9 +138,10 @@ return { }, }, { "filetype", icon_only = true, separator = "", padding = { left = 1, right = 0 } }, - { "filename", path = 1, symbols = { modified = "  ", readonly = "", unnamed = "" } }, - -- stylua: ignore { + function() + return Util.root.pretty_path() + end, }, }, lualine_x = { diff --git a/lua/lazyvim/util/root.lua b/lua/lazyvim/util/root.lua index 54f44169..d799fe44 100644 --- a/lua/lazyvim/util/root.lua +++ b/lua/lazyvim/util/root.lua @@ -144,4 +144,38 @@ function M.get() return roots[1] and roots[1].paths[1] or vim.loop.cwd() end +M.pretty_cache = {} ---@type table +function M.pretty_path() + local path = vim.fn.expand("%:p") --[[@as string]] + if path == "" then + return "" + end + + path = Util.norm(path) + if M.pretty_cache[path] then + return M.pretty_cache[path] + end + local cache_key = path + local cwd = M.realpath(vim.loop.cwd()) or "" + + if path:find(cwd, 1, true) == 1 then + path = path:sub(#cwd + 2) + else + local roots = M.detect({ spec = { ".git" } }) + local root = roots[1] and roots[1].paths[1] or nil + if root then + path = path:sub(#vim.fs.dirname(root) + 2) + end + end + + local sep = package.config:sub(1, 1) + local parts = vim.split(path, "[\\/]") + if #parts > 3 then + parts = { parts[1], "…", parts[#parts - 1], parts[#parts] } + end + local ret = table.concat(parts, sep) + M.pretty_cache[cache_key] = ret + return ret +end + return M From e239235cd34ac9c286eac1e620670784566ef673 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Wed, 11 Oct 2023 22:38:10 +0200 Subject: [PATCH 27/83] feat(util): inject module --- lua/lazyvim/config/init.lua | 4 +--- lua/lazyvim/util/init.lua | 1 + lua/lazyvim/util/inject.lua | 20 ++++++++++++++++++++ lua/lazyvim/util/plugin.lua | 22 +++++++++++----------- 4 files changed, 33 insertions(+), 14 deletions(-) create mode 100644 lua/lazyvim/util/inject.lua diff --git a/lua/lazyvim/config/init.lua b/lua/lazyvim/config/init.lua index 076a003e..04c43f05 100644 --- a/lua/lazyvim/config/init.lua +++ b/lua/lazyvim/config/init.lua @@ -210,9 +210,7 @@ function M.init() -- after installing missing plugins M.load("options") - Util.plugin.fix_imports() - Util.plugin.fix_renames() - Util.plugin.lazy_file() + Util.plugin.setup() M.json.load() end diff --git a/lua/lazyvim/util/init.lua b/lua/lazyvim/util/init.lua index 90f9a89e..5cfd4e77 100644 --- a/lua/lazyvim/util/init.lua +++ b/lua/lazyvim/util/init.lua @@ -10,6 +10,7 @@ local LazyUtil = require("lazy.core.util") ---@field format lazyvim.util.format ---@field plugin lazyvim.util.plugin ---@field extras lazyvim.util.extras +---@field inject lazyvim.util.inject local M = {} ---@type table diff --git a/lua/lazyvim/util/inject.lua b/lua/lazyvim/util/inject.lua new file mode 100644 index 00000000..bf0d11f3 --- /dev/null +++ b/lua/lazyvim/util/inject.lua @@ -0,0 +1,20 @@ +---@class lazyvim.util.inject +local M = {} + +---@generic A: any +---@generic B: any +---@generic C: any +---@generic F: function +---@param fn F|fun(a:A, b:B, c:C) +---@param wrapper fun(a:A, b:B, c:C): boolean? +---@return F +function M.args(fn, wrapper) + return function(...) + if wrapper(...) == false then + return + end + return fn(...) + end +end + +return M diff --git a/lua/lazyvim/util/plugin.lua b/lua/lazyvim/util/plugin.lua index b3650eaa..7491ca7d 100644 --- a/lua/lazyvim/util/plugin.lua +++ b/lua/lazyvim/util/plugin.lua @@ -21,6 +21,12 @@ M.renames = { ["null-ls.nvim"] = "none-ls.nvim", } +function M.setup() + M.fix_imports() + M.fix_renames() + M.lazy_file() +end + -- Properly load file based plugins without blocking the UI function M.lazy_file() M.use_lazy_file = M.use_lazy_file and vim.fn.argc(-1) > 0 @@ -86,23 +92,18 @@ function M.lazy_file() end function M.fix_imports() - local import = Plugin.Spec.import - ---@diagnostic disable-next-line: duplicate-set-field - function Plugin.Spec:import(spec) + Plugin.Spec.import = Util.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 }) - return + return false end - return import(self, spec) - end + end) end function M.fix_renames() - local add = Plugin.Spec.add - ---@diagnostic disable-next-line: duplicate-set-field - Plugin.Spec.add = function(self, plugin, ...) + Plugin.Spec.add = Util.inject.args(Plugin.Spec.add, function(self, plugin) if type(plugin) == "table" then if M.renames[plugin[1]] then Util.warn( @@ -116,8 +117,7 @@ function M.fix_renames() plugin[1] = M.renames[plugin[1]] end end - return add(self, plugin, ...) - end + end) end return M From d8250910bdc4fce7ede914811f786d75ca028b48 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Wed, 11 Oct 2023 22:38:38 +0200 Subject: [PATCH 28/83] style(config): mini.align icons --- lua/lazyvim/config/init.lua | 91 +++++++++++++++++++------------------ 1 file changed, 47 insertions(+), 44 deletions(-) diff --git a/lua/lazyvim/config/init.lua b/lua/lazyvim/config/init.lua index 04c43f05..b3146eef 100644 --- a/lua/lazyvim/config/init.lua +++ b/lua/lazyvim/config/init.lua @@ -20,65 +20,68 @@ local defaults = { -- if you want to disable loading options, add `package.loaded["lazyvim.config.options"] = true` to the top of your init.lua }, -- icons used by other plugins + -- stylua: ignore icons = { misc = { dots = "󰇘", }, dap = { - Stopped = { "󰁕 ", "DiagnosticWarn", "DapStoppedLine" }, - Breakpoint = " ", + Stopped = { "󰁕 ", "DiagnosticWarn", "DapStoppedLine" }, + Breakpoint = " ", BreakpointCondition = " ", - BreakpointRejected = { " ", "DiagnosticError" }, - LogPoint = ".>", + BreakpointRejected = { " ", "DiagnosticError" }, + LogPoint = ".>", }, diagnostics = { Error = " ", - Warn = " ", - Hint = " ", - Info = " ", + Warn = " ", + Hint = " ", + Info = " ", }, git = { - added = " ", + added = " ", modified = " ", - removed = " ", + removed = " ", }, kinds = { - Array = " ", - Boolean = " ", - Class = " ", - Codeium = "󰘦 ", - Color = " ", - Constant = " ", - Constructor = " ", - Copilot = " ", - Enum = " ", - EnumMember = " ", - Event = " ", - Field = " ", - File = " ", - Folder = " ", - Function = " ", - Interface = " ", - Key = " ", - Keyword = " ", - Method = " ", - Module = " ", - Namespace = " ", - Null = " ", - Number = " ", - Object = " ", - Operator = " ", - Package = " ", - Property = " ", - Reference = " ", - Snippet = " ", - String = " ", - Struct = " ", - Text = " ", + Array = " ", + Boolean = "󰨙 ", + Class = " ", + Codeium = "󰘦 ", + Color = " ", + Control = " ", + Collapsed = " ", + Constant = "󰏿 ", + Constructor = " ", + Copilot = " ", + Enum = " ", + EnumMember = " ", + Event = " ", + Field = " ", + File = " ", + Folder = " ", + Function = "󰊕 ", + Interface = " ", + Key = " ", + Keyword = " ", + Method = "󰊕 ", + Module = " ", + Namespace = "󰦮 ", + Null = " ", + Number = "󰎠 ", + Object = " ", + Operator = " ", + Package = " ", + Property = " ", + Reference = " ", + Snippet = " ", + String = " ", + Struct = "󰆼 ", + Text = " ", TypeParameter = " ", - Unit = " ", - Value = " ", - Variable = " ", + Unit = " ", + Value = " ", + Variable = "󰀫 ", }, }, } From cb7f5aca7a04cf2d1d06397e9a80fe078d17976b Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Wed, 11 Oct 2023 22:39:24 +0200 Subject: [PATCH 29/83] feat(treesitter): install nvim-ts-autotag by default --- lua/lazyvim/plugins/treesitter.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lua/lazyvim/plugins/treesitter.lua b/lua/lazyvim/plugins/treesitter.lua index 47e58f1d..e4b50966 100644 --- a/lua/lazyvim/plugins/treesitter.lua +++ b/lua/lazyvim/plugins/treesitter.lua @@ -103,4 +103,10 @@ return { require("nvim-treesitter.configs").setup(opts) end, }, + -- Automatically add closing tags for HTML and JSX + { + "windwp/nvim-ts-autotag", + event = "InsertEnter", + opts = {}, + }, } From eb7a7d7a8e586d30ed6839f4a621e0f019d32410 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Thu, 12 Oct 2023 00:09:04 +0200 Subject: [PATCH 30/83] feat(config): make kind filter configurable for telescope/aerial/... --- lua/lazyvim/config/init.lua | 31 +++++++++++++++++++++++++ lua/lazyvim/plugins/editor.lua | 42 ++++++++-------------------------- 2 files changed, 41 insertions(+), 32 deletions(-) diff --git a/lua/lazyvim/config/init.lua b/lua/lazyvim/config/init.lua index b3146eef..217f0d53 100644 --- a/lua/lazyvim/config/init.lua +++ b/lua/lazyvim/config/init.lua @@ -84,6 +84,26 @@ local defaults = { Variable = "󰀫 ", }, }, + ---@type table? + kind_filter = { + default = { + "Class", + "Constructor", + "Enum", + "Field", + "Function", + "Interface", + "Method", + "Module", + "Property", + "Struct", + "Trait", + }, + -- you can specify a different filter for each filetype + -- lua = { + -- "Function", + -- }, + }, } M.json = { @@ -167,6 +187,17 @@ function M.setup(opts) Util.track() end +---@param buf? number +---@return string[]? +function M.get_kind_filter(buf) + buf = (buf == nil or buf == 0) and vim.api.nvim_get_current_buf() or buf + local ft = vim.bo[buf].filetype + if M.kind_filter == false then + return + end + return M.kind_filter[ft] or M.kind_filter.default +end + ---@param name "autocmds" | "options" | "keymaps" function M.load(name) local function _load(mod) diff --git a/lua/lazyvim/plugins/editor.lua b/lua/lazyvim/plugins/editor.lua index e2c08b98..6e1d63b6 100644 --- a/lua/lazyvim/plugins/editor.lua +++ b/lua/lazyvim/plugins/editor.lua @@ -150,42 +150,20 @@ return { { "uC", Util.telescope("colorscheme", { enable_preview = true }), desc = "Colorscheme with preview" }, { "ss", - Util.telescope("lsp_document_symbols", { - symbols = { - "Class", - "Function", - "Method", - "Constructor", - "Interface", - "Module", - "Struct", - "Trait", - "Field", - "Property", - "Enum", - "Constant", - }, - }), + function() + require("telescope.builtin").lsp_document_symbols({ + symbols = require("lazyvim.config").get_kind_filter(), + }) + end, desc = "Goto Symbol", }, { "sS", - Util.telescope("lsp_dynamic_workspace_symbols", { - symbols = { - "Class", - "Function", - "Method", - "Constructor", - "Interface", - "Module", - "Struct", - "Trait", - "Field", - "Property", - "Enum", - "Constant", - }, - }), + function() + require("telescope.builtin").lsp_dynamic_workspace_symbols({ + symbols = require("lazyvim.config").get_kind_filter(), + }) + end, desc = "Goto Symbol (Workspace)", }, }, From 13dbe4ad55a4e4b9a3dd345521b359411cdc5879 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Thu, 12 Oct 2023 00:09:38 +0200 Subject: [PATCH 31/83] perf(lualine): get rid of lualine's weird lualine_require --- lua/lazyvim/plugins/ui.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lua/lazyvim/plugins/ui.lua b/lua/lazyvim/plugins/ui.lua index a364d460..bef741ec 100644 --- a/lua/lazyvim/plugins/ui.lua +++ b/lua/lazyvim/plugins/ui.lua @@ -113,6 +113,10 @@ return { end end, opts = function() + -- PERF: we don't need this lualine require madness 🤷 + local lualine_require = require("lualine_require") + lualine_require.require = require + local icons = require("lazyvim.config").icons local Util = require("lazyvim.util") From 7b2c31740782fb0754ce715be6ea128083e48c4f Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Thu, 12 Oct 2023 00:11:12 +0200 Subject: [PATCH 32/83] feat(treesitter): add nvim-treesitter-context by default --- lua/lazyvim/plugins/treesitter.lua | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lua/lazyvim/plugins/treesitter.lua b/lua/lazyvim/plugins/treesitter.lua index e4b50966..c833a707 100644 --- a/lua/lazyvim/plugins/treesitter.lua +++ b/lua/lazyvim/plugins/treesitter.lua @@ -103,6 +103,15 @@ return { require("nvim-treesitter.configs").setup(opts) end, }, + + -- Show context of the current function + { + "nvim-treesitter/nvim-treesitter-context", + event = "LazyFile", + enabled = true, + opts = { mode = "cursor" }, + }, + -- Automatically add closing tags for HTML and JSX { "windwp/nvim-ts-autotag", From b43c57d943b2a13460d45f01a288e98cb54f2c1f Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Thu, 12 Oct 2023 00:11:33 +0200 Subject: [PATCH 33/83] feat: added aerial extra with integrations for edgy, telescope and lualine --- lua/lazyvim/plugins/extras/editor/aerial.lua | 133 +++++++++++++++++++ lua/lazyvim/util/plugin.lua | 9 ++ 2 files changed, 142 insertions(+) create mode 100644 lua/lazyvim/plugins/extras/editor/aerial.lua diff --git a/lua/lazyvim/plugins/extras/editor/aerial.lua b/lua/lazyvim/plugins/extras/editor/aerial.lua new file mode 100644 index 00000000..2d86d0d0 --- /dev/null +++ b/lua/lazyvim/plugins/extras/editor/aerial.lua @@ -0,0 +1,133 @@ +local Config = require("lazyvim.config") +local Util = require("lazyvim.util") + +return { + { + "stevearc/aerial.nvim", + event = "LazyFile", + opts = function() + ---@diagnostic disable-next-line: no-unknown + local lualine = require("lualine.components.aerial") + + -- Strip trailing spaces from symbols in statusline + ---@param _ any + ---@param symbols {icon?:string}[] + lualine.format_status = Util.inject.args(lualine.format_status, function(_, symbols) + for _, s in ipairs(symbols) do + s.icon = s.icon and s.icon:gsub("%s*$", "") or nil + end + end) + + local icons = vim.deepcopy(Config.icons.kinds) + + -- HACK: fix lua's weird choice for `Package` for control + -- structures like if/else/for/etc. + icons.lua = { Package = icons.Control } + + ---@type table|false + local filter_kind = false + if Config.kind_filter then + filter_kind = assert(vim.deepcopy(Config.kind_filter)) + filter_kind._ = filter_kind.default + filter_kind.default = nil + end + + local opts = { + attach_mode = "global", + backends = { "lsp", "treesitter", "markdown", "man" }, + show_guides = true, + layout = { + resize_to_content = false, + win_opts = { + winhl = "Normal:NormalFloat,FloatBorder:NormalFloat,SignColumn:SignColumnSB", + signcolumn = "yes", + statuscolumn = " ", + }, + }, + icons = icons, + filter_kind = filter_kind, + -- stylua: ignore + guides = { + mid_item = "├╴", + last_item = "└╴", + nested_top = "│ ", + whitespace = " ", + }, + } + return opts + end, + keys = { + { "cs", "SymbolsOutline", desc = "Symbols Outline" }, + }, + }, + + -- Telescope integration + { + "nvim-telescope/telescope.nvim", + opts = function() + Util.on_load("telescope.nvim", function() + require("telescope").load_extension("aerial") + end) + end, + keys = { + { + "ss", + "Telescope aerial", + desc = "Goto Symbol (Aerial)", + }, + }, + }, + + -- edgy integration + { + "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") + + 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.", { + title = "LazyVim", + }) + end + + opts.right = opts.right or {} + table.insert(opts.right, { + title = "Aerial", + ft = "aerial", + pinned = true, + open = "AerialOpen", + }) + end, + }, + + -- lualine integration + { + "nvim-lualine/lualine.nvim", + optional = true, + opts = function(_, opts) + table.insert(opts.sections.lualine_c, { + "aerial", + -- The separator to be used to separate symbols in status line. + sep = " ", + + -- The number of symbols to render top-down. In order to render only 'N' last + -- symbols, negative numbers may be supplied. For instance, 'depth = -1' can + -- be used in order to render only current symbol. + depth = 5, + + -- When 'dense' mode is on, icons are not rendered near their symbols. Only + -- a single icon that represents the kind of current symbol is rendered at + -- the beginning of status line. + dense = false, + + -- The separator to be used to separate symbols in dense mode. + dense_sep = ".", + + -- Color the symbol icons. + colored = true, + }) + end, + }, +} diff --git a/lua/lazyvim/util/plugin.lua b/lua/lazyvim/util/plugin.lua index 7491ca7d..c022758f 100644 --- a/lua/lazyvim/util/plugin.lua +++ b/lua/lazyvim/util/plugin.lua @@ -27,6 +27,15 @@ function M.setup() M.lazy_file() end +function M.extra_idx(name) + local Config = require("lazy.core.config") + for i, extra in ipairs(Config.spec.modules) do + if extra == "lazyvim.plugins.extras." .. name then + return i + end + end +end + -- Properly load file based plugins without blocking the UI function M.lazy_file() M.use_lazy_file = M.use_lazy_file and vim.fn.argc(-1) > 0 From eedb4a34050443448d0b752e22803d5b1278b419 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Thu, 12 Oct 2023 00:20:32 +0200 Subject: [PATCH 34/83] feat(ui): show optional plugins in a different color --- lua/lazyvim/plugins/extras/editor/aerial.lua | 1 + lua/lazyvim/util/extras.lua | 25 ++++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/lua/lazyvim/plugins/extras/editor/aerial.lua b/lua/lazyvim/plugins/extras/editor/aerial.lua index 2d86d0d0..9f0abdcb 100644 --- a/lua/lazyvim/plugins/extras/editor/aerial.lua +++ b/lua/lazyvim/plugins/extras/editor/aerial.lua @@ -64,6 +64,7 @@ return { -- Telescope integration { "nvim-telescope/telescope.nvim", + optional = true, opts = function() Util.on_load("telescope.nvim", function() require("telescope").load_extension("aerial") diff --git a/lua/lazyvim/util/extras.lua b/lua/lazyvim/util/extras.lua index 6e7bb742..c3c2e52b 100644 --- a/lua/lazyvim/util/extras.lua +++ b/lua/lazyvim/util/extras.lua @@ -11,6 +11,7 @@ local Util = require("lazyvim.util") ---@field managed boolean ---@field row? number ---@field plugins string[] +---@field optional string[] ---@class lazyvim.util.extras local M = {} @@ -43,12 +44,25 @@ function M.get() return vim.tbl_map(function(extra) local modname = "lazyvim.plugins.extras." .. extra local enabled = vim.tbl_contains(M.state, modname) - local spec = Plugin.Spec.new({ import = "lazyvim.plugins.extras." .. extra }, { optional = false }) + local spec = Plugin.Spec.new({ import = "lazyvim.plugins.extras." .. extra }, { optional = true }) + local plugins = {} ---@type string[] + local optional = {} ---@type string[] + for _, p in pairs(spec.plugins) do + if p.optional then + optional[#optional + 1] = p.name + else + plugins[#plugins + 1] = p.name + end + end + table.sort(plugins) + table.sort(optional) + return { name = extra, enabled = enabled, managed = vim.tbl_contains(Config.json.data.extras, extra) or not enabled, - plugins = vim.tbl_keys(spec.plugins), + plugins = plugins, + optional = optional, } end, extras) end @@ -151,6 +165,10 @@ end function X:render() self.text:nl():nl():append("LazyVim Extras", "LazyH1"):nl():nl() self.text + :append("This is a list of all enabled/disabled LazyVim extras.", "LazyComment") + :nl() + :append("Each extra shows the required and optional plugins it may install.", "LazyComment") + :nl() :append("Enable/disable extras with the ", "LazyComment") :append("", "LazySpecial") :append(" key", "LazyComment") @@ -178,6 +196,9 @@ function X:extra(extra) for _, plugin in ipairs(extra.plugins) do self.text:append(" "):append(LazyConfig.options.ui.icons.plugin .. "" .. plugin, "LazyReasonPlugin") end + for _, plugin in ipairs(extra.optional) do + self.text:append(" "):append(LazyConfig.options.ui.icons.plugin .. "" .. plugin, "LazyReasonRequire") + end self.text:nl() end From 1c34af7f0138323d9f465437d0bcef621a8dbe94 Mon Sep 17 00:00:00 2001 From: Bassam Data <105807570+bassamsdata@users.noreply.github.com> Date: Thu, 12 Oct 2023 01:28:49 -0400 Subject: [PATCH 35/83] feat(mini.starter): adding mini.starter to lualine disabled files (#1667) --- lua/lazyvim/plugins/ui.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/lazyvim/plugins/ui.lua b/lua/lazyvim/plugins/ui.lua index bef741ec..7f8b29c5 100644 --- a/lua/lazyvim/plugins/ui.lua +++ b/lua/lazyvim/plugins/ui.lua @@ -126,7 +126,7 @@ return { options = { theme = "auto", globalstatus = true, - disabled_filetypes = { statusline = { "dashboard", "alpha" } }, + disabled_filetypes = { statusline = { "dashboard", "alpha", "starter"} }, }, sections = { lualine_a = { "mode" }, From c7720275c3fa8b19c9ad7e05bfb6ed5c510bf2bb Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Thu, 12 Oct 2023 07:30:40 +0200 Subject: [PATCH 36/83] fix(aerial): keymap --- lua/lazyvim/plugins/extras/editor/aerial.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/lazyvim/plugins/extras/editor/aerial.lua b/lua/lazyvim/plugins/extras/editor/aerial.lua index 9f0abdcb..d46149b1 100644 --- a/lua/lazyvim/plugins/extras/editor/aerial.lua +++ b/lua/lazyvim/plugins/extras/editor/aerial.lua @@ -57,7 +57,7 @@ return { return opts end, keys = { - { "cs", "SymbolsOutline", desc = "Symbols Outline" }, + { "cs", "AerialToggle", desc = "Aerial (Symbols)" }, }, }, From 85215f396b6fd4de24636a202ec1149dafa5f7b5 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Thu, 12 Oct 2023 09:42:31 +0200 Subject: [PATCH 37/83] fix(nlua): make nlua dap work with regular continue. Fixes #1666 --- lua/lazyvim/plugins/extras/dap/core.lua | 1 - lua/lazyvim/plugins/extras/dap/nlua.lua | 49 +++++++++++++++++++++---- 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/lua/lazyvim/plugins/extras/dap/core.lua b/lua/lazyvim/plugins/extras/dap/core.lua index 1f079630..72aabded 100644 --- a/lua/lazyvim/plugins/extras/dap/core.lua +++ b/lua/lazyvim/plugins/extras/dap/core.lua @@ -54,7 +54,6 @@ return { opts = { defaults = { ["d"] = { name = "+debug" }, - ["da"] = { name = "+adapters" }, }, }, }, diff --git a/lua/lazyvim/plugins/extras/dap/nlua.lua b/lua/lazyvim/plugins/extras/dap/nlua.lua index 21a9e51d..12bf63ea 100644 --- a/lua/lazyvim/plugins/extras/dap/nlua.lua +++ b/lua/lazyvim/plugins/extras/dap/nlua.lua @@ -1,24 +1,59 @@ +local Util = require("lazyvim.util") + return { "mfussenegger/nvim-dap", + launch = function(host, port) + if vim.g.nlua then + return + end + vim.o.cmdheight = 10 + local osv = require("osv") + osv.launch({ + port = port, + host = host, + args = { "--cmd", "lua vim.g.nlua = true", "--cmd", "set cmdheight=10" }, + }) + vim.defer_fn(function() + vim.cmd([[luafile %]]) + end, 2000) + end, + dependencies = { { "jbyuki/one-small-step-for-vimkind", -- stylua: ignore - keys = { - { "daL", function() require("osv").launch({ port = 8086 }) end, desc = "Adapter Lua Server", ft = "lua" }, - { "dal", function() require("osv").run_this() end, desc = "Adapter Lua", ft = "lua" }, - }, config = function() local dap = require("dap") - dap.adapters.nlua = function(callback, config) - callback({ type = "server", host = config.host or "127.0.0.1", port = config.port or 8086 }) + dap.adapters.nlua = function(callback, conf) + local adapter = { + type = "server", + host = conf.host or "127.0.0.1", + port = conf.port or 8086, + } + if conf.start_neovim then + local dap_run = dap.run + dap.run = function(c) + adapter.port = c.port + adapter.host = c.host + end + require("osv").run_this() + dap.run = dap_run + end + callback(adapter) end dap.configurations.lua = { { type = "nlua", request = "attach", - name = "Attach to running Neovim instance", + name = "Run this file", + start_neovim = {}, + }, + { + type = "nlua", + request = "attach", + name = "Attach to running Neovim instance (port = 8086)", + port = 8086, }, } end, From 14f3f036e9223315f310ba9d35182690638e7bd7 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Thu, 12 Oct 2023 09:42:48 +0200 Subject: [PATCH 38/83] feat(inject): util method to get upvalue --- lua/lazyvim/util/inject.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lua/lazyvim/util/inject.lua b/lua/lazyvim/util/inject.lua index bf0d11f3..81e0f57a 100644 --- a/lua/lazyvim/util/inject.lua +++ b/lua/lazyvim/util/inject.lua @@ -17,4 +17,18 @@ function M.args(fn, wrapper) end end +function M.get_upvalue(func, name) + local i = 1 + while true do + local n, v = debug.getupvalue(func, i) + if not n then + break + end + if n == name then + return v + end + i = i + 1 + end +end + return M From ba4b8dfecbd79f4498b04a3899a11f948c026244 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Thu, 12 Oct 2023 09:43:24 +0200 Subject: [PATCH 39/83] refactor(nlua): cleanup --- lua/lazyvim/plugins/extras/dap/nlua.lua | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/lua/lazyvim/plugins/extras/dap/nlua.lua b/lua/lazyvim/plugins/extras/dap/nlua.lua index 12bf63ea..9cf0e63d 100644 --- a/lua/lazyvim/plugins/extras/dap/nlua.lua +++ b/lua/lazyvim/plugins/extras/dap/nlua.lua @@ -1,24 +1,5 @@ -local Util = require("lazyvim.util") - return { "mfussenegger/nvim-dap", - - launch = function(host, port) - if vim.g.nlua then - return - end - vim.o.cmdheight = 10 - local osv = require("osv") - osv.launch({ - port = port, - host = host, - args = { "--cmd", "lua vim.g.nlua = true", "--cmd", "set cmdheight=10" }, - }) - vim.defer_fn(function() - vim.cmd([[luafile %]]) - end, 2000) - end, - dependencies = { { "jbyuki/one-small-step-for-vimkind", From 72f3cc684bd1e8f19b2d3c56da3f359032b8c5dc Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Thu, 12 Oct 2023 10:18:50 +0200 Subject: [PATCH 40/83] fix(dap): copy config before overriding args --- lua/lazyvim/plugins/extras/dap/core.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/lua/lazyvim/plugins/extras/dap/core.lua b/lua/lazyvim/plugins/extras/dap/core.lua index 72aabded..c9aa291a 100644 --- a/lua/lazyvim/plugins/extras/dap/core.lua +++ b/lua/lazyvim/plugins/extras/dap/core.lua @@ -1,6 +1,7 @@ ---@param config {args?:string[]|fun():string[]?} local function get_args(config) local args = type(config.args) == "function" and (config.args() or {}) or config.args or {} + config = vim.deepcopy(config) ---@cast args string[] config.args = function() local new_args = vim.fn.input("Run with args: ", table.concat(args, " ")) --[[@as string]] From db5d28b039f656ccb47d3b9f787e8bb482cc6ec1 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Thu, 12 Oct 2023 10:35:47 +0200 Subject: [PATCH 41/83] fix(plugin): add nvim-treesitter-context rename warning --- lua/lazyvim/util/plugin.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/lua/lazyvim/util/plugin.lua b/lua/lazyvim/util/plugin.lua index c022758f..75d49899 100644 --- a/lua/lazyvim/util/plugin.lua +++ b/lua/lazyvim/util/plugin.lua @@ -19,6 +19,7 @@ M.renames = { ["windwp/nvim-spectre"] = "nvim-pack/nvim-spectre", ["jose-elias-alvarez/null-ls.nvim"] = "nvimtools/none-ls.nvim", ["null-ls.nvim"] = "none-ls.nvim", + ["romgrk/nvim-treesitter-context"] = "nvim-treesitter/nvim-treesitter-context", } function M.setup() From 3256abda65ae03358ecdbef1c7789782440fe39e Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Thu, 12 Oct 2023 10:36:15 +0200 Subject: [PATCH 42/83] fix(plugin): show warning of removed core plugin when trying to load them without having the extra --- lua/lazyvim/util/plugin.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lua/lazyvim/util/plugin.lua b/lua/lazyvim/util/plugin.lua index 75d49899..f23bec3b 100644 --- a/lua/lazyvim/util/plugin.lua +++ b/lua/lazyvim/util/plugin.lua @@ -14,6 +14,12 @@ M.deprecated_extras = { ["lazyvim.plugins.extras.ui.dashboard"] = "`dashboard.nvim` is now the default **LazyVim** starter.", } +M.deprecated_modules = { + ["null-ls"] = "lsp.none-ls", + ["nvim-navic.lib"] = "editor.navic", + ["nvim-navic"] = "editor.navic", +} + ---@type table M.renames = { ["windwp/nvim-spectre"] = "nvim-pack/nvim-spectre", @@ -26,6 +32,18 @@ function M.setup() M.fix_imports() M.fix_renames() M.lazy_file() + table.insert(package.loaders, function(module) + if M.deprecated_modules[module] then + Util.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] + ), + { title = "LazyVim" } + ) + return function() end + end + end) end function M.extra_idx(name) From a4e393154f61b95da5835b6461e211eb94740268 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Thu, 12 Oct 2023 11:14:02 +0200 Subject: [PATCH 43/83] fix(extras): make sure we use priorities to import extras in correct order --- lua/lazyvim/plugins/xtras.lua | 17 +++++++++++++++++ lua/lazyvim/util/extras.lua | 15 +-------------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/lua/lazyvim/plugins/xtras.lua b/lua/lazyvim/plugins/xtras.lua index 0a6ed614..009bb6fa 100644 --- a/lua/lazyvim/plugins/xtras.lua +++ b/lua/lazyvim/plugins/xtras.lua @@ -1,5 +1,22 @@ local Config = require("lazyvim.config") +-- Some extras need to be loaded before others +local prios = { + ["editor.aerial"] = 100, + ["editor.symbols-outline"] = 100, + ["test.core"] = 1, + ["dap.core"] = 1, +} + +table.sort(Config.json.data.extras, function(a, b) + local pa = prios[a] or 10 + local pb = prios[b] or 10 + if pa == pb then + return a < b + end + return pa < pb +end) + ---@param extra string return vim.tbl_map(function(extra) return { import = "lazyvim.plugins.extras." .. extra } diff --git a/lua/lazyvim/util/extras.lua b/lua/lazyvim/util/extras.lua index c3c2e52b..c71e328c 100644 --- a/lua/lazyvim/util/extras.lua +++ b/lua/lazyvim/util/extras.lua @@ -16,12 +16,6 @@ local Util = require("lazyvim.util") ---@class lazyvim.util.extras local M = {} -M.prios = { - ["editor.aerial"] = 100, - ["test.core"] = 1, - ["dap.core"] = 1, -} - M.ns = vim.api.nvim_create_namespace("lazyvim.extras") ---@type string[] M.state = nil @@ -115,14 +109,7 @@ function X:toggle() table.insert(Config.json.data.extras, extra.name) M.state[#M.state + 1] = "lazyvim.plugins.extras." .. extra.name end - table.sort(Config.json.data.extras, function(a, b) - local pa = M.prios[a] or 10 - local pb = M.prios[b] or 10 - if pa == pb then - return a < b - end - return pa < pb - end) + table.sort(Config.json.data.extras) Config.json.save() Util.info( "`" From f64039f54620fe3fc9e8f464e35b184c6834ed6e Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Thu, 12 Oct 2023 11:14:23 +0200 Subject: [PATCH 44/83] feat(config): better kind filter default for lua to deal with luals weirdness --- lua/lazyvim/config/init.lua | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/lua/lazyvim/config/init.lua b/lua/lazyvim/config/init.lua index 217f0d53..2f7e0184 100644 --- a/lua/lazyvim/config/init.lua +++ b/lua/lazyvim/config/init.lua @@ -95,14 +95,28 @@ local defaults = { "Interface", "Method", "Module", + "Namespace", + "Package", "Property", "Struct", "Trait", }, -- you can specify a different filter for each filetype - -- lua = { - -- "Function", - -- }, + lua = { + "Class", + "Constructor", + "Enum", + "Field", + "Function", + "Interface", + "Method", + "Module", + "Namespace", + -- "Package", -- remove package since luals uses it for control flow structures + "Property", + "Struct", + "Trait", + }, }, } From b4ba5d881dcb801d3c502665f9767d2f75ca1110 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Thu, 12 Oct 2023 11:14:44 +0200 Subject: [PATCH 45/83] feat(extras): added extra for `symbols-outline.nvim` --- .../plugins/extras/editor/symbols-outline.lua | 55 +++++++++++++++++++ lua/lazyvim/plugins/extras/ui/edgy.lua | 9 --- 2 files changed, 55 insertions(+), 9 deletions(-) create mode 100644 lua/lazyvim/plugins/extras/editor/symbols-outline.lua diff --git a/lua/lazyvim/plugins/extras/editor/symbols-outline.lua b/lua/lazyvim/plugins/extras/editor/symbols-outline.lua new file mode 100644 index 00000000..f0b0ba92 --- /dev/null +++ b/lua/lazyvim/plugins/extras/editor/symbols-outline.lua @@ -0,0 +1,55 @@ +local Util = require("lazyvim.util") + +return { + { + "simrat39/symbols-outline.nvim", + keys = { { "cs", "SymbolsOutline", desc = "Symbols Outline" } }, + cmd = "SymbolsOutline", + opts = function() + local Config = require("lazyvim.config") + local defaults = require("symbols-outline.config").defaults + local opts = { + symbols = {}, + symbol_blacklist = {}, + } + + for kind, symbol in pairs(defaults.symbols) do + opts.symbols[kind] = { + icon = Config.icons.kinds[kind] or symbol.icon, + hl = symbol.hl, + } + if not vim.tbl_contains(Config.kind_filter.default, kind) then + table.insert(opts.symbol_blacklist, kind) + end + end + return opts + end, + }, + + -- edgy integration + { + "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.symbols-outline") + + if edgy_idx and edgy_idx > symbols_idx then + Util.warn( + "The `edgy.nvim` extra must be **imported** before the `symbols-outline.nvim` extra to work properly.", + { + title = "LazyVim", + } + ) + end + + opts.right = opts.right or {} + table.insert(opts.right, { + title = "Symbols Outline", + ft = "Outline", + pinned = true, + open = "SymbolsOutline", + }) + end, + }, +} diff --git a/lua/lazyvim/plugins/extras/ui/edgy.lua b/lua/lazyvim/plugins/extras/ui/edgy.lua index 8692d481..64e6237a 100644 --- a/lua/lazyvim/plugins/extras/ui/edgy.lua +++ b/lua/lazyvim/plugins/extras/ui/edgy.lua @@ -105,15 +105,6 @@ return { end, }, } - local Util = require("lazyvim.util") - if Util.has("symbols-outline.nvim") then - table.insert(opts.left, { - title = "Outline", - ft = "Outline", - pinned = true, - open = "SymbolsOutline", - }) - end return opts end, }, From ce74e28464daa7d694f9ab4e41fae3174e30c8b3 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Thu, 12 Oct 2023 11:20:46 +0200 Subject: [PATCH 46/83] feat(starter): added Lazy Extras to `mini.starter` --- lua/lazyvim/plugins/extras/ui/alpha.lua | 17 +++++++++-------- .../plugins/extras/ui/mini-starter.lua | 15 ++++++++------- lua/lazyvim/plugins/ui.lua | 19 ++++++++++--------- 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/lua/lazyvim/plugins/extras/ui/alpha.lua b/lua/lazyvim/plugins/extras/ui/alpha.lua index 8778ab35..d05c941c 100644 --- a/lua/lazyvim/plugins/extras/ui/alpha.lua +++ b/lua/lazyvim/plugins/extras/ui/alpha.lua @@ -21,16 +21,17 @@ return { ]] dashboard.section.header.val = vim.split(logo, "\n") + -- stylua: ignore dashboard.section.buttons.val = { - dashboard.button("f", " " .. " Find file", " Telescope find_files "), - dashboard.button("n", " " .. " New file", " ene startinsert "), - dashboard.button("r", " " .. " Recent files", " Telescope oldfiles "), - dashboard.button("g", " " .. " Find text", " Telescope live_grep "), - dashboard.button("c", " " .. " Config", " e $MYVIMRC "), + dashboard.button("f", " " .. " Find file", " Telescope find_files "), + dashboard.button("n", " " .. " New file", " ene startinsert "), + dashboard.button("r", " " .. " Recent files", " Telescope oldfiles "), + dashboard.button("g", " " .. " Find text", " Telescope live_grep "), + dashboard.button("c", " " .. " Config", " e $MYVIMRC "), dashboard.button("s", " " .. " Restore Session", [[ lua require("persistence").load() ]]), - dashboard.button("e", " " .. " LazyExtras", " LazyExtras "), - dashboard.button("l", "󰒲 " .. " Lazy", " Lazy "), - dashboard.button("q", " " .. " Quit", " qa "), + dashboard.button("e", " " .. " Lazy Extras", " LazyExtras "), + dashboard.button("l", "󰒲 " .. " Lazy", " Lazy "), + dashboard.button("q", " " .. " Quit", " qa "), } for _, button in ipairs(dashboard.section.buttons.val) do button.opts.hl = "AlphaButtons" diff --git a/lua/lazyvim/plugins/extras/ui/mini-starter.lua b/lua/lazyvim/plugins/extras/ui/mini-starter.lua index 04a578be..6ec0e572 100644 --- a/lua/lazyvim/plugins/extras/ui/mini-starter.lua +++ b/lua/lazyvim/plugins/extras/ui/mini-starter.lua @@ -29,13 +29,14 @@ return { evaluate_single = true, header = logo, items = { - new_section("Find file", "Telescope find_files", "Telescope"), - new_section("Recent files", "Telescope oldfiles", "Telescope"), - new_section("Grep text", "Telescope live_grep", "Telescope"), - new_section("init.lua", "e $MYVIMRC", "Config"), - new_section("Lazy", "Lazy", "Config"), - new_section("New file", "ene | startinsert", "Built-in"), - new_section("Quit", "qa", "Built-in"), + new_section("Find file", "Telescope find_files", "Telescope"), + new_section("Recent files", "Telescope oldfiles", "Telescope"), + new_section("Grep text", "Telescope live_grep", "Telescope"), + new_section("init.lua", "e $MYVIMRC", "Config"), + new_section("Extras", "LazyExtras", "Config"), + new_section("Lazy", "Lazy", "Config"), + new_section("New file", "ene | startinsert", "Built-in"), + new_section("Quit", "qa", "Built-in"), new_section("Session restore", [[lua require("persistence").load()]], "Session"), }, content_hooks = { diff --git a/lua/lazyvim/plugins/ui.lua b/lua/lazyvim/plugins/ui.lua index 7f8b29c5..e821c33e 100644 --- a/lua/lazyvim/plugins/ui.lua +++ b/lua/lazyvim/plugins/ui.lua @@ -126,7 +126,7 @@ return { options = { theme = "auto", globalstatus = true, - disabled_filetypes = { statusline = { "dashboard", "alpha", "starter"} }, + disabled_filetypes = { statusline = { "dashboard", "alpha", "starter" } }, }, sections = { lualine_a = { "mode" }, @@ -354,16 +354,17 @@ return { }, config = { header = vim.split(logo, "\n"), + -- stylua: ignore center = { - { action = "Telescope find_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 = "e $MYVIMRC", desc = " Config", icon = " ", key = "c" }, + { action = "Telescope find_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 = "e $MYVIMRC", desc = " Config", icon = " ", key = "c" }, { action = 'lua require("persistence").load()', desc = " Restore Session", icon = " ", key = "s" }, - { action = "LazyExtras", desc = " LazyExtras", icon = " ", key = "e" }, - { action = "Lazy", desc = " Lazy", icon = "󰒲 ", key = "l" }, - { action = "qa", desc = " Quit", icon = " ", key = "q" }, + { action = "LazyExtras", desc = " Lazy Extras", icon = " ", key = "e" }, + { action = "Lazy", desc = " Lazy", icon = "󰒲 ", key = "l" }, + { action = "qa", desc = " Quit", icon = " ", key = "q" }, }, footer = function() local stats = require("lazy").stats() From 442077fca3cbca73746909c4bc7e1029d35fecad Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 12 Oct 2023 09:48:46 +0000 Subject: [PATCH 47/83] chore(build): auto-generate vimdoc --- doc/LazyVim.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/LazyVim.txt b/doc/LazyVim.txt index a950794a..ea9ed565 100644 --- a/doc/LazyVim.txt +++ b/doc/LazyVim.txt @@ -1,4 +1,4 @@ -*LazyVim.txt* For Neovim >= 0.8.0 Last change: 2023 October 11 +*LazyVim.txt* For Neovim >= 0.8.0 Last change: 2023 October 12 ============================================================================== Table of Contents *LazyVim-table-of-contents* From 73acab16758d37982bd6b2d9b2be37c4ee83cde3 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Thu, 12 Oct 2023 14:38:25 +0200 Subject: [PATCH 48/83] feat: added NEWS.md and option to automatically show when changed (enabled by default) --- NEWS.md | 65 ++++++++++++++++++++++++++++ lua/lazyvim/config/init.lua | 9 ++++ lua/lazyvim/config/keymaps.lua | 2 +- lua/lazyvim/util/init.lua | 9 +--- lua/lazyvim/util/news.lua | 77 ++++++++++++++++++++++++++++++++++ 5 files changed, 153 insertions(+), 9 deletions(-) create mode 100644 NEWS.md create mode 100644 lua/lazyvim/util/news.lua diff --git a/NEWS.md b/NEWS.md new file mode 100644 index 00000000..af6fca2f --- /dev/null +++ b/NEWS.md @@ -0,0 +1,65 @@ +# What's new? + +## 10.x + +- `nvim-ts-autotag` is now included by default + +- `nvim-treesitter-context` is now included by default + +- Added extra for `symbols-outline.nvim` + +- Added extra for `aerial.nvim` + +- `nvim-navic` has been removed. If you want to keep using `nvim-navic`, + you can enable the **editor.navic** extra + +- New `:LazyExtras` command for managing **LazyVim** extras + +- Improved **formatting**: + + - **LazyVim** can now work with multiple formatters. Types: + + - **primary**: only one primary formatter can be active at a time. + _(conform, none-ls, LSP)_ + - **secondary**: multiple secondary formatters can be active _(eslint, ...)_ + + - **LazyVim** automatically selects the primary formatter based on the + current available sources and priorities. + + - New `:LazyFormat` command for formatting the current selection or buffer + - New `:LazyFormatInfo` command for displaying the active formatters + for the current buffer + - Auto-formatting can be disabled with: + + ```lua + vim.g.autoformat = false -- globally + vim.b.autoformat = false -- buffer-local + ``` + +- `none-ls.nvim` is no longer installed by default + + - `conform.nvim` is now the default formatter + - `nvim-lint` is now the default linter + - If you want to keep using `none-ls.nvim`, + you can enable the **lsp.none-ls** extra + +- `dashboard.nvim` is the new default dashboard plugin + + - If you want to keep using `alpha.nvim`, you can enable the **ui.alpha** extra + +- Improved **root detection**: + + - New `:LazyRoot` command that shows info about the root dir detection + - Configurable with `vim.g.root_spec` + + ```lua + -- LazyVim root dir detection + -- Each entry can be: + -- * the name of a detector function like `lsp` or `cwd` + -- * a pattern or array of patterns like `.git` or `lua`. + -- * a function with signature `function(buf) -> string|string[]` + vim.g.root_spec = { "lsp", { ".git", "lua" }, "cwd" } + + -- To disable root detection set to just "cwd" + vim.g.root_spec = { "cwd" } + ``` diff --git a/lua/lazyvim/config/init.lua b/lua/lazyvim/config/init.lua index 2f7e0184..07bb1ed6 100644 --- a/lua/lazyvim/config/init.lua +++ b/lua/lazyvim/config/init.lua @@ -19,6 +19,13 @@ local defaults = { -- lazyvim.config.options can't be configured here since that's loaded before lazyvim setup -- if you want to disable loading options, add `package.loaded["lazyvim.config.options"] = true` to the top of your init.lua }, + news = { + -- When enabled, NEWS.md will be shown when changed. + -- This only contains big new features and breaking changes. + lazyvim = true, + -- Same but for Neovim's news.txt + neovim = false, + }, -- icons used by other plugins -- stylua: ignore icons = { @@ -123,6 +130,7 @@ local defaults = { M.json = { data = { version = nil, ---@type string? + hashes = {}, ---@type table extras = {}, ---@type string[] }, } @@ -173,6 +181,7 @@ function M.setup(opts) M.load("keymaps") Util.format.setup() + Util.news.setup() vim.api.nvim_create_user_command("LazyRoot", function() Util.root.info() diff --git a/lua/lazyvim/config/keymaps.lua b/lua/lazyvim/config/keymaps.lua index 79c0ee06..bae7b15b 100644 --- a/lua/lazyvim/config/keymaps.lua +++ b/lua/lazyvim/config/keymaps.lua @@ -125,7 +125,7 @@ map("n", "qq", "qa", { desc = "Quit all" }) map("n", "ui", vim.show_pos, { desc = "Inspect Pos" }) -- LazyVim Changelog -map("n", "L", Util.changelog, {desc = "LazyVim Changelog"}) +map("n", "L", function() Util.news.changelog() end, { desc = "LazyVim Changelog" }) -- floating terminal local lazyterm = function() Util.terminal(nil, { cwd = Util.root() }) end diff --git a/lua/lazyvim/util/init.lua b/lua/lazyvim/util/init.lua index 5cfd4e77..2751e8e6 100644 --- a/lua/lazyvim/util/init.lua +++ b/lua/lazyvim/util/init.lua @@ -11,6 +11,7 @@ local LazyUtil = require("lazy.core.util") ---@field plugin lazyvim.util.plugin ---@field extras lazyvim.util.extras ---@field inject lazyvim.util.inject +---@field news lazyvim.util.news local M = {} ---@type table @@ -137,14 +138,6 @@ function M.on_load(name, fn) end end -function M.changelog() - local lv = require("lazy.core.config").plugins.LazyVim - local float = require("lazy.util").open(lv.dir .. "/CHANGELOG.md") - vim.wo[float.win].spell = false - vim.wo[float.win].wrap = false - vim.diagnostic.disable(float.buf) -end - -- Wrapper around vim.keymap.set that will -- not create a keymap if a lazy key handler exists. -- It will also set `silent` to true by default. diff --git a/lua/lazyvim/util/news.lua b/lua/lazyvim/util/news.lua new file mode 100644 index 00000000..4e28148b --- /dev/null +++ b/lua/lazyvim/util/news.lua @@ -0,0 +1,77 @@ +local Config = require("lazyvim.config") +local Util = require("lazyvim.util") + +---@class lazyvim.util.news +local M = {} + +function M.hash(file) + local stat = vim.loop.fs_stat(file) + if not stat then + return + end + return stat.size .. "" +end + +function M.setup() + vim.schedule(function() + if Config.news.lazyvim then + M.lazyvim(true) + end + if Config.news.neovim then + M.neovim(true) + end + end) +end + +function M.changelog() + M.open("CHANGELOG.md", { plugin = "LazyVim" }) +end + +function M.lazyvim(when_changed) + M.open("NEWS.md", { plugin = "LazyVim", when_changed = when_changed }) +end + +function M.neovim(when_changed) + M.open("doc/news.txt", { rtp = true, when_changed = when_changed }) +end + +---@param file string +---@param opts? {plugin?:string, rtp?:boolean, when_changed?:boolean} +function M.open(file, opts) + opts = opts or {} + 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) + end + file = plugin.dir .. "/" .. file + elseif opts.rtp then + file = vim.api.nvim_get_runtime_file(file, false)[1] + end + + if not file then + return Util.error("File not found") + end + + if opts.when_changed then + local hash = M.hash(file) + if hash == Config.json.data.hashes[file] then + return + end + Config.json.data.hashes[file] = hash + Config.json.save() + end + + local float = require("lazy.util").float({ + file = file, + size = { width = 0.6, height = 0.6 }, + }) + vim.wo[float.win].spell = false + vim.wo[float.win].wrap = false + vim.wo[float.win].signcolumn = "yes" + vim.wo[float.win].statuscolumn = " " + vim.wo[float.win].conceallevel = 3 + vim.diagnostic.disable(float.buf) +end + +return M From 763c0fd9f296ec31119c0e7109b9b73d15553fff Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 12 Oct 2023 14:49:38 +0200 Subject: [PATCH 49/83] chore(main): release 10.0.0 (#1673) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- CHANGELOG.md | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c1136f07..1161066d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,63 @@ # Changelog +## [10.0.0](https://github.com/LazyVim/LazyVim/compare/v9.9.1...v10.0.0) (2023-10-12) + + +### ⚠ BREAKING CHANGES + +* **starter:** `dashboard.nvim` is now the default starter. To keep using `alpha.nvim`, enable the extra. +* make `conform.nvim` and `nvim-lint` the default formatters/linters + +### Features + +* added aerial extra with integrations for edgy, telescope and lualine ([b43c57d](https://github.com/LazyVim/LazyVim/commit/b43c57d943b2a13460d45f01a288e98cb54f2c1f)) +* added NEWS.md and option to automatically show when changed (enabled by default) ([73acab1](https://github.com/LazyVim/LazyVim/commit/73acab16758d37982bd6b2d9b2be37c4ee83cde3)) +* **config:** better kind filter default for lua to deal with luals weirdness ([f64039f](https://github.com/LazyVim/LazyVim/commit/f64039f54620fe3fc9e8f464e35b184c6834ed6e)) +* **config:** load/save some data in lazyvim.json ([11d66e7](https://github.com/LazyVim/LazyVim/commit/11d66e713467410add9ad5a7a68a3bca0aa24082)) +* **config:** make kind filter configurable for telescope/aerial/... ([eb7a7d7](https://github.com/LazyVim/LazyVim/commit/eb7a7d7a8e586d30ed6839f4a621e0f019d32410)) +* **config:** use lazy's new custom events (`Event.mappings`) for a better `LazyFile` ([4ea1c68](https://github.com/LazyVim/LazyVim/commit/4ea1c6865e6d877207de8626e11a5a863950ae55)) +* **dashboard:** added LazyExtras shortcut to dashboard/alpha ([5bb7420](https://github.com/LazyVim/LazyVim/commit/5bb74205a06a89f048902ba142473dd679b228b8)) +* **extras:** added extra for `symbols-outline.nvim` ([b4ba5d8](https://github.com/LazyVim/LazyVim/commit/b4ba5d881dcb801d3c502665f9767d2f75ca1110)) +* **format:** new LazyVim formatter with integrations for lsp/none-ls/conform/eslint/... ([f1a8f24](https://github.com/LazyVim/LazyVim/commit/f1a8f24a361d0de198f6b1458168652a6835c932)) +* **inject:** util method to get upvalue ([14f3f03](https://github.com/LazyVim/LazyVim/commit/14f3f036e9223315f310ba9d35182690638e7bd7)) +* make `conform.nvim` and `nvim-lint` the default formatters/linters ([14c091b](https://github.com/LazyVim/LazyVim/commit/14c091b1fc6b0dc0b22ac49ccac69f8a02e3844c)) +* **mini.starter:** adding mini.starter to lualine disabled files ([#1667](https://github.com/LazyVim/LazyVim/issues/1667)) ([1c34af7](https://github.com/LazyVim/LazyVim/commit/1c34af7f0138323d9f465437d0bcef621a8dbe94)) +* **navic:** moved navic to extras ([305e82f](https://github.com/LazyVim/LazyVim/commit/305e82f2cacd5d0074027ea545a87a41379afc88)) +* **root:** allow custom functions as part of `vim.g.root_spec` ([c33e748](https://github.com/LazyVim/LazyVim/commit/c33e7489ecdaef7295a63079410f2f24a1cbc9b6)) +* **root:** cached pretty path function for statuslines ([8d7361c](https://github.com/LazyVim/LazyVim/commit/8d7361c4602993a7ea119cb7ce78d421b6787dfb)) +* **root:** customizable root detection and `:LazyRoot` command ([a2d6049](https://github.com/LazyVim/LazyVim/commit/a2d604928b5629d14797437a26022065f7385216)) +* **starter:** `dashboard.nvim` is now the default starter. To keep using `alpha.nvim`, enable the extra. ([4cbe42c](https://github.com/LazyVim/LazyVim/commit/4cbe42cd247c72dfc70c3fcddfa3fb6b5e6485e0)) +* **starter:** added Lazy Extras to `mini.starter` ([ce74e28](https://github.com/LazyVim/LazyVim/commit/ce74e28464daa7d694f9ab4e41fae3174e30c8b3)) +* **treesitter:** add nvim-treesitter-context by default ([7b2c317](https://github.com/LazyVim/LazyVim/commit/7b2c31740782fb0754ce715be6ea128083e48c4f)) +* **treesitter:** install nvim-ts-autotag by default ([cb7f5ac](https://github.com/LazyVim/LazyVim/commit/cb7f5aca7a04cf2d1d06397e9a80fe078d17976b)) +* **ui:** added `:LazyExtras` to manage enabled extras in LazyVim ([c4e55e4](https://github.com/LazyVim/LazyVim/commit/c4e55e4d67a7195b7aa9160cd8ece3ddc2f6cb51)) +* **ui:** show optional plugins in a different color ([eedb4a3](https://github.com/LazyVim/LazyVim/commit/eedb4a34050443448d0b752e22803d5b1278b419)) +* **util:** inject module ([e239235](https://github.com/LazyVim/LazyVim/commit/e239235cd34ac9c286eac1e620670784566ef673)) + + +### Bug Fixes + +* **aerial:** keymap ([c772027](https://github.com/LazyVim/LazyVim/commit/c7720275c3fa8b19c9ad7e05bfb6ed5c510bf2bb)) +* **dap:** copy config before overriding args ([72f3cc6](https://github.com/LazyVim/LazyVim/commit/72f3cc684bd1e8f19b2d3c56da3f359032b8c5dc)) +* **extras:** make sure we use priorities to import extras in correct order ([a4e3931](https://github.com/LazyVim/LazyVim/commit/a4e393154f61b95da5835b6461e211eb94740268)) +* **format:** always show formatter status even when no sources available ([a4abbdc](https://github.com/LazyVim/LazyVim/commit/a4abbdc89bd1d49378ac5873db1279e7e5398927)) +* **lualine:** when opening nvim with a file, show an empty statusline till lualine loads ([8373467](https://github.com/LazyVim/LazyVim/commit/83734675b0f93fbd11a350ee0662c09995836b59)) +* **neo-tree:** during init check global argslist instead of window-local ([8fbde2c](https://github.com/LazyVim/LazyVim/commit/8fbde2c3668960ed085f9225bb4650aca77cc495)) +* **nlua:** make nlua dap work with regular continue. Fixes [#1666](https://github.com/LazyVim/LazyVim/issues/1666) ([85215f3](https://github.com/LazyVim/LazyVim/commit/85215f396b6fd4de24636a202ec1149dafa5f7b5)) +* **notify:** set default zindex=100 ([7fb7948](https://github.com/LazyVim/LazyVim/commit/7fb79486ed1b251b98b95a44ef50b3742edd708d)) +* **plugin:** add nvim-treesitter-context rename warning ([db5d28b](https://github.com/LazyVim/LazyVim/commit/db5d28b039f656ccb47d3b9f787e8bb482cc6ec1)) +* **plugin:** enable lazy_file ([f59cdff](https://github.com/LazyVim/LazyVim/commit/f59cdff4d9f04ff349cefdee0b363d573954ce0d)) +* **plugin:** show warning of removed core plugin when trying to load them without having the extra ([3256abd](https://github.com/LazyVim/LazyVim/commit/3256abda65ae03358ecdbef1c7789782440fe39e)) +* **root:** only use workspace folders that contain the buffer ([592f3b0](https://github.com/LazyVim/LazyVim/commit/592f3b03bb3cd01df42ee5db4cd6ba43937f067e)) +* **ui:** dont show left signs on virtual line numbers (wrap). Fixes [#1654](https://github.com/LazyVim/LazyVim/issues/1654) ([e6d294d](https://github.com/LazyVim/LazyVim/commit/e6d294df6fbd973644d4b7f9691d5f48cc5efdde)) + + +### Performance Improvements + +* **lualine:** get rid of lualine's weird lualine_require ([13dbe4a](https://github.com/LazyVim/LazyVim/commit/13dbe4ad55a4e4b9a3dd345521b359411cdc5879)) +* **plugin:** move all lazy.nvim related code to `lazyvim.util.plugin` ([70f9195](https://github.com/LazyVim/LazyVim/commit/70f91956e7f03e740b51cbc14c87df6a6f74538f)) +* **util:** split lazyvim.util in smaller separate modules ([c8c929c](https://github.com/LazyVim/LazyVim/commit/c8c929c9fdc44cc69cb034c47bd89d2bc4e4a429)) + ## [9.9.1](https://github.com/LazyVim/LazyVim/compare/v9.9.0...v9.9.1) (2023-10-11) From 7d9a3955651ba3f59389596e869affcedccaa489 Mon Sep 17 00:00:00 2001 From: Sergey Kochetkov Date: Thu, 12 Oct 2023 15:10:26 +0200 Subject: [PATCH 50/83] style(format): Fix typo (#1675) --- lua/lazyvim/util/format.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/lazyvim/util/format.lua b/lua/lazyvim/util/format.lua index af64a6f5..2a5ef5ac 100644 --- a/lua/lazyvim/util/format.lua +++ b/lua/lazyvim/util/format.lua @@ -130,7 +130,7 @@ function M.health() 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({ - "`conform.nvim` and `nvim-lint` are now the default forrmatters and linters in LazyVim.", + "`conform.nvim` and `nvim-lint` are now the default formatters and linters in LazyVim.", "", "You can use those plugins together with `none-ls.nvim`,", "but you need to enable the `lazyvim.plugins.extras.lsp.none-ls` extra,", From 2a0b7a88ba4b4562361dd5abb4a071547d004e59 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Thu, 12 Oct 2023 17:48:49 +0200 Subject: [PATCH 51/83] fix(config): make lazyvim.json idempotent, pretty-printed and remove full paths --- lua/lazyvim/config/init.lua | 9 +++++-- lua/lazyvim/util/init.lua | 1 + lua/lazyvim/util/json.lua | 48 +++++++++++++++++++++++++++++++++++++ lua/lazyvim/util/news.lua | 5 ++-- 4 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 lua/lazyvim/util/json.lua diff --git a/lua/lazyvim/config/init.lua b/lua/lazyvim/config/init.lua index 07bb1ed6..4a9a0f22 100644 --- a/lua/lazyvim/config/init.lua +++ b/lua/lazyvim/config/init.lua @@ -130,7 +130,7 @@ local defaults = { M.json = { data = { version = nil, ---@type string? - hashes = {}, ---@type table + news = {}, ---@type table extras = {}, ---@type string[] }, } @@ -144,6 +144,11 @@ function M.json.load() local ok, json = pcall(vim.json.decode, data, { luanil = { object = true, array = true } }) if ok then M.json.data = vim.tbl_deep_extend("force", M.json.data, json or {}) + if M.json.data.hashes then + ---@diagnostic disable-next-line: no-unknown + M.json.data.hashes = nil + M.json.save() + end end end end @@ -152,7 +157,7 @@ function M.json.save() local path = vim.fn.stdpath("config") .. "/lazyvim.json" local f = io.open(path, "w") if f then - f:write(vim.json.encode(M.json.data)) + f:write(Util.json.encode(M.json.data)) f:close() end end diff --git a/lua/lazyvim/util/init.lua b/lua/lazyvim/util/init.lua index 2751e8e6..ac2b4055 100644 --- a/lua/lazyvim/util/init.lua +++ b/lua/lazyvim/util/init.lua @@ -12,6 +12,7 @@ local LazyUtil = require("lazy.core.util") ---@field extras lazyvim.util.extras ---@field inject lazyvim.util.inject ---@field news lazyvim.util.news +---@field json lazyvim.util.json local M = {} ---@type table diff --git a/lua/lazyvim/util/json.lua b/lua/lazyvim/util/json.lua new file mode 100644 index 00000000..73c4fb15 --- /dev/null +++ b/lua/lazyvim/util/json.lua @@ -0,0 +1,48 @@ +local Util = require("lazyvim.util") + +---@class lazyvim.util.json +local M = {} + +---@param value any +---@param indent string +local function encode(value, indent) + local t = type(value) + + if t == "string" then + return string.format("%q", value) + elseif t == "number" or t == "boolean" then + return tostring(value) + elseif t == "table" then + local is_list = Util.is_list(value) + local parts = {} + local next_indent = indent .. " " + + if is_list then + ---@diagnostic disable-next-line: no-unknown + for _, v in ipairs(value) do + local e = encode(v, next_indent) + if e then + table.insert(parts, next_indent .. e) + end + end + return "[\n" .. table.concat(parts, ",\n") .. "\n" .. indent .. "]" + else + local keys = vim.tbl_keys(value) + table.sort(keys) + ---@diagnostic disable-next-line: no-unknown + for _, k in ipairs(keys) do + local e = encode(value[k], next_indent) + if e then + table.insert(parts, next_indent .. string.format("%q", k) .. ": " .. e) + end + end + return "{\n" .. table.concat(parts, ",\n") .. "\n" .. indent .. "}" + end + end +end + +function M.encode(value) + return encode(value, "") +end + +return M diff --git a/lua/lazyvim/util/news.lua b/lua/lazyvim/util/news.lua index 4e28148b..a4517bf5 100644 --- a/lua/lazyvim/util/news.lua +++ b/lua/lazyvim/util/news.lua @@ -38,6 +38,7 @@ end ---@param file string ---@param opts? {plugin?:string, rtp?:boolean, when_changed?:boolean} function M.open(file, opts) + local ref = file opts = opts or {} if opts.plugin then local plugin = require("lazy.core.config").plugins[opts.plugin] --[[@as LazyPlugin?]] @@ -55,10 +56,10 @@ function M.open(file, opts) if opts.when_changed then local hash = M.hash(file) - if hash == Config.json.data.hashes[file] then + if hash == Config.json.data.news[ref] then return end - Config.json.data.hashes[file] = hash + Config.json.data.news[ref] = hash Config.json.save() end From 7c7b4be8dbec5c5e888d02ebdaae944fecf99407 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Thu, 12 Oct 2023 17:59:48 +0200 Subject: [PATCH 52/83] fix(toggle): dont show incorrect deprecation warning for toggle. Fixes #1679 --- lua/lazyvim/util/init.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/lua/lazyvim/util/init.lua b/lua/lazyvim/util/init.lua index ac2b4055..ddfa55f8 100644 --- a/lua/lazyvim/util/init.lua +++ b/lua/lazyvim/util/init.lua @@ -23,7 +23,6 @@ local deprecated = { root_patterns = { "root", "patterns" }, get_root = { "root", "get" }, float_term = { "terminal", "open" }, - toggle = { "toggle", "option" }, toggle_diagnostics = { "toggle", "diagnostics" }, toggle_number = { "toggle", "number" }, fg = "ui", From 666a69e6e0eb3db17810a426b884081d1cc4ad3d Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 12 Oct 2023 18:07:04 +0200 Subject: [PATCH 53/83] chore(main): release 10.0.1 (#1680) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- CHANGELOG.md | 8 ++++++++ lua/lazyvim/config/init.lua | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1161066d..318e04e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## [10.0.1](https://github.com/LazyVim/LazyVim/compare/v10.0.0...v10.0.1) (2023-10-12) + + +### Bug Fixes + +* **config:** make lazyvim.json idempotent, pretty-printed and remove full paths ([2a0b7a8](https://github.com/LazyVim/LazyVim/commit/2a0b7a88ba4b4562361dd5abb4a071547d004e59)) +* **toggle:** dont show incorrect deprecation warning for toggle. Fixes [#1679](https://github.com/LazyVim/LazyVim/issues/1679) ([7c7b4be](https://github.com/LazyVim/LazyVim/commit/7c7b4be8dbec5c5e888d02ebdaae944fecf99407)) + ## [10.0.0](https://github.com/LazyVim/LazyVim/compare/v9.9.1...v10.0.0) (2023-10-12) diff --git a/lua/lazyvim/config/init.lua b/lua/lazyvim/config/init.lua index 4a9a0f22..3f84e91a 100644 --- a/lua/lazyvim/config/init.lua +++ b/lua/lazyvim/config/init.lua @@ -3,7 +3,7 @@ local Util = require("lazyvim.util") ---@class LazyVimConfig: LazyVimOptions local M = {} -M.version = "10.0.0" -- x-release-please-version +M.version = "10.0.1" -- x-release-please-version ---@class LazyVimOptions local defaults = { From cdae38ddd44edbf5e124129fc94e9d1038592760 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Thu, 12 Oct 2023 20:28:56 +0200 Subject: [PATCH 54/83] fix(nvim-lint): check on linter name instead of linter. Fixes #1685 --- lua/lazyvim/plugins/linting.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/lazyvim/plugins/linting.lua b/lua/lazyvim/plugins/linting.lua index 1fb7ab5d..52ff9bee 100644 --- a/lua/lazyvim/plugins/linting.lua +++ b/lua/lazyvim/plugins/linting.lua @@ -27,7 +27,7 @@ return { local lint = require("lint") for name, linter in pairs(opts.linters) do - if type(linter) == "table" and type(lint.linters) == "table" then + if type(linter) == "table" and type(lint.linters[name]) == "table" then lint.linters[name] = vim.tbl_deep_extend("force", lint.linters[name], linter) end end From 8e71968c2bd9e59e535cdac0a99e667f8f120322 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Thu, 12 Oct 2023 20:43:11 +0200 Subject: [PATCH 55/83] fix(nvim-lint): make sure to set custom linters. Fixes #1687 --- lua/lazyvim/plugins/linting.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lua/lazyvim/plugins/linting.lua b/lua/lazyvim/plugins/linting.lua index 52ff9bee..db9fe9c3 100644 --- a/lua/lazyvim/plugins/linting.lua +++ b/lua/lazyvim/plugins/linting.lua @@ -29,6 +29,8 @@ return { for name, linter in pairs(opts.linters) do if type(linter) == "table" and type(lint.linters[name]) == "table" then lint.linters[name] = vim.tbl_deep_extend("force", lint.linters[name], linter) + else + lint.linters[name] = linter end end lint.linters_by_ft = opts.linters_by_ft From c9892652d271663f52edd7b0d88d2565d8f65a52 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Thu, 12 Oct 2023 21:45:32 +0200 Subject: [PATCH 56/83] feat(config): `lazyvim.json` is now versioned and migrates to a newer version when needed --- lua/lazyvim/config/init.lua | 16 +++------------- lua/lazyvim/util/json.lua | 30 ++++++++++++++++++++++++++++++ lua/lazyvim/util/news.lua | 2 +- 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/lua/lazyvim/config/init.lua b/lua/lazyvim/config/init.lua index 3f84e91a..69561c1d 100644 --- a/lua/lazyvim/config/init.lua +++ b/lua/lazyvim/config/init.lua @@ -128,6 +128,7 @@ local defaults = { } M.json = { + version = 1, data = { version = nil, ---@type string? news = {}, ---@type table @@ -144,24 +145,13 @@ function M.json.load() local ok, json = pcall(vim.json.decode, data, { luanil = { object = true, array = true } }) if ok then M.json.data = vim.tbl_deep_extend("force", M.json.data, json or {}) - if M.json.data.hashes then - ---@diagnostic disable-next-line: no-unknown - M.json.data.hashes = nil - M.json.save() + if M.json.data.version ~= M.json.version then + Util.json.migrate() end end end end -function M.json.save() - local path = vim.fn.stdpath("config") .. "/lazyvim.json" - local f = io.open(path, "w") - if f then - f:write(Util.json.encode(M.json.data)) - f:close() - end -end - ---@type LazyVimOptions local options diff --git a/lua/lazyvim/util/json.lua b/lua/lazyvim/util/json.lua index 73c4fb15..b8428add 100644 --- a/lua/lazyvim/util/json.lua +++ b/lua/lazyvim/util/json.lua @@ -1,3 +1,4 @@ +local Config = require("lazyvim.config") local Util = require("lazyvim.util") ---@class lazyvim.util.json @@ -45,4 +46,33 @@ function M.encode(value) return encode(value, "") end +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:close() + end +end + +function M.migrate() + Util.info("Migrating `lazyvim.json` to version `" .. Config.json.version .. "`") + local json = Config.json + + -- v0 + if not json.data.version then + if json.data.hashes then + ---@diagnostic disable-next-line: no-unknown + json.data.hashes = nil + end + json.data.extras = vim.tbl_map(function(extra) + return "lazyvim.plugins.extras." .. extra + end, json.data.extras or {}) + end + + json.data.version = Config.json.version + + M.save() +end + return M diff --git a/lua/lazyvim/util/news.lua b/lua/lazyvim/util/news.lua index a4517bf5..11707155 100644 --- a/lua/lazyvim/util/news.lua +++ b/lua/lazyvim/util/news.lua @@ -60,7 +60,7 @@ function M.open(file, opts) return end Config.json.data.news[ref] = hash - Config.json.save() + Util.json.save() end local float = require("lazy.util").float({ From 1bcf6b9a282bc839d4fde92a94b800185ad58118 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Thu, 12 Oct 2023 21:47:31 +0200 Subject: [PATCH 57/83] feat(extras): LazyExtras can now manage user extras `lua/plugins/extras`. Fixes #1681 --- NEWS.md | 3 + lua/lazyvim/plugins/xtras.lua | 10 ++-- lua/lazyvim/util/extras.lua | 102 ++++++++++++++++++++++------------ 3 files changed, 74 insertions(+), 41 deletions(-) diff --git a/NEWS.md b/NEWS.md index af6fca2f..50b72da3 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,9 @@ ## 10.x +- User extras under `lua/plugins/extras` can now also be managed + with **LazyExtras** + - `nvim-ts-autotag` is now included by default - `nvim-treesitter-context` is now included by default diff --git a/lua/lazyvim/plugins/xtras.lua b/lua/lazyvim/plugins/xtras.lua index 009bb6fa..4eb73804 100644 --- a/lua/lazyvim/plugins/xtras.lua +++ b/lua/lazyvim/plugins/xtras.lua @@ -2,10 +2,10 @@ local Config = require("lazyvim.config") -- Some extras need to be loaded before others local prios = { - ["editor.aerial"] = 100, - ["editor.symbols-outline"] = 100, - ["test.core"] = 1, - ["dap.core"] = 1, + ["lazyvim.plugins.extras.editor.aerial"] = 100, + ["lazyvim.plugins.extras.editor.symbols-outline"] = 100, + ["lazyvim.plugins.extras.test.core"] = 1, + ["lazyvim.plugins.extras.dap.core"] = 1, } table.sort(Config.json.data.extras, function(a, b) @@ -19,5 +19,5 @@ end) ---@param extra string return vim.tbl_map(function(extra) - return { import = "lazyvim.plugins.extras." .. extra } + return { import = extra } end, Config.json.data.extras) diff --git a/lua/lazyvim/util/extras.lua b/lua/lazyvim/util/extras.lua index c71e328c..0417b81e 100644 --- a/lua/lazyvim/util/extras.lua +++ b/lua/lazyvim/util/extras.lua @@ -5,8 +5,16 @@ local Plugin = require("lazy.core.plugin") local Text = require("lazy.view.text") local Util = require("lazyvim.util") +---@class LazyExtraSource +---@field name string +---@field desc? string +---@field module string + ---@class LazyExtra ---@field name string +---@field source LazyExtraSource +---@field module string +---@field desc? string ---@field enabled boolean ---@field managed boolean ---@field row? number @@ -16,6 +24,12 @@ local Util = require("lazyvim.util") ---@class lazyvim.util.extras local M = {} +---@type LazyExtraSource[] +M.sources = { + { name = "LazyVim", desc = "LazyVim extras", module = "lazyvim.plugins.extras" }, + { name = "User", desc = "User extras", module = "plugins.extras" }, +} + M.ns = vim.api.nvim_create_namespace("lazyvim.extras") ---@type string[] M.state = nil @@ -23,42 +37,52 @@ M.state = nil ---@return LazyExtra[] function M.get() M.state = M.state or LazyConfig.spec.modules - local root = LazyConfig.plugins.LazyVim.dir .. "/lua/lazyvim/plugins/extras" - local extras = {} ---@type string[] - - Util.walk(root, function(path, name, type) - if type == "file" and name:match("%.lua$") then - local extra = path:sub(#root + 2, -5):gsub("/", ".") - extras[#extras + 1] = extra + local extras = {} ---@type LazyExtra[] + for _, source in ipairs(M.sources) do + local root = Util.find_root(source.module) + if root then + Util.walk(root, function(path, name, type) + if type == "file" and name:match("%.lua$") then + name = path:sub(#root + 2, -5):gsub("/", ".") + extras[#extras + 1] = M.get_extra(source, source.module .. "." .. name) + end + end) end + end + table.sort(extras, function(a, b) + return a.name < b.name end) - table.sort(extras) + return extras +end - ---@param extra string - return vim.tbl_map(function(extra) - local modname = "lazyvim.plugins.extras." .. extra - local enabled = vim.tbl_contains(M.state, modname) - local spec = Plugin.Spec.new({ import = "lazyvim.plugins.extras." .. extra }, { optional = true }) - local plugins = {} ---@type string[] - local optional = {} ---@type string[] - for _, p in pairs(spec.plugins) do - if p.optional then - optional[#optional + 1] = p.name - else - plugins[#plugins + 1] = p.name - end +---@param modname string +---@param source LazyExtraSource +function M.get_extra(source, modname) + local enabled = vim.tbl_contains(M.state, modname) + local spec = Plugin.Spec.new({ import = modname }, { optional = true }) + local plugins = {} ---@type string[] + local optional = {} ---@type string[] + for _, p in pairs(spec.plugins) do + if p.optional then + optional[#optional + 1] = p.name + else + plugins[#plugins + 1] = p.name end - table.sort(plugins) - table.sort(optional) + end + table.sort(plugins) + table.sort(optional) - return { - name = extra, - enabled = enabled, - managed = vim.tbl_contains(Config.json.data.extras, extra) or not enabled, - plugins = plugins, - optional = optional, - } - end, extras) + ---@type LazyExtra + return { + source = source, + name = modname:sub(#source.module + 2), + module = modname, + enabled = enabled, + desc = require(modname).desc, + managed = vim.tbl_contains(Config.json.data.extras, modname) or not enabled, + plugins = plugins, + optional = optional, + } end ---@class LazyExtraView @@ -100,17 +124,17 @@ function X:toggle() end extra.enabled = not extra.enabled Config.json.data.extras = vim.tbl_filter(function(name) - return name ~= extra.name + return name ~= extra.module end, Config.json.data.extras) M.state = vim.tbl_filter(function(name) - return name ~= "lazyvim.plugins.extras." .. extra.name + return name ~= extra.module end, M.state) if extra.enabled then - table.insert(Config.json.data.extras, extra.name) - M.state[#M.state + 1] = "lazyvim.plugins.extras." .. extra.name + table.insert(Config.json.data.extras, extra.module) + M.state[#M.state + 1] = extra.module end table.sort(Config.json.data.extras) - Config.json.save() + Util.json.save() Util.info( "`" .. extra.name @@ -180,12 +204,18 @@ function X:extra(extra) self.text:append(" " .. LazyConfig.options.ui.icons.not_loaded .. " ", hl) end self.text:append(extra.name) + if extra.source.name ~= "LazyVim" then + self.text:append(" "):append(LazyConfig.options.ui.icons.event .. " " .. extra.source.name, "LazyReasonEvent") + end for _, plugin in ipairs(extra.plugins) do self.text:append(" "):append(LazyConfig.options.ui.icons.plugin .. "" .. plugin, "LazyReasonPlugin") end for _, plugin in ipairs(extra.optional) do self.text:append(" "):append(LazyConfig.options.ui.icons.plugin .. "" .. plugin, "LazyReasonRequire") end + if extra.desc then + self.text:nl():append(" " .. extra.desc, "LazyComment") + end self.text:nl() end From b31d71da9d6ca6c290a8ee7e7cc7ad5ccb3cc0bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ph=C3=BAc=20H=2E=20L=C3=AA=20Kh=E1=BA=AFc?= Date: Thu, 12 Oct 2023 21:52:19 +0200 Subject: [PATCH 58/83] feat(neot-ree): add keymaps to toggle git & buffer (#1339) --- lua/lazyvim/plugins/editor.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lua/lazyvim/plugins/editor.lua b/lua/lazyvim/plugins/editor.lua index 6e1d63b6..63a8e1b1 100644 --- a/lua/lazyvim/plugins/editor.lua +++ b/lua/lazyvim/plugins/editor.lua @@ -24,6 +24,20 @@ return { }, { "e", "fe", desc = "Explorer NeoTree (root dir)", remap = true }, { "E", "fE", desc = "Explorer NeoTree (cwd)", remap = true }, + { + "ge", + function() + require("neo-tree.command").execute({ source = "git_status", toggle = true }) + end, + desc = "Git explorer", + }, + { + "be", + function() + require("neo-tree.command").execute({ source = "buffers", toggle = true }) + end, + desc = "Buffer explorer", + }, }, deactivate = function() vim.cmd([[Neotree close]]) From 1e7924878693be1570c91811fd5c55bb53c8c4d0 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 12 Oct 2023 21:56:56 +0200 Subject: [PATCH 59/83] chore(main): release 10.1.0 (#1686) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- CHANGELOG.md | 15 +++++++++++++++ lua/lazyvim/config/init.lua | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 318e04e5..1639dea3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,20 @@ # Changelog +## [10.1.0](https://github.com/LazyVim/LazyVim/compare/v10.0.1...v10.1.0) (2023-10-12) + + +### Features + +* **config:** `lazyvim.json` is now versioned and migrates to a newer version when needed ([c989265](https://github.com/LazyVim/LazyVim/commit/c9892652d271663f52edd7b0d88d2565d8f65a52)) +* **extras:** LazyExtras can now manage user extras `lua/plugins/extras`. Fixes [#1681](https://github.com/LazyVim/LazyVim/issues/1681) ([1bcf6b9](https://github.com/LazyVim/LazyVim/commit/1bcf6b9a282bc839d4fde92a94b800185ad58118)) +* **neot-ree:** add keymaps to toggle git & buffer ([#1339](https://github.com/LazyVim/LazyVim/issues/1339)) ([b31d71d](https://github.com/LazyVim/LazyVim/commit/b31d71da9d6ca6c290a8ee7e7cc7ad5ccb3cc0bd)) + + +### Bug Fixes + +* **nvim-lint:** check on linter name instead of linter. Fixes [#1685](https://github.com/LazyVim/LazyVim/issues/1685) ([cdae38d](https://github.com/LazyVim/LazyVim/commit/cdae38ddd44edbf5e124129fc94e9d1038592760)) +* **nvim-lint:** make sure to set custom linters. Fixes [#1687](https://github.com/LazyVim/LazyVim/issues/1687) ([8e71968](https://github.com/LazyVim/LazyVim/commit/8e71968c2bd9e59e535cdac0a99e667f8f120322)) + ## [10.0.1](https://github.com/LazyVim/LazyVim/compare/v10.0.0...v10.0.1) (2023-10-12) diff --git a/lua/lazyvim/config/init.lua b/lua/lazyvim/config/init.lua index 69561c1d..774cb7ca 100644 --- a/lua/lazyvim/config/init.lua +++ b/lua/lazyvim/config/init.lua @@ -3,7 +3,7 @@ local Util = require("lazyvim.util") ---@class LazyVimConfig: LazyVimOptions local M = {} -M.version = "10.0.1" -- x-release-please-version +M.version = "10.1.0" -- x-release-please-version ---@class LazyVimOptions local defaults = { From bd1928ba597d777ca79f9f2f4b14217de4c291bc Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Fri, 13 Oct 2023 07:28:02 +0200 Subject: [PATCH 60/83] fix(aerial): use new sep_icon option for aerial lualine component --- lua/lazyvim/plugins/extras/editor/aerial.lua | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/lua/lazyvim/plugins/extras/editor/aerial.lua b/lua/lazyvim/plugins/extras/editor/aerial.lua index d46149b1..440c9fda 100644 --- a/lua/lazyvim/plugins/extras/editor/aerial.lua +++ b/lua/lazyvim/plugins/extras/editor/aerial.lua @@ -2,22 +2,11 @@ local Config = require("lazyvim.config") local Util = require("lazyvim.util") return { + desc = "Aerial Symbol Browser", { "stevearc/aerial.nvim", event = "LazyFile", opts = function() - ---@diagnostic disable-next-line: no-unknown - local lualine = require("lualine.components.aerial") - - -- Strip trailing spaces from symbols in statusline - ---@param _ any - ---@param symbols {icon?:string}[] - lualine.format_status = Util.inject.args(lualine.format_status, function(_, symbols) - for _, s in ipairs(symbols) do - s.icon = s.icon and s.icon:gsub("%s*$", "") or nil - end - end) - local icons = vim.deepcopy(Config.icons.kinds) -- HACK: fix lua's weird choice for `Package` for control @@ -110,8 +99,8 @@ return { opts = function(_, opts) table.insert(opts.sections.lualine_c, { "aerial", - -- The separator to be used to separate symbols in status line. - sep = " ", + sep = " ", -- separator between symbols + sep_icon = "", -- separator between icon and symbol -- The number of symbols to render top-down. In order to render only 'N' last -- symbols, negative numbers may be supplied. For instance, 'depth = -1' can From 01dbd070738a9448ffbdc63602ed9eb5421158da Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Fri, 13 Oct 2023 07:35:24 +0200 Subject: [PATCH 61/83] fix(json): always write version to prevent spurious migrations. Fixes #1692 --- lua/lazyvim/config/init.lua | 2 +- lua/lazyvim/util/json.lua | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lua/lazyvim/config/init.lua b/lua/lazyvim/config/init.lua index 774cb7ca..af31f163 100644 --- a/lua/lazyvim/config/init.lua +++ b/lua/lazyvim/config/init.lua @@ -128,7 +128,7 @@ local defaults = { } M.json = { - version = 1, + version = 2, data = { version = nil, ---@type string? news = {}, ---@type table diff --git a/lua/lazyvim/util/json.lua b/lua/lazyvim/util/json.lua index b8428add..d98d0382 100644 --- a/lua/lazyvim/util/json.lua +++ b/lua/lazyvim/util/json.lua @@ -47,6 +47,7 @@ function M.encode(value) end function M.save() + Config.json.data.version = Config.json.version local path = vim.fn.stdpath("config") .. "/lazyvim.json" local f = io.open(path, "w") if f then @@ -68,10 +69,13 @@ function M.migrate() json.data.extras = vim.tbl_map(function(extra) return "lazyvim.plugins.extras." .. extra end, json.data.extras or {}) + elseif json.data.version == 1 then + json.data.extras = vim.tbl_map(function(extra) + -- replace double extras module name + return extra:gsub("^lazyvim%.plugins%.extras%.lazyvim%.plugins%.extras%.", "lazyvim.plugins.extras.") + end, json.data.extras or {}) end - json.data.version = Config.json.version - M.save() end From 66f0d55beb6604abc07110edbfc483f69660625b Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 13 Oct 2023 05:36:45 +0000 Subject: [PATCH 62/83] chore(build): auto-generate vimdoc --- doc/LazyVim.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/LazyVim.txt b/doc/LazyVim.txt index ea9ed565..49d339b6 100644 --- a/doc/LazyVim.txt +++ b/doc/LazyVim.txt @@ -1,4 +1,4 @@ -*LazyVim.txt* For Neovim >= 0.8.0 Last change: 2023 October 12 +*LazyVim.txt* For Neovim >= 0.8.0 Last change: 2023 October 13 ============================================================================== Table of Contents *LazyVim-table-of-contents* From 1b1d9a16ee96b73090ca1906204c41550f6528e6 Mon Sep 17 00:00:00 2001 From: Susheel Thapa <83917129+SusheelThapa@users.noreply.github.com> Date: Fri, 13 Oct 2023 11:22:07 +0545 Subject: [PATCH 63/83] docs: typos fixed in CHANGELOG.md (#1693) --- CHANGELOG.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1639dea3..4573b18d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -259,7 +259,7 @@ ### Bug Fixes -* **dasboard:** disable alpha only once ([d6b56c0](https://github.com/LazyVim/LazyVim/commit/d6b56c075e88ce12e9e16fb2eeeea38fb7853600)) +* **dashboard:** disable alpha only once ([d6b56c0](https://github.com/LazyVim/LazyVim/commit/d6b56c075e88ce12e9e16fb2eeeea38fb7853600)) * **options:** set default laststatus=3 and set it to 0 before loading dashboard to prevent flickering ([1eb0192](https://github.com/LazyVim/LazyVim/commit/1eb019274b5564e66ac6c7e119c140bae262e10c)) * **tailwind:** allow overriding filetypes. Fixes [#1590](https://github.com/LazyVim/LazyVim/issues/1590) ([d3e7f77](https://github.com/LazyVim/LazyVim/commit/d3e7f7717e960bb883b35e9a75badfd5b938cace)) @@ -300,7 +300,7 @@ ### Bug Fixes -* **autocmds:** retore last location for correct buffer ([afc8e7f](https://github.com/LazyVim/LazyVim/commit/afc8e7f8cac06335efd12ec5f71cabb1f38a09b0)) +* **autocmds:** restore last location for correct buffer ([afc8e7f](https://github.com/LazyVim/LazyVim/commit/afc8e7f8cac06335efd12ec5f71cabb1f38a09b0)) * **conform:** dont try merging function formatters. Fixes [#1582](https://github.com/LazyVim/LazyVim/issues/1582) ([f475085](https://github.com/LazyVim/LazyVim/commit/f4750859f2c2c9a41b3974ac05962ce9648d6c16)) * **conform:** dont try to merge formatter functions ([9f034ab](https://github.com/LazyVim/LazyVim/commit/9f034ab10650e306e178d5189ee9214a52f2e8e5)) * **nvim-lint:** dont try merging function linters ([79010ae](https://github.com/LazyVim/LazyVim/commit/79010ae671035d8ed0040ce51df4fb59ec3962f8)) @@ -1023,7 +1023,7 @@ * **hipatterns:** default options ([3082436](https://github.com/LazyVim/LazyVim/commit/30824369c2c58647df170566766ea1dbda2730cc)) * **neotest:** added some additional filetypes to close with q ([1288f0d](https://github.com/LazyVim/LazyVim/commit/1288f0d5a5cc5f5279678cc3c3d99abe20a1e052)) -* **neotest:** support neotest adapaters that use `setup()` for custom setup ([2a3bac7](https://github.com/LazyVim/LazyVim/commit/2a3bac769045abac76395fcabb36b17b68bc42fc)) +* **neotest:** support neotest adapters that use `setup()` for custom setup ([2a3bac7](https://github.com/LazyVim/LazyVim/commit/2a3bac769045abac76395fcabb36b17b68bc42fc)) ## [4.2.0](https://github.com/LazyVim/LazyVim/compare/v4.1.1...v4.2.0) (2023-05-26) @@ -1630,7 +1630,7 @@ ### Bug Fixes -* **illuminate:** always set refernce keymaps on the buffer as well to properly overwrite ftplugin mappings. Fixes [#292](https://github.com/LazyVim/LazyVim/issues/292) ([a0cf00c](https://github.com/LazyVim/LazyVim/commit/a0cf00c81b3a4a352cdc26c94112d9a5827881e1)) +* **illuminate:** always set reference keymaps on the buffer as well to properly overwrite ftplugin mappings. Fixes [#292](https://github.com/LazyVim/LazyVim/issues/292) ([a0cf00c](https://github.com/LazyVim/LazyVim/commit/a0cf00c81b3a4a352cdc26c94112d9a5827881e1)) * **mini.surround:** don't create empty keymaps. Fixes [#296](https://github.com/LazyVim/LazyVim/issues/296) ([8e84dcf](https://github.com/LazyVim/LazyVim/commit/8e84dcf85c8a73ebcf6ade6b7b77544f468f1dfa)) * **treesitter:** disable indent only for python right now ([de6a28b](https://github.com/LazyVim/LazyVim/commit/de6a28b781e8a06e4f70c913539c97260392131a)) * **treesitter:** disable treesitter indent by default, since it has too many issues. See [#297](https://github.com/LazyVim/LazyVim/issues/297) ([329a2da](https://github.com/LazyVim/LazyVim/commit/329a2daff493abd2bd5c8fedbf0dfa13039d3931)) @@ -1774,7 +1774,7 @@ ### Bug Fixes -* **mini.ai:** load ai on VeryLazy. Keymaps interfer with which-key. [#155](https://github.com/LazyVim/LazyVim/issues/155) ([3b5f363](https://github.com/LazyVim/LazyVim/commit/3b5f36307438ad05beae6796ca005f6b56d6a360)) +* **mini.ai:** load ai on VeryLazy. Keymaps interfere with which-key. [#155](https://github.com/LazyVim/LazyVim/issues/155) ([3b5f363](https://github.com/LazyVim/LazyVim/commit/3b5f36307438ad05beae6796ca005f6b56d6a360)) * **noice:** scroll doc window in normal, insert and select mode ([c5b22c0](https://github.com/LazyVim/LazyVim/commit/c5b22c0832603198f571ff68b6fb9d0c17f73d33)) * **nvim-navic:** use kinds icons for navic. Fixes [#164](https://github.com/LazyVim/LazyVim/issues/164) ([b81ecf9](https://github.com/LazyVim/LazyVim/commit/b81ecf9f7ac78e3f87a4d9b305fa0d3cfd6decf2)) @@ -1949,7 +1949,7 @@ * **lsp:** allow overriding options for vim.lsp.buf.format. Fixes [#51](https://github.com/LazyVim/LazyVim/issues/51) ([40d363c](https://github.com/LazyVim/LazyVim/commit/40d363cf3f468a1cc4ea482eaabbd5c7e224f397)) * **lsp:** make diagnostics configurable with `{"neovim/nvim-lspconfig", opts = {diagnostics = {}}}`. Fixes [#55](https://github.com/LazyVim/LazyVim/issues/55) ([1efc925](https://github.com/LazyVim/LazyVim/commit/1efc925d16b57659cbb9af5a1579cb1b9ee9643f)) * **neo-tree:** added `<leader>e` and `E` to toggle neo-tree ([542920f](https://github.com/LazyVim/LazyVim/commit/542920fb8249d45d1e9ddbf6517a8f8539769eda)) -* **neo-tree:** load neo-tree when specifying a direcory on the cmdline ([81d798f](https://github.com/LazyVim/LazyVim/commit/81d798fdaa5bf49737969e0f15af4a90621a0a61)) +* **neo-tree:** load neo-tree when specifying a directory on the cmdline ([81d798f](https://github.com/LazyVim/LazyVim/commit/81d798fdaa5bf49737969e0f15af4a90621a0a61)) * **notify:** delay notifs till replaced or at most 500ms to prevent more prompts ([701337f](https://github.com/LazyVim/LazyVim/commit/701337fac8cb1de0f3e31400cef30b053762320f)) * **notify:** lazy-load nvim-notify to show proper notifs before Noice loads ([7406313](https://github.com/LazyVim/LazyVim/commit/74063135d838b0ed9fe1a8d0e777c8cfe83ae28f)) * **util:** use lazy's notify instead of `vim.notify` ([48d1e8d](https://github.com/LazyVim/LazyVim/commit/48d1e8df12795cf559f704223b63e76259998582)) From ea4174d46016dd191de48c03bdf23462483f9f6a Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 13 Oct 2023 07:39:24 +0200 Subject: [PATCH 64/83] chore(main): release 10.1.1 (#1694) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- CHANGELOG.md | 8 ++++++++ lua/lazyvim/config/init.lua | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4573b18d..80f25f8e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## [10.1.1](https://github.com/LazyVim/LazyVim/compare/v10.1.0...v10.1.1) (2023-10-13) + + +### Bug Fixes + +* **aerial:** use new sep_icon option for aerial lualine component ([bd1928b](https://github.com/LazyVim/LazyVim/commit/bd1928ba597d777ca79f9f2f4b14217de4c291bc)) +* **json:** always write version to prevent spurious migrations. Fixes [#1692](https://github.com/LazyVim/LazyVim/issues/1692) ([01dbd07](https://github.com/LazyVim/LazyVim/commit/01dbd070738a9448ffbdc63602ed9eb5421158da)) + ## [10.1.0](https://github.com/LazyVim/LazyVim/compare/v10.0.1...v10.1.0) (2023-10-12) diff --git a/lua/lazyvim/config/init.lua b/lua/lazyvim/config/init.lua index af31f163..4a5abf17 100644 --- a/lua/lazyvim/config/init.lua +++ b/lua/lazyvim/config/init.lua @@ -3,7 +3,7 @@ local Util = require("lazyvim.util") ---@class LazyVimConfig: LazyVimOptions local M = {} -M.version = "10.1.0" -- x-release-please-version +M.version = "10.1.1" -- x-release-please-version ---@class LazyVimOptions local defaults = { From 4584410e76bf8a6ba426270bef8eca5a100d4cce Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Fri, 13 Oct 2023 09:45:35 +0200 Subject: [PATCH 65/83] feat(format): use conform as lsp formatter since it has better format diffs --- lua/lazyvim/util/lsp.lua | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lua/lazyvim/util/lsp.lua b/lua/lazyvim/util/lsp.lua index d5903cd8..7060c7a5 100644 --- a/lua/lazyvim/util/lsp.lua +++ b/lua/lazyvim/util/lsp.lua @@ -104,9 +104,17 @@ end ---@param opts? {filter?: lsp.Client.filter, bufnr?: number} function M.format(opts) - vim.lsp.buf.format( - vim.tbl_deep_extend("force", opts or {}, require("lazyvim.util").opts("nvim-lspconfig").format or {}) - ) + opts = vim.tbl_deep_extend("force", {}, opts or {}, require("lazyvim.util").opts("nvim-lspconfig").format or {}) + local ok, conform = pcall(require, "conform") + -- use conform for formatting with LSP when available, + -- since it has better format diffing + if ok then + opts.formatters = {} + opts.lsp_fallback = true + conform.format(opts) + else + vim.lsp.buf.format(opts) + end end return M From 3f1bf70b144f098f427b47d44d42d87945778328 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Fri, 13 Oct 2023 12:20:55 +0200 Subject: [PATCH 66/83] refactor(util.lsp): easier lsp client filters --- lua/lazyvim/util/lsp.lua | 59 ++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/lua/lazyvim/util/lsp.lua b/lua/lazyvim/util/lsp.lua index 7060c7a5..b34a2afe 100644 --- a/lua/lazyvim/util/lsp.lua +++ b/lua/lazyvim/util/lsp.lua @@ -1,10 +1,26 @@ +local Util = require("lazyvim.util") + ---@class lazyvim.util.lsp local M = {} -function M.get_clients(...) - ---@diagnostic disable-next-line: deprecated - local fn = vim.lsp.get_clients or vim.lsp.get_active_clients - return fn(...) +---@alias lsp.Client.filter {id?: number, bufnr?: number, name?: string, method?: string, filter?:fun(client: lsp.Client):boolean} + +---@param opts? lsp.Client.filter +function M.get_clients(opts) + local ret = {} ---@type lsp.Client[] + if vim.lsp.get_clients then + ret = vim.lsp.get_clients(opts) + else + ---@diagnostic disable-next-line: deprecated + ret = vim.lsp.get_active_clients(opts) + if opts and opts.method then + ---@param client lsp.Client + ret = vim.tbl_filter(function(client) + return client.supports_method(opts.method, { bufnr = opts.bufnr }) + end, ret) + end + end + return opts and opts.filter and vim.tbl_filter(opts.filter, ret) or ret end ---@param on_attach fun(client, buffer) @@ -59,39 +75,26 @@ function M.disable(server, cond) end) end ----@alias lsp.Client.filter fun(client: lsp.Client): boolean - ----@param name string ----@return lsp.Client.filter -function M.filter(name) - return function(client) - return client.name == name - end -end - ----@param opts? LazyFormatter| {filter?: (string|lsp.Client.filter), bufnr?: number} +---@param opts? LazyFormatter| {filter?: (string|lsp.Client.filter)} function M.formatter(opts) opts = opts or {} - local filter = opts.filter - filter = type(filter) == "string" and M.filter(filter) or filter - ---@cast filter lsp.Client.filter? + local filter = opts.filter or {} + filter = type(filter) == "string" and { name = filter } or filter + ---@cast filter lsp.Client.filter ---@type LazyFormatter local ret = { name = "LSP", primary = true, priority = 1, format = function(buf) - M.format({ bufnr = buf, filter = filter }) + M.format(Util.merge(filter, { bufnr = buf })) end, sources = function(buf) - local clients = M.get_clients({ bufnr = buf }) + local clients = M.get_clients(Util.merge(filter, { bufnr = buf })) ---@param client lsp.Client local ret = vim.tbl_filter(function(client) - return (not filter or filter(client)) - and ( - client.supports_method("textDocument/formatting") - or client.supports_method("textDocument/rangeFormatting") - ) + return client.supports_method("textDocument/formatting") + or client.supports_method("textDocument/rangeFormatting") end, clients) ---@param client lsp.Client return vim.tbl_map(function(client) @@ -99,10 +102,12 @@ function M.formatter(opts) end, ret) end, } - return vim.tbl_deep_extend("force", ret, opts) --[[@as LazyFormatter]] + return Util.merge(ret, opts) --[[@as LazyFormatter]] end ----@param opts? {filter?: lsp.Client.filter, bufnr?: number} +---@alias lsp.Client.format {timeout_ms?: number, format_options?: table} | lsp.Client.filter + +---@param opts? lsp.Client.format function M.format(opts) opts = vim.tbl_deep_extend("force", {}, opts or {}, require("lazyvim.util").opts("nvim-lspconfig").format or {}) local ok, conform = pcall(require, "conform") From 6fd66f486e210e35b4c375691fbfd61a611b6027 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Fri, 13 Oct 2023 12:21:38 +0200 Subject: [PATCH 67/83] feat(conform): use conform.nvim `opts.format` options for formatting with conform --- lua/lazyvim/plugins/formatting.lua | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/lua/lazyvim/plugins/formatting.lua b/lua/lazyvim/plugins/formatting.lua index 855e356e..b40245ea 100644 --- a/lua/lazyvim/plugins/formatting.lua +++ b/lua/lazyvim/plugins/formatting.lua @@ -1,3 +1,8 @@ +local Util = require("lazyvim.util") + +---@type ConformOpts +local format_opts = {} + return { { "stevearc/conform.nvim", @@ -23,7 +28,7 @@ return { priority = 100, primary = true, format = function(buf) - require("conform").format({ bufnr = buf }) + require("conform").format(Util.merge(format_opts, { bufnr = buf })) end, sources = function(buf) local ret = require("conform").list_formatters(buf) @@ -34,7 +39,12 @@ return { }) end) end, + ---@class ConformOpts opts = { + -- LazyVim will use these options when formatting with the conform.nvim formatter + format = { + timeout_ms = 1000, + }, formatters_by_ft = { lua = { "stylua" }, fish = { "fish_indent" }, @@ -53,6 +63,7 @@ return { -- }, }, }, + ---@param opts ConformOpts config = function(_, opts) opts.formatters = opts.formatters or {} for name, formatter in pairs(opts.formatters) do @@ -63,6 +74,17 @@ return { end end end + for _, key in ipairs({ "format_on_save", "format_after_save" }) do + if opts[key] then + Util.warn( + ("Don't set `opts.%s` for `conform.nvim`.\n**LazyVim** will use the conform formatter automatically"):format( + key + ) + ) + opts[key] = nil + end + end + format_opts = opts.format require("conform").setup(opts) end, }, From c7244d9d47d617e68fe603a1e45b8701b08cf0ca Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Fri, 13 Oct 2023 12:31:32 +0200 Subject: [PATCH 68/83] style(dot): make enabled a function for doc gen --- lua/lazyvim/plugins/extras/util/dot.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lua/lazyvim/plugins/extras/util/dot.lua b/lua/lazyvim/plugins/extras/util/dot.lua index 6dda53d3..2424589d 100644 --- a/lua/lazyvim/plugins/extras/util/dot.lua +++ b/lua/lazyvim/plugins/extras/util/dot.lua @@ -11,7 +11,9 @@ return { -- Add Hyprland Parser { "luckasRanarison/tree-sitter-hypr", - enabled = have("hypr"), + enabled = function() + return have("hypr") + end, event = "BufRead */hypr/*.conf", build = ":TSUpdate hypr", config = function() From 385c99dbb7ccdcf53276086892cceee65b85fa21 Mon Sep 17 00:00:00 2001 From: Juan Cruz De La Torre Date: Fri, 13 Oct 2023 07:43:51 -0300 Subject: [PATCH 69/83] feat(go): add gofumpt formatter with conform/none-ls (#1683) * feat(go): only install required packages * fix: add gofumpt formatter using conform/none-ls * fix: add mason.nvim as dependency of none-ls --- lua/lazyvim/plugins/extras/lang/go.lua | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/lua/lazyvim/plugins/extras/lang/go.lua b/lua/lazyvim/plugins/extras/lang/go.lua index 7e87678b..aaad0128 100644 --- a/lua/lazyvim/plugins/extras/lang/go.lua +++ b/lua/lazyvim/plugins/extras/lang/go.lua @@ -82,15 +82,32 @@ return { }, }, -- Ensure Go tools are installed + { + "williamboman/mason.nvim", + opts = function(_, opts) + opts.ensure_installed = opts.ensure_installed or {} + vim.list_extend(opts.ensure_installed, { "goimports", "gofumpt" }) + end, + }, { "nvimtools/none-ls.nvim", optional = true, + dependencies = { + { + "williamboman/mason.nvim", + opts = function(_, opts) + opts.ensure_installed = opts.ensure_installed or {} + vim.list_extend(opts.ensure_installed, { "gomodifytags", "impl" }) + end, + }, + }, opts = function(_, opts) local nls = require("null-ls") opts.sources = vim.list_extend(opts.sources or {}, { nls.builtins.code_actions.gomodifytags, nls.builtins.code_actions.impl, nls.builtins.formatting.goimports, + nls.builtins.formatting.gofumpt, }) end, }, @@ -99,7 +116,7 @@ return { optional = true, opts = { formatters_by_ft = { - go = { "goimports" }, + go = { "goimports", "gofumpt" }, }, }, }, @@ -108,10 +125,10 @@ return { optional = true, dependencies = { { - "mason.nvim", + "williamboman/mason.nvim", opts = function(_, opts) opts.ensure_installed = opts.ensure_installed or {} - vim.list_extend(opts.ensure_installed, { "gomodifytags", "impl", "goimports", "delve" }) + vim.list_extend(opts.ensure_installed, { "delve" }) end, }, { From 873ff892843898033be0b59cee8130c6b1b29d85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ph=C3=BAc=20H=2E=20L=C3=AA=20Kh=E1=BA=AFc?= Date: Fri, 13 Oct 2023 16:53:55 +0200 Subject: [PATCH 70/83] fix(keymaps): no diagnostic keymaps w/o lsp attached (#1698) --- lua/lazyvim/config/keymaps.lua | 16 ++++++++++++++++ lua/lazyvim/plugins/lsp/keymaps.lua | 15 --------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/lua/lazyvim/config/keymaps.lua b/lua/lazyvim/config/keymaps.lua index bae7b15b..85517a65 100644 --- a/lua/lazyvim/config/keymaps.lua +++ b/lua/lazyvim/config/keymaps.lua @@ -98,6 +98,22 @@ map({ "n", "v" }, "cf", function() Util.format({ force = true }) end, { desc = "Format" }) +-- diagnostic +local diagnostic_goto = function(next, severity) + local go = next and vim.diagnostic.goto_next or vim.diagnostic.goto_prev + severity = severity and vim.diagnostic.severity[severity] or nil + return function() + go({ severity = severity }) + end +end +map("n", "cd", vim.diagnostic.open_float, { desc = "Line Diagnostics" }) +map("n", "]d", diagnostic_goto(true), { desc = "Next Diagnostic" }) +map("n", "[d", diagnostic_goto(false), { desc = "Prev Diagnostic" }) +map("n", "]e", diagnostic_goto(true, "ERROR"), { desc = "Next Error" }) +map("n", "[e", diagnostic_goto(false, "ERROR"), { desc = "Prev Error" }) +map("n", "]w", diagnostic_goto(true, "WARN"), { desc = "Next Warning" }) +map("n", "[w", diagnostic_goto(false, "WARN"), { desc = "Prev Warning" }) + -- stylua: ignore start -- toggle options diff --git a/lua/lazyvim/plugins/lsp/keymaps.lua b/lua/lazyvim/plugins/lsp/keymaps.lua index 7b9c2189..10e5d86f 100644 --- a/lua/lazyvim/plugins/lsp/keymaps.lua +++ b/lua/lazyvim/plugins/lsp/keymaps.lua @@ -13,7 +13,6 @@ function M.get() end -- stylua: ignore M._keys = { - { "cd", vim.diagnostic.open_float, desc = "Line Diagnostics" }, { "cl", "LspInfo", desc = "Lsp Info" }, { "gd", function() require("telescope.builtin").lsp_definitions({ reuse_win = true }) end, desc = "Goto Definition", has = "definition" }, { "gr", "Telescope lsp_references", desc = "References" }, @@ -23,12 +22,6 @@ function M.get() { "K", vim.lsp.buf.hover, desc = "Hover" }, { "gK", vim.lsp.buf.signature_help, desc = "Signature Help", has = "signatureHelp" }, { "", vim.lsp.buf.signature_help, mode = "i", desc = "Signature Help", has = "signatureHelp" }, - { "]d", M.diagnostic_goto(true), desc = "Next Diagnostic" }, - { "[d", M.diagnostic_goto(false), desc = "Prev Diagnostic" }, - { "]e", M.diagnostic_goto(true, "ERROR"), desc = "Next Error" }, - { "[e", M.diagnostic_goto(false, "ERROR"), desc = "Prev Error" }, - { "]w", M.diagnostic_goto(true, "WARN"), desc = "Next Warning" }, - { "[w", M.diagnostic_goto(false, "WARN"), desc = "Prev Warning" }, { "ca", vim.lsp.buf.code_action, desc = "Code Action", mode = { "n", "v" }, has = "codeAction" }, { "cA", @@ -106,12 +99,4 @@ function M.on_attach(_, buffer) end end -function M.diagnostic_goto(next, severity) - local go = next and vim.diagnostic.goto_next or vim.diagnostic.goto_prev - severity = severity and vim.diagnostic.severity[severity] or nil - return function() - go({ severity = severity }) - end -end - return M From 3eb91c64b5960ccd84bd8e6a3318a1ee79cb85c5 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Fri, 13 Oct 2023 18:03:40 +0200 Subject: [PATCH 71/83] feat(conform): make it easier to add `extra_args` --- lua/lazyvim/plugins/formatting.lua | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lua/lazyvim/plugins/formatting.lua b/lua/lazyvim/plugins/formatting.lua index b40245ea..2053d1a5 100644 --- a/lua/lazyvim/plugins/formatting.lua +++ b/lua/lazyvim/plugins/formatting.lua @@ -61,10 +61,14 @@ return { -- return vim.fs.find({ "dprint.json" }, { path = ctx.filename, upward = true })[1] -- end, -- }, + shfmt = { + extra_args = { "-i", "2", "-ci" }, + }, }, }, ---@param opts ConformOpts config = function(_, opts) + local util = require("conform.util") opts.formatters = opts.formatters or {} for name, formatter in pairs(opts.formatters) do if type(formatter) == "table" then @@ -72,8 +76,13 @@ return { if ok and type(defaults) == "table" then opts.formatters[name] = vim.tbl_deep_extend("force", {}, defaults, formatter) end + if opts.formatters[name].extra_args then + opts.formatters[name].args = + util.extend_args(opts.formatters[name].args or {}, opts.formatters[name].extra_args) + end end end + for _, key in ipairs({ "format_on_save", "format_after_save" }) do if opts[key] then Util.warn( From b6e68fa2bf829753be86ba8cc56baafd47b7da67 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Fri, 13 Oct 2023 18:20:41 +0200 Subject: [PATCH 72/83] feat(conform): show error when user overwrites conform config function --- lua/lazyvim/plugins/formatting.lua | 126 ++++++++++++++++------------- 1 file changed, 71 insertions(+), 55 deletions(-) diff --git a/lua/lazyvim/plugins/formatting.lua b/lua/lazyvim/plugins/formatting.lua index 2053d1a5..5042f076 100644 --- a/lua/lazyvim/plugins/formatting.lua +++ b/lua/lazyvim/plugins/formatting.lua @@ -1,8 +1,41 @@ local Util = require("lazyvim.util") +local M = {} + ---@type ConformOpts local format_opts = {} +---@param opts ConformOpts +function M.setup(plugin, opts) + local util = require("conform.util") + opts.formatters = opts.formatters or {} + for name, formatter in pairs(opts.formatters) do + if type(formatter) == "table" then + local ok, defaults = pcall(require, "conform.formatters." .. name) + if ok and type(defaults) == "table" then + opts.formatters[name] = vim.tbl_deep_extend("force", {}, defaults, formatter) + end + if opts.formatters[name].extra_args then + opts.formatters[name].args = + util.extend_args(opts.formatters[name].args or {}, opts.formatters[name].extra_args) + end + end + end + + for _, key in ipairs({ "format_on_save", "format_after_save" }) do + if opts[key] then + Util.warn( + ("Don't set `opts.%s` for `conform.nvim`.\n**LazyVim** will use the conform formatter automatically"):format( + key + ) + ) + opts[key] = nil + end + end + format_opts = opts.format + require("conform").setup(opts) +end + return { { "stevearc/conform.nvim", @@ -39,62 +72,45 @@ return { }) end) end, - ---@class ConformOpts - opts = { - -- LazyVim will use these options when formatting with the conform.nvim formatter - format = { - timeout_ms = 1000, - }, - formatters_by_ft = { - lua = { "stylua" }, - fish = { "fish_indent" }, - sh = { "shfmt" }, - }, - -- LazyVim will merge the options you set here with builtin formatters. - -- You can also define any custom formatters here. - ---@type table - formatters = { - injected = { options = { ignore_errors = true } }, - -- -- Example of using dprint only when a dprint.json file is present - -- dprint = { - -- condition = function(ctx) - -- return vim.fs.find({ "dprint.json" }, { path = ctx.filename, upward = true })[1] - -- end, - -- }, - shfmt = { - extra_args = { "-i", "2", "-ci" }, + opts = function() + local plugin = require("lazy.core.config").plugins["conform.nvim"] + if plugin.config ~= M.setup then + Util.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", + }, { title = "LazyVim" }) + end + ---@class ConformOpts + return { + -- LazyVim will use these options when formatting with the conform.nvim formatter + format = { + timeout_ms = 1000, }, - }, - }, - ---@param opts ConformOpts - config = function(_, opts) - local util = require("conform.util") - opts.formatters = opts.formatters or {} - for name, formatter in pairs(opts.formatters) do - if type(formatter) == "table" then - local ok, defaults = pcall(require, "conform.formatters." .. name) - if ok and type(defaults) == "table" then - opts.formatters[name] = vim.tbl_deep_extend("force", {}, defaults, formatter) - end - if opts.formatters[name].extra_args then - opts.formatters[name].args = - util.extend_args(opts.formatters[name].args or {}, opts.formatters[name].extra_args) - end - end - end - - for _, key in ipairs({ "format_on_save", "format_after_save" }) do - if opts[key] then - Util.warn( - ("Don't set `opts.%s` for `conform.nvim`.\n**LazyVim** will use the conform formatter automatically"):format( - key - ) - ) - opts[key] = nil - end - end - format_opts = opts.format - require("conform").setup(opts) + formatters_by_ft = { + lua = { "stylua" }, + fish = { "fish_indent" }, + sh = { "shfmt" }, + }, + -- LazyVim will merge the options you set here with builtin formatters. + -- You can also define any custom formatters here. + ---@type table + formatters = { + injected = { options = { ignore_errors = true } }, + -- # Example of using dprint only when a dprint.json file is present + -- dprint = { + -- condition = function(ctx) + -- return vim.fs.find({ "dprint.json" }, { path = ctx.filename, upward = true })[1] + -- end, + -- }, + -- + -- # Example of using shfmt with extra args + -- shfmt = { + -- extra_args = { "-i", "2", "-ci" }, + -- }, + }, + } end, + config = M.setup, }, } From 7fe68d9f055fd34d95f19a8711e281ab40629482 Mon Sep 17 00:00:00 2001 From: Kevin Traver Date: Fri, 13 Oct 2023 11:17:50 -0600 Subject: [PATCH 73/83] fix(spectre): add title to Spectre panel in edgy (#1703) --- lua/lazyvim/plugins/extras/ui/edgy.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/lazyvim/plugins/extras/ui/edgy.lua b/lua/lazyvim/plugins/extras/ui/edgy.lua index 64e6237a..6cabd24d 100644 --- a/lua/lazyvim/plugins/extras/ui/edgy.lua +++ b/lua/lazyvim/plugins/extras/ui/edgy.lua @@ -49,7 +49,7 @@ return { return vim.bo[buf].buftype == "help" end, }, - { ft = "spectre_panel", size = { height = 0.4 } }, + { title = "Spectre", ft = "spectre_panel", size = { height = 0.4 } }, { title = "Neotest Output", ft = "neotest-output-panel", size = { height = 15 } }, }, left = { From ff9bf005b6957bb46a5541188925f32a1d86365d Mon Sep 17 00:00:00 2001 From: Thibault Duplessis Date: Sat, 14 Oct 2023 13:21:30 +0200 Subject: [PATCH 74/83] fix(dashboard-nvim): repository has moved to nvimdev/dashboard-nvim (#1715) * fix(dashboard-nvim) repository has moved to nvimdev/dashboard-nvim * fix(dashboard): automatically rename dashboard.nvim --------- Co-authored-by: Folke Lemaitre --- lua/lazyvim/plugins/extras/ui/alpha.lua | 2 +- lua/lazyvim/plugins/extras/ui/mini-starter.lua | 2 +- lua/lazyvim/plugins/extras/util/project.lua | 2 +- lua/lazyvim/plugins/ui.lua | 2 +- lua/lazyvim/util/plugin.lua | 1 + 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lua/lazyvim/plugins/extras/ui/alpha.lua b/lua/lazyvim/plugins/extras/ui/alpha.lua index d05c941c..875c11c8 100644 --- a/lua/lazyvim/plugins/extras/ui/alpha.lua +++ b/lua/lazyvim/plugins/extras/ui/alpha.lua @@ -1,6 +1,6 @@ return { - { "glepnir/dashboard-nvim", enabled = false }, + { "nvimdev/dashboard-nvim", enabled = false }, { "echasnovski/mini.starter", enabled = false }, -- Dashboard. This runs when neovim starts, and is what displays -- the "LAZYVIM" banner. diff --git a/lua/lazyvim/plugins/extras/ui/mini-starter.lua b/lua/lazyvim/plugins/extras/ui/mini-starter.lua index 6ec0e572..887db7ef 100644 --- a/lua/lazyvim/plugins/extras/ui/mini-starter.lua +++ b/lua/lazyvim/plugins/extras/ui/mini-starter.lua @@ -2,7 +2,7 @@ return { -- disable alpha { "goolord/alpha-nvim", enabled = false }, - { "glepnir/dashboard-nvim", enabled = false }, + { "nvimdev/dashboard-nvim", enabled = false }, -- enable mini.starter { diff --git a/lua/lazyvim/plugins/extras/util/project.lua b/lua/lazyvim/plugins/extras/util/project.lua index 0800e5d5..8164d19f 100644 --- a/lua/lazyvim/plugins/extras/util/project.lua +++ b/lua/lazyvim/plugins/extras/util/project.lua @@ -45,7 +45,7 @@ return { end, }, { - "glepnir/dashboard-nvim", + "nvimdev/dashboard-nvim", optional = true, opts = function(_, opts) local projects = { diff --git a/lua/lazyvim/plugins/ui.lua b/lua/lazyvim/plugins/ui.lua index e821c33e..abba7d44 100644 --- a/lua/lazyvim/plugins/ui.lua +++ b/lua/lazyvim/plugins/ui.lua @@ -331,7 +331,7 @@ return { end, }, { - "glepnir/dashboard-nvim", + "nvimdev/dashboard-nvim", event = "VimEnter", opts = function() local logo = [[ diff --git a/lua/lazyvim/util/plugin.lua b/lua/lazyvim/util/plugin.lua index f23bec3b..9ff2c986 100644 --- a/lua/lazyvim/util/plugin.lua +++ b/lua/lazyvim/util/plugin.lua @@ -26,6 +26,7 @@ M.renames = { ["jose-elias-alvarez/null-ls.nvim"] = "nvimtools/none-ls.nvim", ["null-ls.nvim"] = "none-ls.nvim", ["romgrk/nvim-treesitter-context"] = "nvim-treesitter/nvim-treesitter-context", + ["glepnir/dashboard-nvim"] = "nvimdev/dashboard-nvim", } function M.setup() From f724eae2e3d1065f406baa22fc4dae30a49be86b Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sat, 14 Oct 2023 11:22:06 +0000 Subject: [PATCH 75/83] chore(build): auto-generate vimdoc --- doc/LazyVim.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/LazyVim.txt b/doc/LazyVim.txt index 49d339b6..0347bf2f 100644 --- a/doc/LazyVim.txt +++ b/doc/LazyVim.txt @@ -1,4 +1,4 @@ -*LazyVim.txt* For Neovim >= 0.8.0 Last change: 2023 October 13 +*LazyVim.txt* For Neovim >= 0.8.0 Last change: 2023 October 14 ============================================================================== Table of Contents *LazyVim-table-of-contents* From 5e1a86d3b257db37c8b443deea6ca1fefcb0b1aa Mon Sep 17 00:00:00 2001 From: Kevin Traver Date: Sat, 14 Oct 2023 06:40:25 -0600 Subject: [PATCH 76/83] feat(toggle): add keymap to toggle treesitter context (#1711) * feat: add keymap to toggle treesitter context * fix: get correct enabled state --------- Co-authored-by: Folke Lemaitre --- lua/lazyvim/plugins/formatting.lua | 2 +- lua/lazyvim/plugins/treesitter.lua | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lua/lazyvim/plugins/formatting.lua b/lua/lazyvim/plugins/formatting.lua index 5042f076..c98a7252 100644 --- a/lua/lazyvim/plugins/formatting.lua +++ b/lua/lazyvim/plugins/formatting.lua @@ -6,7 +6,7 @@ local M = {} local format_opts = {} ---@param opts ConformOpts -function M.setup(plugin, opts) +function M.setup(_, opts) local util = require("conform.util") opts.formatters = opts.formatters or {} for name, formatter in pairs(opts.formatters) do diff --git a/lua/lazyvim/plugins/treesitter.lua b/lua/lazyvim/plugins/treesitter.lua index c833a707..1b4debcf 100644 --- a/lua/lazyvim/plugins/treesitter.lua +++ b/lua/lazyvim/plugins/treesitter.lua @@ -110,6 +110,22 @@ return { event = "LazyFile", enabled = true, opts = { mode = "cursor" }, + keys = { + { + "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" }) + else + Util.warn("Disabled Treesitter Context", { title = "Option" }) + end + end, + desc = "Toggle Treesitter Context", + }, + }, }, -- Automatically add closing tags for HTML and JSX From 5b89bc8cbf990edec201d07c146a3fe28db3302f Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Sat, 14 Oct 2023 16:56:18 +0200 Subject: [PATCH 77/83] fix(lsp): trigger FileType commands after installing LSP servers --- lua/lazyvim/plugins/lsp/init.lua | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lua/lazyvim/plugins/lsp/init.lua b/lua/lazyvim/plugins/lsp/init.lua index 165367bf..f0823e46 100644 --- a/lua/lazyvim/plugins/lsp/init.lua +++ b/lua/lazyvim/plugins/lsp/init.lua @@ -218,6 +218,15 @@ return { config = function(_, opts) require("mason").setup(opts) local mr = require("mason-registry") + mr:on("package:install:success", function() + vim.defer_fn(function() + -- trigger FileType event to possibly load this newly installed LSP server + require("lazy.core.handler.event").trigger({ + event = "FileType", + buf = vim.api.nvim_get_current_buf(), + }) + end, 100) + end) local function ensure_installed() for _, tool in ipairs(opts.ensure_installed) do local p = mr.get_package(tool) From 6b9ee963e2684e7b37120b86bab5049918e14899 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Sat, 14 Oct 2023 16:56:48 +0200 Subject: [PATCH 78/83] fix(news): dont show news when it has never been viewed (new install) --- lua/lazyvim/util/news.lua | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/lua/lazyvim/util/news.lua b/lua/lazyvim/util/news.lua index 11707155..4c212470 100644 --- a/lua/lazyvim/util/news.lua +++ b/lua/lazyvim/util/news.lua @@ -15,6 +15,9 @@ end function M.setup() vim.schedule(function() if Config.news.lazyvim then + if not Config.json.data.news["NEWS.md"] then + M.welcome() + end M.lazyvim(true) end if Config.news.neovim then @@ -23,6 +26,10 @@ function M.setup() end) end +function M.welcome() + Util.info("Welcome to LazyVim!") +end + function M.changelog() M.open("CHANGELOG.md", { plugin = "LazyVim" }) end @@ -55,23 +62,28 @@ function M.open(file, opts) end if opts.when_changed then + local is_new = not Config.json.data.news[ref] local hash = M.hash(file) if hash == Config.json.data.news[ref] then return end Config.json.data.news[ref] = hash Util.json.save() + -- don't open if file has never been opened + if is_new then + return + end end local float = require("lazy.util").float({ file = file, size = { width = 0.6, height = 0.6 }, }) - vim.wo[float.win].spell = false - vim.wo[float.win].wrap = false - vim.wo[float.win].signcolumn = "yes" - vim.wo[float.win].statuscolumn = " " - vim.wo[float.win].conceallevel = 3 + vim.opt_local.spell = false + vim.opt_local.wrap = false + vim.opt_local.signcolumn = "yes" + vim.opt_local.statuscolumn = " " + vim.opt_local.conceallevel = 3 vim.diagnostic.disable(float.buf) end From 3a93757bb1ee28c3e1b59c6c47ea5c4e74d8f1b2 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Sat, 14 Oct 2023 17:32:06 +0200 Subject: [PATCH 79/83] fix: dont lazy-load on ft. Load on cmd or keys only --- lua/lazyvim/plugins/extras/lang/markdown.lua | 64 ++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 lua/lazyvim/plugins/extras/lang/markdown.lua diff --git a/lua/lazyvim/plugins/extras/lang/markdown.lua b/lua/lazyvim/plugins/extras/lang/markdown.lua new file mode 100644 index 00000000..123f92bf --- /dev/null +++ b/lua/lazyvim/plugins/extras/lang/markdown.lua @@ -0,0 +1,64 @@ +return { + { + "nvim-treesitter/nvim-treesitter", + opts = function(_, opts) + if type(opts.ensure_installed) == "table" then + vim.list_extend(opts.ensure_installed, { "markdown", "markdown_inline" }) + end + end, + }, + { + "williamboman/mason.nvim", + opts = function(_, opts) + opts.ensure_installed = opts.ensure_installed or {} + vim.list_extend(opts.ensure_installed, { "markdownlint" }) + end, + }, + { + "nvimtools/none-ls.nvim", + optional = true, + opts = function(_, opts) + local nls = require("null-ls") + opts.sources = vim.list_extend(opts.sources or {}, { + nls.builtins.diagnostics.markdownlint, + }) + end, + }, + { + "mfussenegger/nvim-lint", + optional = true, + opts = { + linters_by_ft = { + markdown = { "markdownlint" }, + }, + }, + }, + { + "neovim/nvim-lspconfig", + opts = { + servers = { + marksman = {}, + }, + }, + }, + + -- Markdown preview + { + "iamcco/markdown-preview.nvim", + cmd = { "MarkdownPreviewToggle", "MarkdownPreview", "MarkdownPreviewStop" }, + build = function() + vim.fn["mkdp#util#install"]() + end, + keys = { + { + "cp", + ft = "markdown", + "MarkdownPreviewToggle", + desc = "Peek (Markdown Preview)", + }, + }, + config = function() + vim.cmd([[do FileType]]) + end, + }, +} From 121df706047c7c075066ea93b0be389a30644533 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Sat, 14 Oct 2023 17:35:13 +0200 Subject: [PATCH 80/83] Revert "fix: dont lazy-load on ft. Load on cmd or keys only" This reverts commit 3a93757bb1ee28c3e1b59c6c47ea5c4e74d8f1b2. --- lua/lazyvim/plugins/extras/lang/markdown.lua | 64 -------------------- 1 file changed, 64 deletions(-) delete mode 100644 lua/lazyvim/plugins/extras/lang/markdown.lua diff --git a/lua/lazyvim/plugins/extras/lang/markdown.lua b/lua/lazyvim/plugins/extras/lang/markdown.lua deleted file mode 100644 index 123f92bf..00000000 --- a/lua/lazyvim/plugins/extras/lang/markdown.lua +++ /dev/null @@ -1,64 +0,0 @@ -return { - { - "nvim-treesitter/nvim-treesitter", - opts = function(_, opts) - if type(opts.ensure_installed) == "table" then - vim.list_extend(opts.ensure_installed, { "markdown", "markdown_inline" }) - end - end, - }, - { - "williamboman/mason.nvim", - opts = function(_, opts) - opts.ensure_installed = opts.ensure_installed or {} - vim.list_extend(opts.ensure_installed, { "markdownlint" }) - end, - }, - { - "nvimtools/none-ls.nvim", - optional = true, - opts = function(_, opts) - local nls = require("null-ls") - opts.sources = vim.list_extend(opts.sources or {}, { - nls.builtins.diagnostics.markdownlint, - }) - end, - }, - { - "mfussenegger/nvim-lint", - optional = true, - opts = { - linters_by_ft = { - markdown = { "markdownlint" }, - }, - }, - }, - { - "neovim/nvim-lspconfig", - opts = { - servers = { - marksman = {}, - }, - }, - }, - - -- Markdown preview - { - "iamcco/markdown-preview.nvim", - cmd = { "MarkdownPreviewToggle", "MarkdownPreview", "MarkdownPreviewStop" }, - build = function() - vim.fn["mkdp#util#install"]() - end, - keys = { - { - "cp", - ft = "markdown", - "MarkdownPreviewToggle", - desc = "Peek (Markdown Preview)", - }, - }, - config = function() - vim.cmd([[do FileType]]) - end, - }, -} From b3d46bc0141c23bfd4302718ff42dfa172c6952b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Koz=C5=82owicz?= Date: Sat, 14 Oct 2023 17:42:02 +0200 Subject: [PATCH 81/83] feat(lang): add markdown support (#1718) * feat(lang): add markdown support * feat: use peek.nvim instead of markdown-preview. Disable and show warning when deno is not installed * feat: add markdown-preview back --------- Co-authored-by: Folke Lemaitre --- lua/lazyvim/plugins/extras/lang/markdown.lua | 64 ++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 lua/lazyvim/plugins/extras/lang/markdown.lua diff --git a/lua/lazyvim/plugins/extras/lang/markdown.lua b/lua/lazyvim/plugins/extras/lang/markdown.lua new file mode 100644 index 00000000..123f92bf --- /dev/null +++ b/lua/lazyvim/plugins/extras/lang/markdown.lua @@ -0,0 +1,64 @@ +return { + { + "nvim-treesitter/nvim-treesitter", + opts = function(_, opts) + if type(opts.ensure_installed) == "table" then + vim.list_extend(opts.ensure_installed, { "markdown", "markdown_inline" }) + end + end, + }, + { + "williamboman/mason.nvim", + opts = function(_, opts) + opts.ensure_installed = opts.ensure_installed or {} + vim.list_extend(opts.ensure_installed, { "markdownlint" }) + end, + }, + { + "nvimtools/none-ls.nvim", + optional = true, + opts = function(_, opts) + local nls = require("null-ls") + opts.sources = vim.list_extend(opts.sources or {}, { + nls.builtins.diagnostics.markdownlint, + }) + end, + }, + { + "mfussenegger/nvim-lint", + optional = true, + opts = { + linters_by_ft = { + markdown = { "markdownlint" }, + }, + }, + }, + { + "neovim/nvim-lspconfig", + opts = { + servers = { + marksman = {}, + }, + }, + }, + + -- Markdown preview + { + "iamcco/markdown-preview.nvim", + cmd = { "MarkdownPreviewToggle", "MarkdownPreview", "MarkdownPreviewStop" }, + build = function() + vim.fn["mkdp#util#install"]() + end, + keys = { + { + "cp", + ft = "markdown", + "MarkdownPreviewToggle", + desc = "Peek (Markdown Preview)", + }, + }, + config = function() + vim.cmd([[do FileType]]) + end, + }, +} From 8f42733ce526b6c866b26824d78a1822730c2852 Mon Sep 17 00:00:00 2001 From: MoetaYuko Date: Sat, 14 Oct 2023 23:49:23 +0800 Subject: [PATCH 82/83] feat(python): add key binding for organize imports (#1670) --- lua/lazyvim/plugins/extras/lang/python.lua | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lua/lazyvim/plugins/extras/lang/python.lua b/lua/lazyvim/plugins/extras/lang/python.lua index 835c9da8..a4783973 100644 --- a/lua/lazyvim/plugins/extras/lang/python.lua +++ b/lua/lazyvim/plugins/extras/lang/python.lua @@ -12,7 +12,23 @@ return { opts = { servers = { pyright = {}, - ruff_lsp = {}, + ruff_lsp = { + keys = { + { + "co", + function() + vim.lsp.buf.code_action({ + apply = true, + context = { + only = { "source.organizeImports" }, + diagnostics = {}, + }, + }) + end, + desc = "Organize Imports", + }, + }, + }, }, setup = { ruff_lsp = function() From 1a4342abaeb468f22009ce0f2e25e746ca18f585 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Sat, 14 Oct 2023 18:02:47 +0200 Subject: [PATCH 83/83] refactor: move cmp status lualine component to util --- lua/lazyvim/plugins/extras/coding/codeium.lua | 38 +-------------- lua/lazyvim/util/init.lua | 1 + lua/lazyvim/util/lualine.lua | 46 +++++++++++++++++++ 3 files changed, 48 insertions(+), 37 deletions(-) create mode 100644 lua/lazyvim/util/lualine.lua diff --git a/lua/lazyvim/plugins/extras/coding/codeium.lua b/lua/lazyvim/plugins/extras/coding/codeium.lua index 457535cd..a9f40624 100644 --- a/lua/lazyvim/plugins/extras/coding/codeium.lua +++ b/lua/lazyvim/plugins/extras/coding/codeium.lua @@ -27,43 +27,7 @@ return { optional = true, event = "VeryLazy", opts = function(_, opts) - local started = false - local function status() - if not package.loaded["cmp"] then - return - end - for _, s in ipairs(require("cmp").core.sources) do - if s.name == "codeium" then - if s.source:is_available() then - started = true - else - return started and "error" or nil - end - if s.status == s.SourceStatus.FETCHING then - return "pending" - end - return "ok" - end - end - end - - local Util = require("lazyvim.util") - local colors = { - ok = Util.ui.fg("Special"), - error = Util.ui.fg("DiagnosticError"), - pending = Util.ui.fg("DiagnosticWarn"), - } - table.insert(opts.sections.lualine_x, 2, { - function() - return require("lazyvim.config").icons.kinds.Codeium - end, - cond = function() - return status() ~= nil - end, - color = function() - return colors[status()] or colors.ok - end, - }) + table.insert(opts.sections.lualine_x, 2, require("lazyvim.util").lualine.cmp_source("codeium")) end, }, } diff --git a/lua/lazyvim/util/init.lua b/lua/lazyvim/util/init.lua index ddfa55f8..4a98aee4 100644 --- a/lua/lazyvim/util/init.lua +++ b/lua/lazyvim/util/init.lua @@ -13,6 +13,7 @@ local LazyUtil = require("lazy.core.util") ---@field inject lazyvim.util.inject ---@field news lazyvim.util.news ---@field json lazyvim.util.json +---@field lualine lazyvim.util.lualine local M = {} ---@type table diff --git a/lua/lazyvim/util/lualine.lua b/lua/lazyvim/util/lualine.lua new file mode 100644 index 00000000..8efcf714 --- /dev/null +++ b/lua/lazyvim/util/lualine.lua @@ -0,0 +1,46 @@ +local Util = require("lazyvim.util") + +---@class lazyvim.util.lualine +local M = {} + +function M.cmp_source(name, icon) + local started = false + local function status() + if not package.loaded["cmp"] then + return + end + for _, s in ipairs(require("cmp").core.sources) do + if s.name == name then + if s.source:is_available() then + started = true + else + return started and "error" or nil + end + if s.status == s.SourceStatus.FETCHING then + return "pending" + end + return "ok" + end + end + end + + local colors = { + ok = Util.ui.fg("Special"), + error = Util.ui.fg("DiagnosticError"), + pending = Util.ui.fg("DiagnosticWarn"), + } + + return { + function() + return icon or require("lazyvim.config").icons.kinds[name:sub(1, 1):upper() .. name:sub(2)] + end, + cond = function() + return status() ~= nil + end, + color = function() + return colors[status()] or colors.ok + end, + } +end + +return M