Skip to content

Commit

Permalink
feat(nvim): using conform.nvim
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
  • Loading branch information
caarlos0 committed Oct 2, 2023
1 parent 4067ea4 commit a83c6e3
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 43 deletions.
1 change: 1 addition & 0 deletions modules/neovim/config/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,4 @@ require("Comment").setup()
require("user.treesitter")
require("user.debug")
require("user.other")
require("user.conform")
29 changes: 14 additions & 15 deletions modules/neovim/config/lua/lsp_autocommands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ local M = {}
---@param client table Client object
---@param bufnr number
M.on_attach = function(client, bufnr)
-- what are the chances of a lsp supporting code actions but not supporting formatting?
if client.server_capabilities.codeActionProvider and client.name ~= "lua_ls" then
vim.api.nvim_create_autocmd({ "BufWritePre" }, {
buffer = bufnr,
Expand All @@ -59,20 +58,20 @@ M.on_attach = function(client, bufnr)
})
end

if client.server_capabilities.documentFormattingProvider then
vim.api.nvim_create_autocmd({ "BufWritePre" }, {
buffer = bufnr,
callback = function()
vim.lsp.buf.format({
bufnr = bufnr,
filter = function(cli)
return cli.id == client.id
end,
})
end,
group = group,
})
end
-- if client.server_capabilities.documentFormattingProvider then
-- vim.api.nvim_create_autocmd({ "BufWritePre" }, {
-- buffer = bufnr,
-- callback = function()
-- vim.lsp.buf.format({
-- bufnr = bufnr,
-- filter = function(cli)
-- return cli.id == client.id
-- end,
-- })
-- end,
-- group = group,
-- })
-- end

if client.server_capabilities.codeLensProvider then
vim.api.nvim_create_autocmd({ "BufEnter", "CursorHold", "InsertLeave" }, {
Expand Down
21 changes: 21 additions & 0 deletions modules/neovim/config/lua/user/conform.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
local prettier = { { "prettierd", "prettier" } }
local conform = require("conform")
conform.setup({
formatters_by_ft = {
lua = { "stylua" },
javascript = prettier,
markdown = prettier,
html = prettier,
css = prettier,
nix = { "nixpkgs_fmt" },
},
})

vim.api.nvim_create_autocmd("BufWritePre", {
pattern = "*",
callback = function(args)
conform.format({ bufnr = args.buf })
end,
})

vim.o.formatexpr = "v:lua.require'conform'.formatexpr()"
24 changes: 0 additions & 24 deletions modules/neovim/config/lua/user/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -198,30 +198,6 @@ lspconfig.taplo.setup({
on_attach = on_attach,
})

local prettier = require("efmls-configs.formatters.prettier")
local stylua = require("efmls-configs.formatters.stylua")
local languages = {
lua = { stylua },
css = { prettier },
javascript = { prettier },
html = { prettier },
markdown = { prettier },
}

lspconfig.efm.setup({
capabilities = capabilities,
on_attach = on_attach,
filetypes = vim.tbl_keys(languages),
settings = {
rootMarkers = { ".git/" },
languages = languages,
},
init_options = {
documentFormatting = true,
documentRangeFormatting = true,
},
})

local float_config = {
focusable = false,
style = "minimal",
Expand Down
7 changes: 4 additions & 3 deletions modules/neovim/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ in

# coding
nvim-lspconfig
efmls-configs-nvim
(fromGitHub "stevearc" "conform.nvim" "v3.7.2"
"sha256-Pk0dq4PNvmlHPWIMT02C+Fm8+fwEkCCZIyt47PcKyWA=")
nvim-cmp
cmp-buffer
cmp-path
Expand Down Expand Up @@ -115,8 +116,8 @@ in
nvim-treesitter-endwise
other-nvim
# treesitter injections for home-manager
(fromGitHub "calops" "hmts.nvim" "v0.1.0"
"sha256-SBNTtuzwSmGgwALD/JqLwXGLow+Prn7dJrQNODPeOAY=")
(fromGitHub "calops" "hmts.nvim" "v1.2.2"
"sha256-jUuztOqNBltC3axa7s3CPJz9Cmukfwkf846+Z/gAxCU=")

# debug
nvim-dap
Expand Down
1 change: 0 additions & 1 deletion modules/pkgs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
clang-tools # clangd lsp
delve
dockerfile-language-server-nodejs
efm-langserver
gofumpt
golangci-lint
golangci-lint-langserver
Expand Down

0 comments on commit a83c6e3

Please sign in to comment.