From 05fabaf9972efca3d9c7c33b55b254f732416d6f Mon Sep 17 00:00:00 2001 From: Pratik Tripathy Date: Mon, 31 Mar 2025 11:39:06 +0530 Subject: [PATCH] feat(nvim-formatting): Auto install required formatters through mason - Sort configurations by ft - Add formatters to lsp so they can be auto installed by mason --- .../nvim/lua/plugins/code-formatting.lua | 31 ++++++++++--------- common/.config/nvim/lua/plugins/code-lsp.lua | 28 ++++++++++------- 2 files changed, 33 insertions(+), 26 deletions(-) diff --git a/common/.config/nvim/lua/plugins/code-formatting.lua b/common/.config/nvim/lua/plugins/code-formatting.lua index 8855b49..d2e8b2e 100644 --- a/common/.config/nvim/lua/plugins/code-formatting.lua +++ b/common/.config/nvim/lua/plugins/code-formatting.lua @@ -6,22 +6,23 @@ return { event = { "BufWritePre" }, opts = { formatters_by_ft = { - cs = { "csharpier" }, - javascript = { "prettierd", "prettier", stop_after_first = true }, - typescript = { "prettierd", "prettier", stop_after_first = true }, - javascriptreact = { "prettierd", "prettier", stop_after_first = true }, - typescriptreact = { "prettierd", "prettier", stop_after_first = true }, - svelte = { "prettierd", "prettier", stop_after_first = true }, - css = { "prettierd", "prettier", stop_after_first = true }, - html = { "prettierd", "prettier", stop_after_first = true }, - json = { "prettierd", "prettier", stop_after_first = true }, - graphql = { "prettierd", "prettier", stop_after_first = true }, - yaml = { "yamlfmt", "prettierd", stop_after_first = true }, - markdown = { "markdownlint", "markdown-toc" }, - lua = { "stylua" }, - python = { "black" }, - sh = { "shfmt", "shellharden", stop_after_first = true }, bash = { "shfmt", "shellharden", stop_after_first = true }, + cs = { "csharpier" }, + css = { "prettierd", "prettier", stop_after_first = true }, + graphql = { "prettierd", "prettier", stop_after_first = true }, + html = { "prettierd", "prettier", stop_after_first = true }, + javascript = { "prettierd", "prettier", stop_after_first = true }, + javascriptreact = { "prettierd", "prettier", stop_after_first = true }, + json = { "prettierd", "prettier", stop_after_first = true }, + lua = { "stylua" }, + markdown = { "markdownlint", "markdown-toc" }, + python = { "black" }, + rust = { "rustfmt" }, + sh = { "shfmt", "shellharden", stop_after_first = true }, + svelte = { "prettierd", "prettier", stop_after_first = true }, + typescript = { "prettierd", "prettier", stop_after_first = true }, + typescriptreact = { "prettierd", "prettier", stop_after_first = true }, + yaml = { "yamlfmt", "prettierd", stop_after_first = true }, zsh = { "shfmt", "shellharden", stop_after_first = true }, ["_"] = { "trim_whitespace" }, }, diff --git a/common/.config/nvim/lua/plugins/code-lsp.lua b/common/.config/nvim/lua/plugins/code-lsp.lua index d8a320a..e8367b0 100644 --- a/common/.config/nvim/lua/plugins/code-lsp.lua +++ b/common/.config/nvim/lua/plugins/code-lsp.lua @@ -219,21 +219,27 @@ return { -- Add completion capabilities local capabilities = vim.lsp.protocol.make_client_capabilities() - capabilities = vim.tbl_deep_extend("force", capabilities, require("blink.cmp").get_lsp_capabilities()) - -- Add other tools here that you want Mason to install for you + -- TODO: Remove this when we get neovim 0.11 + capabilities = require("blink.cmp").get_lsp_capabilities(capabilities) + + -- Add other (other than LSP servers) tools here that you want Mason to install for you + -- Which means: formatters and debuggers local ensure_installed = vim.tbl_keys(servers or {}) vim.list_extend(ensure_installed, { - "stylua", - "bash-language-server", - "html-lsp", - "css-lsp", - "dockerfile-language-server", - "python-lsp-server", - "markdownlint", + "black", -- Python formatter + "csharpier", -- C# formatter + "djlint", -- Handlebar Formatter "markdown-toc", - "csharpier", - "netcoredbg", + "markdownlint", + "netcoredbg", -- C# Debugger + "prettier", + "prettierd", + "shellharden", + "shfmt", + "stylua", + "trivy", -- Vulnerability Linter + "yamlfmt", }) -- TODO: Remove all installations through Mason