Closed caneta closed 6 months ago
mason shouldnt be used here, because it downloads stuff globally for neovim and puts in a folder
i think you will achieve it by npm and for eslint, use lspconfig and for prettier, use conform. And make sure prettier/eslint isnt installed globally
No way to make project prettier work: I've got some hint here, but cannot find the executable:
My current config inside lua/configs/conform.lua is the following:
local options = {
formatters = {
prettier = {
command = "./node_modules/.bin/prettier",
},
},
formatters_by_ft = {
lua = { "stylua" },
css = { "prettier" },
scss = { "prettier" },
html = { "prettier" },
javascript = { "prettier" },
javascriptreact = { "prettier" },
typescript = { "prettier" },
typescriptreact = { "prettier" },
},
format_on_save = {
-- These options will be passed to conform.format()
timeout_ms = 500,
lsp_fallback = true,
},
}
require("conform").setup(options)
Any suggestion?
@caneta i dont use prettier so cant help sorry! you could ask in conform repo
or r/neovim
I solved with some changes to NvChad/starter; here's a minimal example with prettier for css files:
{
"stevearc/conform.nvim",
event = "BufWritePre", -- uncommented
cmd = "ConformInfo", -- otherwise ConformInfo don't show up until first <leader>fm
config = function()
require "configs.conform"
end,
},
local options = {
ft_parsers = { -- added
css = "css",
},
formatters_by_ft = {
css = { "prettier" }, --uncommented
},
format_on_save = { -- uncommented and changed
-- These options will be passed to conform.format()
timeout_ms = 999999, -- non way to make it work otherwise!
lsp_fallback = true,
},
}
-- overwriting the same lines in NvChad mapping file, in order to add timeout_ms
-- even here no way to make it work without it
map("n", "<leader>fm", function()
require("conform").format({ timeout_ms = 999999, lsp_fallback = true })
end, { desc = "custom format files" })
I do not know why but the Conform async options (default to false) seems not to work properly here...
@caneta if it works the weird way then the plugin probably has a bug, you should make an issue there!
No bugs Conform side, the author just clarified me how to configure it better: https://github.com/stevearc/conform.nvim/issues/401
In the end I make it work with the following:
{
"stevearc/conform.nvim",
event = "BufWritePre",
cmd = "ConformInfo",
config = function()
require "configs.conform"
end,
},
local options = {
formatters_by_ft = {
css = { "prettier" },
},
format_after_save = {
lsp_fallback = true,
},
}
-- overwriting the same lines in NvChad mapping file, in order to add `async = true`
map("n", "<leader>fm", function()
require("conform").format({ async = true, lsp_fallback = true })
end, { desc = "custom format files" })
Maybe the last one could be added to the core mappings of NvChad!
are there any cons of async?
Nope, as far as I know...
I'm used to work with prettier/eslint installed per project instead the ones installed in the editor itself, because:
Now, how to tell NVChad to do that?
I'm not sure on what to configure to achieve this: Mason? Conform? I need to install something else?
Is there any config snippet suggested?
Thanks