Skip to content

Commit f5b0e49

Browse files
authored
Merge pull request #1991 from nvim-lua/refactor/conform
Refactor/conform
2 parents 648471c + ce353a9 commit f5b0e49

1 file changed

Lines changed: 20 additions & 13 deletions

File tree

init.lua

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,8 @@ require('lazy').setup({
616616
-- Special Lua Config, as recommended by neovim help docs
617617
lua_ls = {
618618
on_init = function(client)
619+
client.server_capabilities.documentFormattingProvider = false -- Disable formatting (formatting is done by stylua)
620+
619621
if client.workspace_folders then
620622
local path = client.workspace_folders[1].name
621623
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({
637639
},
638640
})
639641
end,
642+
---@type lspconfig.settings.lua_ls
640643
settings = {
641-
Lua = {},
644+
Lua = {
645+
format = { enable = false }, -- Disable formatting (formatting is done by stylua)
646+
},
642647
},
643648
},
644649
}
@@ -671,7 +676,7 @@ require('lazy').setup({
671676
keys = {
672677
{
673678
'<leader>f',
674-
function() require('conform').format { async = true, lsp_format = 'fallback' } end,
679+
function() require('conform').format { async = true } end,
675680
mode = '',
676681
desc = '[F]ormat buffer',
677682
},
@@ -681,21 +686,23 @@ require('lazy').setup({
681686
opts = {
682687
notify_on_error = false,
683688
format_on_save = function(bufnr)
684-
-- Disable "format_on_save lsp_fallback" for languages that don't
685-
-- have a well standardized coding style. You can add additional
686-
-- languages here or re-enable it for the disabled ones.
687-
local disable_filetypes = { c = true, cpp = true }
688-
if disable_filetypes[vim.bo[bufnr].filetype] then
689-
return nil
689+
-- You can specify filetypes to autoformat on save here:
690+
local enabled_filetypes = {
691+
-- lua = true,
692+
-- python = true,
693+
}
694+
if enabled_filetypes[vim.bo[bufnr].filetype] then
695+
return { timeout_ms = 500 }
690696
else
691-
return {
692-
timeout_ms = 500,
693-
lsp_format = 'fallback',
694-
}
697+
return nil
695698
end
696699
end,
700+
default_format_opts = {
701+
lsp_format = 'fallback', -- Use external formatters if configured below, otherwise use LSP formatting. Set to `false` to disable LSP formatting entirely.
702+
},
703+
-- You can also specify external formatters in here.
697704
formatters_by_ft = {
698-
lua = { 'stylua' },
705+
-- rust = { 'rustfmt' },
699706
-- Conform can also run multiple formatters sequentially
700707
-- python = { "isort", "black" },
701708
--

0 commit comments

Comments
 (0)