update conform formatting and lsp config
This commit is contained in:
parent
cf4b3e253b
commit
041c9fb929
2 changed files with 165 additions and 19 deletions
|
|
@ -1,23 +1,168 @@
|
||||||
{
|
{
|
||||||
plugins.conform-nvim = {
|
lib,
|
||||||
enable = true;
|
pkgs,
|
||||||
formatOnSave = {
|
...
|
||||||
lspFallback = true;
|
}: {
|
||||||
timeoutMs = 500;
|
config = {
|
||||||
};
|
extraConfigLuaPre =
|
||||||
notifyOnError = true;
|
# lua
|
||||||
formattersByFt = {
|
''
|
||||||
liquidsoap = ["liquidsoap-prettier"];
|
local slow_format_filetypes = {}
|
||||||
html = [["prettierd" "prettier"]];
|
|
||||||
css = [["prettierd" "prettier"]];
|
vim.api.nvim_create_user_command("FormatDisable", function(args)
|
||||||
javascript = [["prettierd" "prettier"]];
|
if args.bang then
|
||||||
typescript = [["prettierd" "prettier"]];
|
-- FormatDisable! will disable formatting just for this buffer
|
||||||
python = ["black"];
|
vim.b.disable_autoformat = true
|
||||||
lua = ["stylua"];
|
else
|
||||||
nix = ["alejandra"];
|
vim.g.disable_autoformat = true
|
||||||
markdown = [["prettierd" "prettier"]];
|
end
|
||||||
yaml = ["yamllint" "yamlfmt"];
|
end, {
|
||||||
terraform = ["terraform-fmt"];
|
desc = "Disable autoformat-on-save",
|
||||||
|
bang = true,
|
||||||
|
})
|
||||||
|
vim.api.nvim_create_user_command("FormatEnable", function()
|
||||||
|
vim.b.disable_autoformat = false
|
||||||
|
vim.g.disable_autoformat = false
|
||||||
|
end, {
|
||||||
|
desc = "Re-enable autoformat-on-save",
|
||||||
|
})
|
||||||
|
vim.api.nvim_create_user_command("FormatToggle", function(args)
|
||||||
|
if args.bang then
|
||||||
|
-- Toggle formatting for current buffer
|
||||||
|
vim.b.disable_autoformat = not vim.b.disable_autoformat
|
||||||
|
else
|
||||||
|
-- Toggle formatting globally
|
||||||
|
vim.g.disable_autoformat = not vim.g.disable_autoformat
|
||||||
|
end
|
||||||
|
end, {
|
||||||
|
desc = "Toggle autoformat-on-save",
|
||||||
|
bang = true,
|
||||||
|
})
|
||||||
|
'';
|
||||||
|
plugins.conform-nvim = {
|
||||||
|
enable = true;
|
||||||
|
formatOnSave = ''
|
||||||
|
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
|
||||||
|
'';
|
||||||
|
|
||||||
|
formatAfterSave = ''
|
||||||
|
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
|
||||||
|
'';
|
||||||
|
#formatOnSave = {
|
||||||
|
# lspFallback = true;
|
||||||
|
# timeoutMs = 500;
|
||||||
|
#};
|
||||||
|
notifyOnError = true;
|
||||||
|
formattersByFt = {
|
||||||
|
html = [
|
||||||
|
[
|
||||||
|
"prettierd"
|
||||||
|
"prettier"
|
||||||
|
]
|
||||||
|
];
|
||||||
|
css = [
|
||||||
|
[
|
||||||
|
"prettierd"
|
||||||
|
"prettier"
|
||||||
|
]
|
||||||
|
];
|
||||||
|
javascript = [
|
||||||
|
[
|
||||||
|
"prettierd"
|
||||||
|
"prettier"
|
||||||
|
]
|
||||||
|
];
|
||||||
|
typescript = [
|
||||||
|
[
|
||||||
|
"prettierd"
|
||||||
|
"prettier"
|
||||||
|
]
|
||||||
|
];
|
||||||
|
python = [
|
||||||
|
"black"
|
||||||
|
"isort"
|
||||||
|
];
|
||||||
|
lua = ["stylua"];
|
||||||
|
nix = ["alejandra"];
|
||||||
|
markdown = [
|
||||||
|
[
|
||||||
|
"prettierd"
|
||||||
|
"prettier"
|
||||||
|
]
|
||||||
|
];
|
||||||
|
yaml = [
|
||||||
|
[
|
||||||
|
"prettierd"
|
||||||
|
"prettier"
|
||||||
|
]
|
||||||
|
];
|
||||||
|
terraform = ["terraform_fmt"];
|
||||||
|
bash = [
|
||||||
|
"shellcheck"
|
||||||
|
"shellharden"
|
||||||
|
"shfmt"
|
||||||
|
];
|
||||||
|
json = ["jq"];
|
||||||
|
"_" = ["trim_whitespace"];
|
||||||
|
};
|
||||||
|
formatters = {
|
||||||
|
black = {
|
||||||
|
command = "${lib.getExe pkgs.black}";
|
||||||
|
};
|
||||||
|
isort = {
|
||||||
|
command = "${lib.getExe pkgs.isort}";
|
||||||
|
};
|
||||||
|
alejandra = {
|
||||||
|
command = "${lib.getExe pkgs.alejandra}";
|
||||||
|
};
|
||||||
|
jq = {
|
||||||
|
command = "${lib.getExe pkgs.jq}";
|
||||||
|
};
|
||||||
|
prettierd = {
|
||||||
|
command = "${lib.getExe pkgs.prettierd}";
|
||||||
|
};
|
||||||
|
stylua = {
|
||||||
|
command = "${lib.getExe pkgs.stylua}";
|
||||||
|
};
|
||||||
|
shellcheck = {
|
||||||
|
command = "${lib.getExe pkgs.shellcheck}";
|
||||||
|
};
|
||||||
|
shfmt = {
|
||||||
|
command = "${lib.getExe pkgs.shfmt}";
|
||||||
|
};
|
||||||
|
shellharden = {
|
||||||
|
command = "${lib.getExe pkgs.shellharden}";
|
||||||
|
};
|
||||||
|
#yamlfmt = {
|
||||||
|
# command = "${lib.getExe pkgs.yamlfmt}";
|
||||||
|
#};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
{
|
{
|
||||||
plugins = {
|
plugins = {
|
||||||
|
lsp-lines = {enable = true;};
|
||||||
lsp-format = {enable = true;};
|
lsp-format = {enable = true;};
|
||||||
lsp = {
|
lsp = {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue