vim: conform

This commit is contained in:
Casper V. Kristensen 2024-11-15 02:07:58 +01:00
parent ef62607ad1
commit 110d9b26e8
2 changed files with 44 additions and 17 deletions

View file

@ -34,6 +34,6 @@
wget wget
whois whois
wireguard-tools wireguard-tools
yq yq-go
]; ];
} }

View file

@ -256,10 +256,6 @@
highlight = { highlight = {
enable = true, enable = true,
}, },
-- Indentation based on treesitter
indent = {
enable = true,
},
}) })
''; '';
} }
@ -487,7 +483,7 @@
anchor_bias = "above", anchor_bias = "above",
-- Keep open until leaving insert mode. -- Keep open until leaving insert mode.
-- Default: { CursorMoved, CursorMovedI, InsertCharPre }. -- Default: { CursorMoved, CursorMovedI, InsertCharPre }.
close_events = { "CursorMoved", }, close_events = {"CursorMoved"},
-- Make floating window unfocusable. Allows updating parameter -- Make floating window unfocusable. Allows updating parameter
-- highlight with another <C-s> rather than focusing the window. -- highlight with another <C-s> rather than focusing the window.
focusable = false, focusable = false,
@ -502,7 +498,6 @@
vim.keymap.set("n", "gD", vim.lsp.buf.declaration) vim.keymap.set("n", "gD", vim.lsp.buf.declaration)
vim.keymap.set("n", "gy", vim.lsp.buf.type_definition) vim.keymap.set("n", "gy", vim.lsp.buf.type_definition)
vim.keymap.set("n", "gI", ts.lsp_implementations) vim.keymap.set("n", "gI", ts.lsp_implementations)
vim.keymap.set("n", "<Leader>gq", vim.lsp.buf.format)
-- TODO: This becomes default in newer neovim? -- TODO: This becomes default in newer neovim?
vim.keymap.set("n", "gra", vim.lsp.buf.code_action) vim.keymap.set("n", "gra", vim.lsp.buf.code_action)
@ -525,13 +520,6 @@
-- https://github.com/nix-community/nixd -- https://github.com/nix-community/nixd
lspconfig.nixd.setup({ lspconfig.nixd.setup({
capabilities = capabilities, capabilities = capabilities,
settings = {
nixd = {
formatting = {
command = {"${pkgs.alejandra}/bin/alejandra"},
},
},
},
}) })
-- https://docs.basedpyright.com -- https://docs.basedpyright.com
@ -687,6 +675,40 @@
''; '';
} }
# Lightweight yet powerful formatter plugin for Neovim.
# https://github.com/stevearc/conform.nvim
{
plugin = conform-nvim;
type = "lua";
config =
# lua
''
-- TODO: injected language formatting (treesitter code blocks)
local conform = require("conform")
conform.setup({
formatters_by_ft = {
-- Use conform built-ins on all ("*") filetypes
["*"] = {"trim_newlines", "trim_whitespace"},
css = {"prettier"},
graphql = {"prettier"},
html = {"prettier"},
javascript = {"prettier"},
json = {"prettier"},
markdown = {"prettier"},
nix = {"alejandra"},
-- Ruff follows the project's pyproject.toml/ruff.toml
python = {"ruff_fix", "ruff_organize_imports", "ruff_format"},
terraform = {"tofu_fmt"},
toml = {"taplo"},
typescript = {"prettier"},
yaml = {"prettier"},
},
})
vim.o.formatexpr = "v:lua.require'conform'.formatexpr()"
vim.keymap.set("n", "<Leader>gq", conform.format)
'';
}
# Indentation guides. # Indentation guides.
# https://github.com/lukas-reineke/indent-blankline.nvim # https://github.com/lukas-reineke/indent-blankline.nvim
{ {
@ -883,9 +905,14 @@
} }
]; ];
extraPackages = [ extraPackages = [
nixpkgs-unstable.legacyPackages.${pkgs.system}.basedpyright nixpkgs-unstable.legacyPackages.${pkgs.system}.basedpyright # lsp
pkgs.nixd nixpkgs-unstable.legacyPackages.${pkgs.system}.ruff # lsp/conform
pkgs.yaml-language-server pkgs.alejandra # conform
pkgs.nixd # lsp
pkgs.nodePackages.prettier # conform
pkgs.opentofu # conform
pkgs.taplo # conform
pkgs.yaml-language-server # lsp
]; ];
extraLuaPackages = ps: []; extraLuaPackages = ps: [];
extraPython3Packages = ps: []; extraPython3Packages = ps: [];