Skip to content

Commit bc01c75

Browse files
stop using none-ls, use conform
it is easier to use conform, and easier to configure it. It has autopep8, ruff and other formatters that are not found in none-ls. If I use none-ls, I have to configure extra, kinda time consuming sometimes
1 parent f77f568 commit bc01c75

File tree

3 files changed

+54
-16
lines changed

3 files changed

+54
-16
lines changed

lua/modules/lsp/conform.lua

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
require("conform").setup({
2+
formatters_by_ft = {
3+
lua = { "stylua" },
4+
-- Uses ruff. If ruff unavailable, use isot and black
5+
python = function(bufnr)
6+
if require("conform").get_formatter_info("ruff_format", bufnr).available then
7+
return { "ruff_format", "ruff_organize_imports" }
8+
else
9+
return { "isort", "black" }
10+
end
11+
end,
12+
rust = { "rustfmt", lsp_format = "fallback" },
13+
cpp = { "clang-format" }
14+
},
15+
16+
format_on_save = {
17+
-- timeout_ms = 200,
18+
-- async = true,
19+
lsp_format = "fallback",
20+
},
21+
})
22+
23+
vim.api.nvim_create_autocmd("BufWritePre", {
24+
pattern = "*",
25+
callback = function(args)
26+
require("conform").format({ bufnr = args.buf })
27+
end,
28+
})

lua/modules/lsp/null-ls.lua

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,23 @@ null_ls.setup({
1313
formatting.stylua,
1414
-- formatting.rustfmt,
1515
formatting.clang_format,
16-
formatting.black.with({
17-
extra_args = function(_)
18-
return {
19-
"--fast",
20-
"--quiet",
21-
"--target-version",
22-
"py38",
23-
"py39",
24-
"py310",
25-
"py311",
26-
"py312",
27-
"-l",
28-
vim.opt_local.colorcolumn:get()[1] or "88",
29-
}
30-
end,
31-
}),
16+
-- formatting.black.with({
17+
-- extra_args = function(_)
18+
-- return {
19+
-- "--fast",
20+
-- "--quiet",
21+
-- "--target-version",
22+
-- "py38",
23+
-- "py39",
24+
-- "py310",
25+
-- "py311",
26+
-- "py312",
27+
-- "-l",
28+
-- vim.opt_local.colorcolumn:get()[1] or "88",
29+
-- }
30+
-- end,
31+
-- }),
32+
formatting.black,
3233
require("none-ls.formatting.rustfmt"),
3334
--[[ diagnostics.flake8.with {
3435
extra_args = function(_)

lua/modules/lsp/plugins.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ lsp({
105105
})
106106

107107
lsp({
108+
enabled = false,
108109
"nvimtools/none-ls.nvim",
109110
event = { "InsertEnter" },
110111
dependencies = {
@@ -121,3 +122,11 @@ lsp({
121122
require("modules.lsp.servers.lua_ls").setup(opts)
122123
end,
123124
})
125+
126+
lsp({
127+
"stevearc/conform.nvim",
128+
event = { "BufWritePre" },
129+
config = function()
130+
require("modules.lsp.conform")
131+
end
132+
})

0 commit comments

Comments
 (0)