Skip to content

Commit 9cf1323

Browse files
committed
Merge upstream: Merge pull request nvim-lua#1991 from nvim-lua/refactor/conform
2 parents 3fadba5 + f5b0e49 commit 9cf1323

2 files changed

Lines changed: 20 additions & 13 deletions

File tree

lua/kickstart/plugins/conform.lua

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ return {
88
keys = {
99
{
1010
'<leader>f',
11-
function() require('conform').format { async = true, lsp_format = 'fallback' } end,
11+
function() require('conform').format { async = true } end,
1212
mode = '',
1313
desc = '[F]ormat buffer',
1414
},
@@ -18,21 +18,23 @@ return {
1818
opts = {
1919
notify_on_error = false,
2020
format_on_save = function(bufnr)
21-
-- Disable "format_on_save lsp_fallback" for languages that don't
22-
-- have a well standardized coding style. You can add additional
23-
-- languages here or re-enable it for the disabled ones.
24-
local disable_filetypes = { c = true, cpp = true }
25-
if disable_filetypes[vim.bo[bufnr].filetype] then
26-
return nil
21+
-- You can specify filetypes to autoformat on save here:
22+
local enabled_filetypes = {
23+
-- lua = true,
24+
-- python = true,
25+
}
26+
if enabled_filetypes[vim.bo[bufnr].filetype] then
27+
return { timeout_ms = 500 }
2728
else
28-
return {
29-
timeout_ms = 500,
30-
lsp_format = 'fallback',
31-
}
29+
return nil
3230
end
3331
end,
32+
default_format_opts = {
33+
lsp_format = 'fallback', -- Use external formatters if configured below, otherwise use LSP formatting. Set to `false` to disable LSP formatting entirely.
34+
},
35+
-- You can also specify external formatters in here.
3436
formatters_by_ft = {
35-
lua = { 'stylua' },
37+
-- rust = { 'rustfmt' },
3638
-- Conform can also run multiple formatters sequentially
3739
-- python = { "isort", "black" },
3840
--

lua/kickstart/plugins/lspconfig.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ return {
138138
-- Special Lua Config, as recommended by neovim help docs
139139
lua_ls = {
140140
on_init = function(client)
141+
client.server_capabilities.documentFormattingProvider = false -- Disable formatting (formatting is done by stylua)
142+
141143
if client.workspace_folders then
142144
local path = client.workspace_folders[1].name
143145
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
@@ -159,8 +161,11 @@ return {
159161
},
160162
})
161163
end,
164+
---@type lspconfig.settings.lua_ls
162165
settings = {
163-
Lua = {},
166+
Lua = {
167+
format = { enable = false }, -- Disable formatting (formatting is done by stylua)
168+
},
164169
},
165170
},
166171
}

0 commit comments

Comments
 (0)