Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
},
},
},
}
Expand Down Expand Up @@ -671,7 +676,7 @@ require('lazy').setup({
keys = {
{
'<leader>f',
function() require('conform').format { async = true, lsp_format = 'fallback' } end,
function() require('conform').format { async = true } end,
mode = '',
desc = '[F]ormat buffer',
},
Expand All @@ -681,21 +686,23 @@ 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
-- 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 {
timeout_ms = 500,
lsp_format = 'fallback',
}
return nil
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.
},
Comment on lines +700 to +702
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the theme of this PR is to reduce unexpected formatting on save, I think these lines should be removed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah but then the lua formatting will not work. Hmm not sure.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway, that comment is not correct. Fallback means using LSP when no other formatters are available, not prioritizing it.

See conform documentation here

Copy link
Copy Markdown
Collaborator Author

@oriori1703 oriori1703 Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

those lines were added just so you don't have to repeat it in 2 places (previously it was in 693 and 674)

-- 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" },
--
Expand Down
Loading