Skip to content

Commit 7aacf4d

Browse files
oriori1703PaulFinch
authored andcommitted
Use stylua as an lsp formatter instead of an external formatter
1 parent 7a2d98a commit 7aacf4d

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

init.lua

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,8 @@ require('lazy').setup({
622622
-- Special Lua Config, as recommended by neovim help docs
623623
lua_ls = {
624624
on_init = function(client)
625+
client.server_capabilities.documentFormattingProvider = false -- Disable formatting (formatting is done by stylua)
626+
625627
if client.workspace_folders then
626628
local path = client.workspace_folders[1].name
627629
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
@@ -643,8 +645,11 @@ require('lazy').setup({
643645
},
644646
})
645647
end,
648+
---@type lspconfig.settings.lua_ls
646649
settings = {
647-
Lua = {},
650+
Lua = {
651+
format = { enable = false }, -- Disable formatting (formatting is done by stylua)
652+
},
648653
},
649654
},
650655
}
@@ -686,7 +691,7 @@ require('lazy').setup({
686691
keys = {
687692
{
688693
'<leader>f',
689-
function() require('conform').format { async = true, lsp_format = 'fallback' } end,
694+
function() require('conform').format { async = true } end,
690695
mode = '',
691696
desc = '[F]ormat buffer',
692697
},
@@ -703,14 +708,15 @@ require('lazy').setup({
703708
if disable_filetypes[vim.bo[bufnr].filetype] then
704709
return nil
705710
else
706-
return {
707-
timeout_ms = 500,
708-
lsp_format = 'fallback',
709-
}
711+
return { timeout_ms = 500 }
710712
end
711713
end,
714+
default_format_opts = {
715+
lsp_format = 'fallback', -- Use external formatters if configured below, otherwise use LSP formatting. Set to `false` to disable LSP formatting entirely.
716+
},
717+
-- You can also specify external formatters in here.
712718
formatters_by_ft = {
713-
lua = { 'stylua' },
719+
-- rust = { 'rustfmt' },
714720
-- Conform can also run multiple formatters sequentially
715721
-- python = { "isort", "black" },
716722
--

0 commit comments

Comments
 (0)