diff --git a/CHANGELOG.md b/CHANGELOG.md index af64098e..45c72e6e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,45 @@ # Changelog +## [12.10.0](https://github.com/LazyVim/LazyVim/compare/v12.9.0...v12.10.0) (2024-06-07) + + +### Features + +* **prettier:** prettier is now enabled for all supported filetypes and no longer requires a config file by default ([7d50bf0](https://github.com/LazyVim/LazyVim/commit/7d50bf0626f768b4d036b500ff204835fa405b74)) +* **prettier:** with the prettier & astro extra, prettier will be enabled if the prettier-astro-plugin is available ([214f5fc](https://github.com/LazyVim/LazyVim/commit/214f5fccdf468030b05851ebfbef8394485322fb)) +* **svelte:** with prettier & svelte extra, prettier will be enabled when prettier-plugin-svelte is available ([945143a](https://github.com/LazyVim/LazyVim/commit/945143a34e298541989a9f050a3fb2ced6646e9e)) +* **util:** added LazyVim.has_extra ([b714f28](https://github.com/LazyVim/LazyVim/commit/b714f286623cca6e3da31df43c4cf4354a46c36d)) +* **util:** added LazyVim.memoize ([5a11d74](https://github.com/LazyVim/LazyVim/commit/5a11d740e119d392858b97b69470201e66e66212)) + + +### Bug Fixes + +* **clojure:** removed rainbow delimiters and fixed some plugin setups. Closes [#3530](https://github.com/LazyVim/LazyVim/issues/3530) ([cfa8c9f](https://github.com/LazyVim/LazyVim/commit/cfa8c9fbd45a36784f76d4842bc385828214ee1c)) +* **cmp:** don't enable `snippets` source without `nvim-snippets` ([#3527](https://github.com/LazyVim/LazyVim/issues/3527)) ([af80811](https://github.com/LazyVim/LazyVim/commit/af80811be01f5349544a1b21e9dd03f0e25fefca)) +* **extras:** load prettier extra before svelte/astro ([4980574](https://github.com/LazyVim/LazyVim/commit/49805748d4cefc077cc0c81e864f1757198fc3f4)) +* **formatting:** remove deprecation check on some options ([c16fb5d](https://github.com/LazyVim/LazyVim/commit/c16fb5d49bfe10041fb36f6ac80a755767b9e6bf)) +* **prettier:** fixup ([ac9217b](https://github.com/LazyVim/LazyVim/commit/ac9217b1994ad00b488ba73021d89afac03873ee)) + +## [12.9.0](https://github.com/LazyVim/LazyVim/compare/v12.8.0...v12.9.0) (2024-06-07) + + +### Features + +* **autocmd:** enable spell for typst and text file ([#3505](https://github.com/LazyVim/LazyVim/issues/3505)) ([8ca7245](https://github.com/LazyVim/LazyVim/commit/8ca72451298f60e6440ac48293052c5e82bd8ec6)) +* **docs:** add link to LazyVim For Ambitious Developers to README ([#3504](https://github.com/LazyVim/LazyVim/issues/3504)) ([2a5ab31](https://github.com/LazyVim/LazyVim/commit/2a5ab3109a7e5f3ef98c2a93f24738797c6d9cc6)) +* **lang:** add clojure support ([#2179](https://github.com/LazyVim/LazyVim/issues/2179)) ([913902b](https://github.com/LazyVim/LazyVim/commit/913902ba362603a4620f8981fdedac7f53816b3a)) +* **neo-tree:** added l:open and h:close_node to neo-tree. Closes [#3293](https://github.com/LazyVim/LazyVim/issues/3293) ([dbec83d](https://github.com/LazyVim/LazyVim/commit/dbec83d57a1d5936ac860c37e0393a89b7cae7e9)) +* **options:** when available use treesitter spell regions for spell checking ([276b803](https://github.com/LazyVim/LazyVim/commit/276b8032bedb6e1601ae85ecdfaee63217843b4f)) +* **sql:** add SQL extra ([#1740](https://github.com/LazyVim/LazyVim/issues/1740)) ([59495c1](https://github.com/LazyVim/LazyVim/commit/59495c18714d8ae4c0b5f7a41dad96e39f9eb189)) + + +### Bug Fixes + +* **editor:** telescope init error when trouble.nvim is disabled ([#3518](https://github.com/LazyVim/LazyVim/issues/3518)) ([c452fd7](https://github.com/LazyVim/LazyVim/commit/c452fd730c94bfcbb5f9f4af1cae3c851f9456a3)) +* **lualine:** only show one Lualine component for symbols ([#3514](https://github.com/LazyVim/LazyVim/issues/3514)) ([827aa53](https://github.com/LazyVim/LazyVim/commit/827aa5380a883e6a2a9904c253627489d43d3050)), closes [#3511](https://github.com/LazyVim/LazyVim/issues/3511) +* **mini.files:** fix error about `opts.mappings` ([#3507](https://github.com/LazyVim/LazyVim/issues/3507)) ([9210648](https://github.com/LazyVim/LazyVim/commit/92106484ed89efb364568fa27a689bd8be83d066)) +* removed leader-m, since it is leading to too many issues. Still available at leader-wm ([119dcb9](https://github.com/LazyVim/LazyVim/commit/119dcb949a84d9b10a620c9ad8400c220c5e5adb)) + ## [12.8.0](https://github.com/LazyVim/LazyVim/compare/v12.7.0...v12.8.0) (2024-06-06) diff --git a/NEWS.md b/NEWS.md index 05a1ddce..3abd43b7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,19 @@ # What's new? -## 11.x +## 12.x + +- This **news** is now also available on the website at [https://www.lazyvim.org/news](https://www.lazyvim.org/news) + +- **prettier** extra now works for all prettier supported filetypes + and will be enabled for astro/svelte extra if you have a proper + config file with the correct prettier plugin + +- **New Language Support:** SQL, Clojure, Thrift, Elm, Gleam, Angular, + NuShell, Svelte, Kotlin, Astro, Toml and PHP + +- **New Extras:** `copilot-chat`, `git`, `octo`, `inc-rename` and `neogen` + +- The **typescript** extra now uses `vtsls` instead of `tsserver` - **Neovim >= 0.10** now uses the much faster [lazydev.nvim](https://github.com/folke/lazydev.nvim) instead of `neodev.nvim` @@ -8,6 +21,18 @@ - moved `neoconf.nvim` to extras. Project specific LSP settings can be done with a `.lazy.lua` file instead. +## 11.x + +- **Keymaps:** + + - `gB` to open the current repo in the browser + - `gco` and `gcO` to add a comment below or above the current line + - `wm` to toggle window maximize + +- **lazydev.nvim:** faster alternative to `neodev.nvim` + +- **Options:** Added `linebreak=true` to default options. + - `mini.ai` is back as a default plugin! Removing it was a mistake. It's a great plugin that enhances the native text objects. diff --git a/doc/LazyVim.txt b/doc/LazyVim.txt index 309ad8fc..38e4c106 100644 --- a/doc/LazyVim.txt +++ b/doc/LazyVim.txt @@ -1,4 +1,4 @@ -*LazyVim.txt* For Neovim >= 0.9.0 Last change: 2024 June 07 +*LazyVim.txt* For Neovim >= 0.9.0 Last change: 2024 June 08 ============================================================================== Table of Contents *LazyVim-table-of-contents* diff --git a/lua/lazyvim/plugins/coding.lua b/lua/lazyvim/plugins/coding.lua index cf563f4a..155cfe80 100644 --- a/lua/lazyvim/plugins/coding.lua +++ b/lua/lazyvim/plugins/coding.lua @@ -111,7 +111,9 @@ return { return LazyVim.cmp.expand(item.body) end, } - table.insert(opts.sources, { name = "snippets" }) + if LazyVim.has("nvim-snippets") then + table.insert(opts.sources, { name = "snippets" }) + end end, keys = { { diff --git a/lua/lazyvim/plugins/extras/coding/copilot.lua b/lua/lazyvim/plugins/extras/coding/copilot.lua index afe14f61..a9897107 100644 --- a/lua/lazyvim/plugins/extras/coding/copilot.lua +++ b/lua/lazyvim/plugins/extras/coding/copilot.lua @@ -66,10 +66,8 @@ return { -- attach cmp source whenever copilot attaches -- fixes lazy-loading issues with the copilot cmp source LazyVim.lsp.on_attach(function(client) - if client.name == "copilot" then - copilot_cmp._on_insert_enter({}) - end - end) + copilot_cmp._on_insert_enter({}) + end, "copilot") end, }, }, diff --git a/lua/lazyvim/plugins/extras/dap/core.lua b/lua/lazyvim/plugins/extras/dap/core.lua index c76a0d5b..7bc2345f 100644 --- a/lua/lazyvim/plugins/extras/dap/core.lua +++ b/lua/lazyvim/plugins/extras/dap/core.lua @@ -53,7 +53,7 @@ return { -- stylua: ignore keys = { - { "d", "", desc = "+debug" }, + { "d", "", desc = "+debug", mode = {"n", "v"} }, { "dB", function() require("dap").set_breakpoint(vim.fn.input('Breakpoint condition: ')) end, desc = "Breakpoint Condition" }, { "db", function() require("dap").toggle_breakpoint() end, desc = "Toggle Breakpoint" }, { "dc", function() require("dap").continue() end, desc = "Continue" }, diff --git a/lua/lazyvim/plugins/extras/editor/refactoring.lua b/lua/lazyvim/plugins/extras/editor/refactoring.lua index 586cda53..9d8f8f9c 100644 --- a/lua/lazyvim/plugins/extras/editor/refactoring.lua +++ b/lua/lazyvim/plugins/extras/editor/refactoring.lua @@ -7,7 +7,7 @@ return { "nvim-treesitter/nvim-treesitter", }, keys = { - { "r", "", desc = "+refactor" }, + { "r", "", desc = "+refactor", mode = { "n", "v" } }, { "rs", function() diff --git a/lua/lazyvim/plugins/extras/formatting/prettier.lua b/lua/lazyvim/plugins/extras/formatting/prettier.lua index c0a84cba..13704ca9 100644 --- a/lua/lazyvim/plugins/extras/formatting/prettier.lua +++ b/lua/lazyvim/plugins/extras/formatting/prettier.lua @@ -1,23 +1,88 @@ +---@diagnostic disable: inject-field if lazyvim_docs then - -- By default, prettier will only be used for formatting - -- if a prettier configuration file is found in the project. - -- Set to `false` to always use prettier for supported filetypes. - vim.g.lazyvim_prettier_needs_config = true + -- Enable the option to require a Prettier config file + -- If no prettier config file is found, the formatter will not be used + vim.g.lazyvim_prettier_needs_config = false end -local needs_config = vim.g.lazyvim_prettier_needs_config ~= false +---@alias ConformCtx {buf: number, filename: string, dirname: string} +local M = {} --- local check = vim.g.lazyvim_prettier +local supported = { + "css", + "graphql", + "handlebars", + "html", + "javascript", + "javascriptreact", + "json", + "jsonc", + "less", + "markdown", + "markdown.mdx", + "scss", + "typescript", + "typescriptreact", + "vue", + "yaml", +} -local enabled = {} ---@type table +--- Checks if a Prettier config file exists for the given context +---@param ctx ConformCtx +function M.has_config(ctx) + vim.fn.system({ "prettier", "--find-config-path", ctx.filename }) + return vim.v.shell_error == 0 +end + +--- Checks if a parser can be inferred for the given context: +--- * If the filetype is in the supported list, return true +--- * Otherwise, check if a parser can be inferred +---@param ctx ConformCtx +function M.has_parser(ctx) + local ft = vim.bo[ctx.buf].filetype --[[@as string]] + -- default filetypes are always supported + if vim.tbl_contains(supported, ft) then + return true + end + -- otherwise, check if a parser can be inferred + local ret = vim.fn.system({ "prettier", "--file-info", ctx.filename }) + ---@type boolean, string? + local ok, parser = pcall(function() + return vim.fn.json_decode(ret).inferredParser + end) + return ok and parser and parser ~= vim.NIL +end + +M.has_config = LazyVim.memoize(M.has_config) +M.has_parser = LazyVim.memoize(M.has_parser) return { { "williamboman/mason.nvim", + opts = { ensure_installed = { "prettier" } }, + }, + + -- conform + { + "stevearc/conform.nvim", + optional = true, + ---@param opts ConformOpts opts = function(_, opts) - table.insert(opts.ensure_installed, "prettier") + opts.formatters_by_ft = opts.formatters_by_ft or {} + for _, ft in ipairs(supported) do + opts.formatters_by_ft[ft] = { "prettier" } + end + + opts.formatters = opts.formatters or {} + opts.formatters.prettier = { + condition = function(_, ctx) + return M.has_parser(ctx) and (vim.g.lazyvim_prettier_needs_config ~= true or M.has_config(ctx)) + end, + } end, }, + + -- none-ls support { "nvimtools/none-ls.nvim", optional = true, @@ -27,43 +92,4 @@ return { table.insert(opts.sources, nls.builtins.formatting.prettier) end, }, - { - "stevearc/conform.nvim", - optional = true, - opts = { - formatters_by_ft = { - ["javascript"] = { "prettier" }, - ["javascriptreact"] = { "prettier" }, - ["typescript"] = { "prettier" }, - ["typescriptreact"] = { "prettier" }, - ["vue"] = { "prettier" }, - ["css"] = { "prettier" }, - ["scss"] = { "prettier" }, - ["less"] = { "prettier" }, - ["html"] = { "prettier" }, - ["json"] = { "prettier" }, - ["jsonc"] = { "prettier" }, - ["yaml"] = { "prettier" }, - ["markdown"] = { "prettier" }, - ["markdown.mdx"] = { "prettier" }, - ["graphql"] = { "prettier" }, - ["handlebars"] = { "prettier" }, - ["svelte"] = { "prettier" }, - }, - formatters = { - prettier = { - condition = function(_, ctx) - if not needs_config then - return true - end - if enabled[ctx.filename] == nil then - vim.fn.system({ "prettier", "--find-config-path", ctx.filename }) - enabled[ctx.filename] = vim.v.shell_error == 0 - end - return enabled[ctx.filename] - end, - }, - }, - }, - }, } diff --git a/lua/lazyvim/plugins/extras/lang/angular.lua b/lua/lazyvim/plugins/extras/lang/angular.lua index a6dc6ab2..583b0627 100644 --- a/lua/lazyvim/plugins/extras/lang/angular.lua +++ b/lua/lazyvim/plugins/extras/lang/angular.lua @@ -36,11 +36,9 @@ return { setup = { angularls = function() LazyVim.lsp.on_attach(function(client) - if client.name == "angularls" then - --HACK: disable angular renaming capability due to duplicate rename popping up - client.server_capabilities.renameProvider = false - end - end) + --HACK: disable angular renaming capability due to duplicate rename popping up + client.server_capabilities.renameProvider = false + end, "angularls") end, }, }, diff --git a/lua/lazyvim/plugins/extras/lang/astro.lua b/lua/lazyvim/plugins/extras/lang/astro.lua index b0bd2616..a4384148 100644 --- a/lua/lazyvim/plugins/extras/lang/astro.lua +++ b/lua/lazyvim/plugins/extras/lang/astro.lua @@ -41,4 +41,14 @@ return { }) end, }, + + { + "conform.nvim", + opts = function(_, opts) + if LazyVim.has_extra("formatting.prettier") then + opts.formatters_by_ft = opts.formatters_by_ft or {} + opts.formatters_by_ft.astro = { "prettier" } + end + end, + }, } diff --git a/lua/lazyvim/plugins/extras/lang/clojure.lua b/lua/lazyvim/plugins/extras/lang/clojure.lua index 1740ce52..7197aabd 100644 --- a/lua/lazyvim/plugins/extras/lang/clojure.lua +++ b/lua/lazyvim/plugins/extras/lang/clojure.lua @@ -26,17 +26,17 @@ return { end, }, - -- Enable rainbow parenthesis - { "HiPhish/rainbow-delimiters.nvim" }, - -- Add s-exp mappings - { "PaterJason/nvim-treesitter-sexp" }, + { "PaterJason/nvim-treesitter-sexp", opts = {}, event = "LazyFile" }, -- Colorize the output of the log buffer { "m00qek/baleia.nvim", - config = function() - vim.g.conjure_baleia = require("baleia").setup({ line_starts_at = 3 }) + opts = { + line_starts_at = 3, + }, + config = function(_, opts) + vim.g.conjure_baleia = require("baleia").setup(opts) vim.api.nvim_create_user_command("BaleiaColorize", function() vim.g.conjure_baleia.once(vim.api.nvim_get_current_buf()) @@ -49,6 +49,7 @@ return { -- Use Clojure REPL { "Olical/conjure", + event = "LazyFile", config = function(_, _) require("conjure.main").main() require("conjure.mapping")["on-filetype"]() diff --git a/lua/lazyvim/plugins/extras/lang/go.lua b/lua/lazyvim/plugins/extras/lang/go.lua index 5551789e..b3e0ffab 100644 --- a/lua/lazyvim/plugins/extras/lang/go.lua +++ b/lua/lazyvim/plugins/extras/lang/go.lua @@ -61,20 +61,18 @@ return { -- workaround for gopls not supporting semanticTokensProvider -- https://github.com/golang/go/issues/54531#issuecomment-1464982242 LazyVim.lsp.on_attach(function(client, _) - if client.name == "gopls" then - if not client.server_capabilities.semanticTokensProvider then - local semantic = client.config.capabilities.textDocument.semanticTokens - client.server_capabilities.semanticTokensProvider = { - full = true, - legend = { - tokenTypes = semantic.tokenTypes, - tokenModifiers = semantic.tokenModifiers, - }, - range = true, - } - end + if not client.server_capabilities.semanticTokensProvider then + local semantic = client.config.capabilities.textDocument.semanticTokens + client.server_capabilities.semanticTokensProvider = { + full = true, + legend = { + tokenTypes = semantic.tokenTypes, + tokenModifiers = semantic.tokenModifiers, + }, + range = true, + } end - end) + end, "gopls") -- end workaround end, }, diff --git a/lua/lazyvim/plugins/extras/lang/helm.lua b/lua/lazyvim/plugins/extras/lang/helm.lua index 4145b790..67ec0b26 100644 --- a/lua/lazyvim/plugins/extras/lang/helm.lua +++ b/lua/lazyvim/plugins/extras/lang/helm.lua @@ -1,13 +1,3 @@ -LazyVim.lsp.on_attach(function(client, buffer) - if client.name == "yamlls" then - if vim.api.nvim_get_option_value("filetype", { buf = buffer }) == "helm" then - vim.schedule(function() - vim.cmd("LspStop ++force yamlls") - end) - end - end -end) - return { recommended = function() return LazyVim.extras.wants({ @@ -25,9 +15,19 @@ return { "neovim/nvim-lspconfig", opts = { servers = { - yamlls = {}, helm_ls = {}, }, + setup = { + yamlls = function() + LazyVim.lsp.on_attach(function(client, buffer) + if vim.bo[buffer].filetype == "helm" then + vim.schedule(function() + vim.cmd("LspStop ++force yamlls") + end) + end + end, "yamlls") + end, + }, }, }, } diff --git a/lua/lazyvim/plugins/extras/lang/python.lua b/lua/lazyvim/plugins/extras/lang/python.lua index 1d2bb206..0be4b93c 100644 --- a/lua/lazyvim/plugins/extras/lang/python.lua +++ b/lua/lazyvim/plugins/extras/lang/python.lua @@ -58,11 +58,9 @@ return { setup = { [ruff] = function() LazyVim.lsp.on_attach(function(client, _) - if client.name == ruff then - -- Disable hover in favor of Pyright - client.server_capabilities.hoverProvider = false - end - end) + -- Disable hover in favor of Pyright + client.server_capabilities.hoverProvider = false + end, ruff) end, }, }, diff --git a/lua/lazyvim/plugins/extras/lang/svelte.lua b/lua/lazyvim/plugins/extras/lang/svelte.lua index 2d711ab6..565e50e5 100644 --- a/lua/lazyvim/plugins/extras/lang/svelte.lua +++ b/lua/lazyvim/plugins/extras/lang/svelte.lua @@ -54,4 +54,14 @@ return { }) end, }, + + { + "conform.nvim", + opts = function(_, opts) + if LazyVim.has_extra("formatting.prettier") then + opts.formatters_by_ft = opts.formatters_by_ft or {} + opts.formatters_by_ft.svelte = { "prettier" } + end + end, + }, } diff --git a/lua/lazyvim/plugins/extras/lang/typescript.lua b/lua/lazyvim/plugins/extras/lang/typescript.lua index 97c3353c..7316ad50 100644 --- a/lua/lazyvim/plugins/extras/lang/typescript.lua +++ b/lua/lazyvim/plugins/extras/lang/typescript.lua @@ -119,6 +119,56 @@ return { return true end, vtsls = function(_, opts) + LazyVim.lsp.on_attach(function(client, buffer) + client.commands["_typescript.moveToFileRefactoring"] = function(command, ctx) + ---@type string, string, lsp.Range + local action, uri, range = unpack(command.arguments) + + local function move(newf) + client.request("workspace/executeCommand", { + command = command.command, + arguments = { action, uri, range, newf }, + }) + end + + local fname = vim.uri_to_fname(uri) + client.request("workspace/executeCommand", { + command = "typescript.tsserverRequest", + arguments = { + "getMoveToRefactoringFileSuggestions", + { + file = fname, + startLine = range.start.line + 1, + startOffset = range.start.character + 1, + endLine = range["end"].line + 1, + endOffset = range["end"].character + 1, + }, + }, + }, function(_, result) + ---@type string[] + local files = result.body.files + table.insert(files, 1, "Enter new path...") + vim.ui.select(files, { + prompt = "Select move destination:", + format_item = function(f) + return vim.fn.fnamemodify(f, ":~:.") + end, + }, function(f) + if f and f:find("^Enter new path") then + vim.ui.input({ + prompt = "Enter move destination:", + default = vim.fn.fnamemodify(fname, ":h") .. "/", + completion = "file", + }, function(newf) + return newf and move(newf) + end) + elseif f then + move(f) + end + end) + end) + end + end, "vtsls") -- copy typescript settings to javascript opts.settings.javascript = vim.tbl_deep_extend("force", {}, opts.settings.typescript, opts.settings.javascript or {}) diff --git a/lua/lazyvim/plugins/extras/lang/yaml.lua b/lua/lazyvim/plugins/extras/lang/yaml.lua index b34e2a26..9a3aadb8 100644 --- a/lua/lazyvim/plugins/extras/lang/yaml.lua +++ b/lua/lazyvim/plugins/extras/lang/yaml.lua @@ -60,10 +60,8 @@ return { -- Neovim < 0.10 does not have dynamic registration for formatting if vim.fn.has("nvim-0.10") == 0 then LazyVim.lsp.on_attach(function(client, _) - if client.name == "yamlls" then - client.server_capabilities.documentFormattingProvider = true - end - end) + client.server_capabilities.documentFormattingProvider = true + end, "yamlls") end end, }, diff --git a/lua/lazyvim/plugins/formatting.lua b/lua/lazyvim/plugins/formatting.lua index 28dea8ed..0935f6b3 100644 --- a/lua/lazyvim/plugins/formatting.lua +++ b/lua/lazyvim/plugins/formatting.lua @@ -2,27 +2,10 @@ local M = {} ---@param opts ConformOpts function M.setup(_, opts) - for name, formatter in pairs(opts.formatters or {}) do - if type(formatter) == "table" then - ---@diagnostic disable-next-line: undefined-field - if formatter.extra_args then - ---@diagnostic disable-next-line: undefined-field - formatter.prepend_args = formatter.extra_args - LazyVim.deprecate( - ("opts.formatters.%s.extra_args"):format(name), - ("opts.formatters.%s.prepend_args"):format(name) - ) - end - end - end - for _, key in ipairs({ "format_on_save", "format_after_save" }) do if opts[key] then - LazyVim.warn( - ("Don't set `opts.%s` for `conform.nvim`.\n**LazyVim** will use the conform formatter automatically"):format( - key - ) - ) + local msg = "Don't set `opts.%s` for `conform.nvim`.\n**LazyVim** will use the conform formatter automatically" + LazyVim.warn(msg:format(key)) ---@diagnostic disable-next-line: no-unknown opts[key] = nil end diff --git a/lua/lazyvim/plugins/xtras.lua b/lua/lazyvim/plugins/xtras.lua index 8b4b2ec9..e636c255 100644 --- a/lua/lazyvim/plugins/xtras.lua +++ b/lua/lazyvim/plugins/xtras.lua @@ -2,13 +2,14 @@ local Config = require("lazyvim.config") -- Some extras need to be loaded before others local prios = { - ["lazyvim.plugins.extras.editor.aerial"] = 100, - ["lazyvim.plugins.extras.editor.outline"] = 100, - ["lazyvim.plugins.extras.editor.trouble-v3"] = 100, - ["lazyvim.plugins.extras.lang.typescript"] = 5, - ["lazyvim.plugins.extras.ui.edgy"] = 2, ["lazyvim.plugins.extras.test.core"] = 1, ["lazyvim.plugins.extras.dap.core"] = 1, + ["lazyvim.plugins.extras.ui.edgy"] = 2, + ["lazyvim.plugins.extras.lang.typescript"] = 5, + ["lazyvim.plugins.extras.formatting.prettier"] = 10, + -- default priority is 50 + ["lazyvim.plugins.extras.editor.aerial"] = 100, + ["lazyvim.plugins.extras.editor.outline"] = 100, } ---@type string[] @@ -24,8 +25,8 @@ if vim.tbl_contains(compat, v) then end table.sort(extras, function(a, b) - local pa = prios[a] or 10 - local pb = prios[b] or 10 + local pa = prios[a] or 50 + local pb = prios[b] or 50 if pa == pb then return a < b end diff --git a/lua/lazyvim/types.lua b/lua/lazyvim/types.lua index 52a340c9..a963ac42 100644 --- a/lua/lazyvim/types.lua +++ b/lua/lazyvim/types.lua @@ -5,3 +5,20 @@ vim.g = {} _G.lazyvim_docs = true _G.LazyVim = require("lazyvim.util") + +---@class vim.api.create_autocmd.callback.args +---@field id number +---@field event string +---@field group number? +---@field match string +---@field buf number +---@field file string +---@field data any + +---@class vim.api.keyset.create_autocmd.opts: vim.api.keyset.create_autocmd +---@field callback? fun(ev:vim.api.create_autocmd.callback.args):boolean? + +--- @param event any (string|array) Event(s) that will trigger the handler +--- @param opts vim.api.keyset.create_autocmd.opts +--- @return integer +function vim.api.nvim_create_autocmd(event, opts) end diff --git a/lua/lazyvim/util/init.lua b/lua/lazyvim/util/init.lua index 9b13b50d..d8f485ed 100644 --- a/lua/lazyvim/util/init.lua +++ b/lua/lazyvim/util/init.lua @@ -75,6 +75,12 @@ function M.has(plugin) return M.get_plugin(plugin) ~= nil end +---@param extra string +function M.has_extra(extra) + local modname = "lazyvim.plugins.extras." .. extra + return vim.tbl_contains(require("lazy.core.config").spec.modules, modname) +end + ---@param fn fun() function M.on_very_lazy(fn) vim.api.nvim_create_autocmd("User", { @@ -262,4 +268,17 @@ for _, level in ipairs({ "info", "warn", "error" }) do end end +local cache = {} ---@type table +---@generic T: fun() +---@param fn T +---@return T +function M.memoize(fn) + return function(...) + local key = vim.inspect({ ... }) + if cache[key] == nil then + cache[key] = fn(...) + end + return cache[key] + end +end return M diff --git a/lua/lazyvim/util/lsp.lua b/lua/lazyvim/util/lsp.lua index f1be8801..11877f1b 100644 --- a/lua/lazyvim/util/lsp.lua +++ b/lua/lazyvim/util/lsp.lua @@ -22,12 +22,13 @@ function M.get_clients(opts) end ---@param on_attach fun(client:vim.lsp.Client, buffer) -function M.on_attach(on_attach) +---@param name? string +function M.on_attach(on_attach, name) return 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) - if client then + if client and (not name or client.name == name) then return on_attach(client, buffer) end end, @@ -340,6 +341,7 @@ M.action = setmetatable({}, { ---@class LspCommand: lsp.ExecuteCommandParams ---@field open? boolean +---@field handler? lsp.Handler ---@param opts LspCommand function M.execute(opts) @@ -353,7 +355,7 @@ function M.execute(opts) params = params, }) else - return vim.lsp.buf_request(0, "workspace/executeCommand", params) + return vim.lsp.buf_request(0, "workspace/executeCommand", params, opts.handler) end end