2024-08-24 23:36:19 -07:00
|
|
|
# Code formatters
|
2024-09-02 18:28:53 -07:00
|
|
|
{ pkgs, ... }:
|
|
|
|
{
|
2024-08-24 23:36:19 -07:00
|
|
|
extraPackages = with pkgs; [
|
2024-09-02 18:25:15 -07:00
|
|
|
# TS/JS, Markdown, TOML, JSON, etc
|
2024-08-24 23:36:19 -07:00
|
|
|
nodePackages.prettier
|
|
|
|
|
|
|
|
# Rust
|
|
|
|
rustfmt
|
|
|
|
|
|
|
|
# Nix
|
2024-09-02 18:25:15 -07:00
|
|
|
nixfmt-rfc-style
|
2024-08-24 23:36:19 -07:00
|
|
|
|
|
|
|
# Python
|
|
|
|
black
|
|
|
|
|
|
|
|
# Lua
|
|
|
|
stylua
|
|
|
|
|
|
|
|
# Haskell
|
|
|
|
haskellPackages.fourmolu
|
|
|
|
|
2024-09-11 00:54:12 -07:00
|
|
|
taplo
|
|
|
|
|
2024-09-27 15:04:40 -07:00
|
|
|
typstyle
|
2024-08-24 23:36:19 -07:00
|
|
|
# Misc
|
2024-09-02 18:25:15 -07:00
|
|
|
# codespell
|
2024-08-24 23:36:19 -07:00
|
|
|
];
|
|
|
|
|
|
|
|
plugins.conform-nvim = {
|
|
|
|
enable = true;
|
2024-09-16 23:48:33 -07:00
|
|
|
# because combinePlugins.enable = true, the collision of `doc` is
|
|
|
|
# unavoidable. this renames them.
|
|
|
|
package = pkgs.vimPlugins.conform-nvim.overrideAttrs (oldAttrs: {
|
|
|
|
postInstall =
|
|
|
|
(oldAttrs.postInstall or "")
|
|
|
|
+ ''
|
|
|
|
mv $out/doc/recipes.md $out/doc/conform-nvim_recipes.md
|
|
|
|
'';
|
|
|
|
});
|
|
|
|
# package = pkgs.vimPlugins.conform-nvim;
|
2024-08-24 23:36:19 -07:00
|
|
|
settings = {
|
2024-09-17 15:51:01 -07:00
|
|
|
# format_on_save = {
|
|
|
|
# timeoutMs = 500;
|
|
|
|
# lspFallback = true;
|
|
|
|
# };
|
|
|
|
format_on_save = # Lua
|
|
|
|
''
|
|
|
|
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 = 500, lsp_fallback = true }, on_format
|
|
|
|
return { timeout_ms = 500, lsp_fallback = true }
|
|
|
|
end
|
|
|
|
'';
|
|
|
|
format_after_save = # Lua
|
|
|
|
''
|
|
|
|
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-08-24 23:36:19 -07:00
|
|
|
formatters_by_ft = {
|
2024-09-02 18:28:53 -07:00
|
|
|
lua = [ "stylua" ];
|
|
|
|
python = [ "black" ];
|
|
|
|
nix = [ "nixfmt" ];
|
|
|
|
svelte = [ "prettier" ];
|
|
|
|
rust = [ "rustfmt" ];
|
|
|
|
haskell = [ "fourmolu" ];
|
2024-09-11 00:54:12 -07:00
|
|
|
toml = [ "taplo" ];
|
2024-09-02 18:28:53 -07:00
|
|
|
json = [ "prettier" ];
|
|
|
|
markdown = [ "prettier" ];
|
|
|
|
yaml = [ "prettier" ];
|
|
|
|
html = [ "prettier" ];
|
|
|
|
javascript = [ "prettier" ];
|
|
|
|
typescript = [ "prettier" ];
|
2024-09-27 15:02:17 -07:00
|
|
|
typst = [ "typstyle" ];
|
2024-09-02 18:25:15 -07:00
|
|
|
# "*" = ["codespell"];
|
2024-09-02 18:28:53 -07:00
|
|
|
"_" = [ "trim_whitespace" ];
|
2024-08-24 23:36:19 -07:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|