nixvim/config/lsp/conform.nix

70 lines
1.6 KiB
Nix
Raw Permalink Normal View History

2024-10-14 03:56:12 +00:00
{ helpers, pkgs, ... }:
{
plugins.conform-nvim = {
enable = true;
2024-10-14 03:56:12 +00:00
settings = {
2024-11-03 14:03:01 +00:00
format_on_save = ''
function(bufnr)
if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then
return
end
if slow_format_filetypes[vim.bo[bufnr].filetype] then
return
end
local function on_format(err)
if err and err:match("timeout$") then
slow_format_filetypes[vim.bo[bufnr].filetype] = true
end
end
return { timeout_ms = 200, lsp_fallback = true }, on_format
end
'';
2024-10-14 03:56:12 +00:00
format_after_save = ''
function(bufnr)
if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then
return
end
if not slow_format_filetypes[vim.bo[bufnr].filetype] then
return
end
return { lsp_fallback = true }
end
'';
2024-10-14 03:56:12 +00:00
formatters_by_ft = {
python = [ "black" ];
c = [ "clang-format" ];
cpp = [ "clang-format" ];
cmake = [ "cmake_format" ];
nix = [ "nixfmt" ];
# Standalone scalafmt is too slow, so we use it as a fallback
scala = helpers.mkRaw ''
{ scalafmt, lsp_format = "prefer" }
'';
toml = [ "taplo" ];
yaml = [ "yq" ];
json = [ "jq" ];
};
};
};
extraPackages = with pkgs; [
black
clang-tools
cmake-format
jq
nixfmt-rfc-style
scalafmt
taplo
yq
];
2024-11-03 14:03:01 +00:00
extraConfigLuaPre = ''
local slow_format_filetypes = { "scala" }
'';
}