pkgs(nixvim): Add some language supports for formatting

This commit is contained in:
ulic-youthlic 2025-07-13 06:04:55 +08:00
parent 37914d6957
commit d242144445
Signed by: youthlic
GPG key ID: 63E86C3C14A0D721
10 changed files with 352 additions and 0 deletions

View file

@ -0,0 +1,31 @@
{
lib,
pkgs,
...
}: {
plugins.conform-nvim.settings = {
formatters_by_ft.c = {
__unkeyed-1 = "clang-format";
lsp_format = "fallback";
};
formatters.clang-format = {
__raw =
#lua
''
function()
local defaultFormatter = require("conform.formatters.clang-format")
return vim.tbl_extend("force", defaultFormatter, {
command = function()
local exe = vim.fn["exepath"]("clang-format")
if exe ~= "" then
return exe
else
return "${lib.getExe' pkgs.clang-tools "clang-format"}"
end
end
})
end
'';
};
};
}

View file

@ -0,0 +1,31 @@
{
lib,
pkgs,
...
}: {
plugins.conform-nvim.settings = {
formatters_by_ft.cpp = {
__unkeyed-1 = "clang-format";
lsp_format = "fallback";
};
formatters.clang-format = {
__raw =
#lua
''
function()
local defaultFormatter = require("conform.formatters.clang-format")
return vim.tbl_extend("force", defaultFormatter, {
command = function()
local exe = vim.fn["exepath"]("clang-format")
if exe ~= "" then
return exe
else
return "${lib.getExe' pkgs.clang-tools "clang-format"}"
end
end
})
end
'';
};
};
}

View file

@ -0,0 +1,30 @@
{
lib,
pkgs,
...
}: {
plugins.conform-nvim.settings = {
formatters_by_ft.json = {
__unkeyed-1 = "deno_fmt";
};
formatters.deno_fmt = {
__raw =
#lua
''
function()
local defaultFormatter = require("conform.formatters.deno_fmt")
return vim.tbl_extend("force", defaultFormatter, {
command = function()
local exe = vim.fn["exepath"]("deno")
if exe ~= "" then
return exe
else
return "${lib.getExe pkgs.deno}"
end
end
})
end
'';
};
};
}

View file

@ -0,0 +1,31 @@
{
lib,
pkgs,
...
}: {
plugins.conform-nvim.settings = {
formatters_by_ft.lua = {
__unkeyed-1 = "stylua";
lsp_format = "fallback";
};
formatters.stylua = {
__raw =
#lua
''
function()
local defaultFormatter = require("conform.formatters.stylua")
return vim.tbl_extend("force", defaultFormatter, {
command = function()
local exe = vim.fn["exepath"]("stylua")
if exe ~= "" then
return exe
else
return "${lib.getExe pkgs.stylua}"
end
end
})
end
'';
};
};
}

View file

@ -0,0 +1,30 @@
{
lib,
pkgs,
...
}: {
plugins.conform-nvim.settings = {
formatters_by_ft.markdown = {
__unkeyed-1 = "deno_fmt";
};
formatters.deno_fmt = {
__raw =
#lua
''
function()
local defaultFormatter = require("conform.formatters.deno_fmt")
return vim.tbl_extend("force", defaultFormatter, {
command = function()
local exe = vim.fn["exepath"]("deno")
if exe ~= "" then
return exe
else
return "${lib.getExe pkgs.deno}"
end
end
})
end
'';
};
};
}

View file

@ -0,0 +1,53 @@
{
lib,
pkgs,
...
}: {
plugins.conform-nvim.settings = {
formatters_by_ft.nix = {
__unkeyed-1 = "alejandra";
__unkeyed-2 = "injected";
lsp_format = "fallback";
};
formatters = {
alejandra = {
__raw =
#lua
''
function()
local defaultFormatter = require("conform.formatters.alejandra")
return vim.tbl_extend("force", defaultFormatter, {
command = function()
local exe = vim.fn["exepath"]("alejandra")
if exe ~= "" then
return exe
else
return "${lib.getExe pkgs.alejandra}"
end
end
})
end
'';
};
nixfmt = {
__raw =
#lua
''
function()
local defaultFormatter = require("conform.formatters.nixfmt")
return vim.tbl_extend("force", defaultFormatter, {
command = function()
local exe = vim.fn["exepath"]("nixfmt")
if exe ~= "" then
return exe
else
return "${lib.getExe pkgs.nixfmt-rfc-style}"
end
end
})
end
'';
};
};
};
}

View file

@ -0,0 +1,53 @@
{
lib,
pkgs,
...
}: {
plugins.conform-nvim.settings = {
formatters_by_ft.python = {
__unkeyed-1 = "ruff_format";
__unkeyed-2 = "ruff_organize_imports";
lsp_format = "fallback";
};
formatters = {
ruff_organize_imports = {
__raw =
#lua
''
function()
local defaultFormatter = require("conform.formatters.ruff_organize_imports")
return vim.tbl_extend("force", defaultFormatter, {
command = function()
local exe = vim.fn["exepath"]("ruff")
if exe ~= "" then
return exe
else
return "${lib.getExe pkgs.ruff}"
end
end
})
end
'';
};
ruff_format = {
__raw =
#lua
''
function()
local defaultFormatter = require("conform.formatters.ruff_format")
return vim.tbl_extend("force", defaultFormatter, {
command = function()
local exe = vim.fn["exepath"]("ruff")
if exe ~= "" then
return exe
else
return "${lib.getExe pkgs.ruff}"
end
end
})
end
'';
};
};
};
}

View file

@ -0,0 +1,31 @@
{
lib,
pkgs,
...
}: {
plugins.conform-nvim.settings = {
formatters_by_ft.rust = {
__unkeyed-1 = "rustfmt";
lsp_format = "fallback";
};
formatters.rustfmt = {
__raw =
#lua
''
function()
local defaultFormatter = require("conform.formatters.rustfmt")
return vim.tbl_extend("force", defaultFormatter, {
command = function()
local exe = vim.fn["exepath"]("rustfmt")
if exe ~= "" then
return exe
else
return "${lib.getExe pkgs.rustfmt}"
end
end
})
end
'';
};
};
}

View file

@ -0,0 +1,32 @@
{
lib,
pkgs,
...
}: {
plugins.conform-nvim.settings = {
formatters_by_ft.toml = {
__unkeyed-1 = "taplo";
lsp_format = "fallback";
};
formatters.taplo = {
__raw =
#lua
''
function()
local defaultFormatter = require("conform.formatters.taplo")
return vim.tbl_extend("force", defaultFormatter, {
command = function()
local exe = vim.fn["exepath"]("taplo")
if exe ~= "" then
return exe
else
return "${lib.getExe pkgs.taplo}"
end
end,
args = { "format", "-o", "reorder_keys=true", "-o", "reorder_inline_tables=true", "-o", "reorder_arrays=true", "-" },
})
end
'';
};
};
}

View file

@ -0,0 +1,30 @@
{
lib,
pkgs,
...
}: {
plugins.conform-nvim.settings = {
formatters_by_ft.yaml = {
__unkeyed-1 = "deno_fmt";
};
formatters.deno_fmt = {
__raw =
#lua
''
function()
local defaultFormatter = require("conform.formatters.deno_fmt")
return vim.tbl_extend("force", defaultFormatter, {
command = function()
local exe = vim.fn["exepath"]("deno")
if exe ~= "" then
return exe
else
return "${lib.getExe pkgs.deno}"
end
end
})
end
'';
};
};
}