From 459b86865e9e81235c9db3be553d107adac5f72f Mon Sep 17 00:00:00 2001 From: orip Date: Sun, 12 Apr 2026 19:38:37 +0300 Subject: [PATCH 1/2] Use stylua as an lsp formatter instead of an external formatter --- init.lua | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/init.lua b/init.lua index b56ce29814c..dea2fccf8c6 100644 --- a/init.lua +++ b/init.lua @@ -616,6 +616,8 @@ require('lazy').setup({ -- Special Lua Config, as recommended by neovim help docs lua_ls = { on_init = function(client) + client.server_capabilities.documentFormattingProvider = false -- Disable formatting (formatting is done by stylua) + if client.workspace_folders then local path = client.workspace_folders[1].name if path ~= vim.fn.stdpath 'config' and (vim.uv.fs_stat(path .. '/.luarc.json') or vim.uv.fs_stat(path .. '/.luarc.jsonc')) then return end @@ -637,8 +639,11 @@ require('lazy').setup({ }, }) end, + ---@type lspconfig.settings.lua_ls settings = { - Lua = {}, + Lua = { + format = { enable = false }, -- Disable formatting (formatting is done by stylua) + }, }, }, } @@ -671,7 +676,7 @@ require('lazy').setup({ keys = { { 'f', - function() require('conform').format { async = true, lsp_format = 'fallback' } end, + function() require('conform').format { async = true } end, mode = '', desc = '[F]ormat buffer', }, @@ -688,14 +693,15 @@ require('lazy').setup({ if disable_filetypes[vim.bo[bufnr].filetype] then return nil else - return { - timeout_ms = 500, - lsp_format = 'fallback', - } + return { timeout_ms = 500 } end end, + default_format_opts = { + lsp_format = 'fallback', -- Use external formatters if configured below, otherwise use LSP formatting. Set to `false` to disable LSP formatting entirely. + }, + -- You can also specify external formatters in here. formatters_by_ft = { - lua = { 'stylua' }, + -- rust = { 'rustfmt' }, -- Conform can also run multiple formatters sequentially -- python = { "isort", "black" }, -- From ce353a9b0e3c47d27784509217200818f522329e Mon Sep 17 00:00:00 2001 From: orip Date: Sun, 12 Apr 2026 22:33:59 +0300 Subject: [PATCH 2/2] Change format_on_save to a whitelist instead of a blacklist --- init.lua | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/init.lua b/init.lua index dea2fccf8c6..600258db910 100644 --- a/init.lua +++ b/init.lua @@ -686,14 +686,15 @@ require('lazy').setup({ opts = { notify_on_error = false, format_on_save = function(bufnr) - -- Disable "format_on_save lsp_fallback" for languages that don't - -- have a well standardized coding style. You can add additional - -- languages here or re-enable it for the disabled ones. - local disable_filetypes = { c = true, cpp = true } - if disable_filetypes[vim.bo[bufnr].filetype] then - return nil - else + -- You can specify filetypes to autoformat on save here: + local enabled_filetypes = { + -- lua = true, + -- python = true, + } + if enabled_filetypes[vim.bo[bufnr].filetype] then return { timeout_ms = 500 } + else + return nil end end, default_format_opts = {