Added prettier back and limited it
This commit is contained in:
@@ -32,6 +32,7 @@ return {
|
|||||||
mason_null_ls.setup({
|
mason_null_ls.setup({
|
||||||
ensure_installed = {
|
ensure_installed = {
|
||||||
"stylua",
|
"stylua",
|
||||||
|
"prettier",
|
||||||
},
|
},
|
||||||
automatic_installation = true,
|
automatic_installation = true,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -9,9 +9,29 @@ return {
|
|||||||
local formatting = null_ls.builtins.formatting
|
local formatting = null_ls.builtins.formatting
|
||||||
local diagnostics = null_ls.builtins.diagnostics
|
local diagnostics = null_ls.builtins.diagnostics
|
||||||
|
|
||||||
|
local root_has_file = function(files)
|
||||||
|
return function(utils)
|
||||||
|
return utils.root_has_file(files)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local prettier_root_files = {
|
||||||
|
".prettierrc",
|
||||||
|
".prettierrc.json",
|
||||||
|
".prettierrc.js",
|
||||||
|
".prettierrc.mjs",
|
||||||
|
".prettierrc.cjs",
|
||||||
|
"prettier.config.cjs",
|
||||||
|
"prettier.config.js",
|
||||||
|
"prettier.config.mjs",
|
||||||
|
}
|
||||||
|
local formatting_with_prettier = formatting.prettier.with({
|
||||||
|
condition = root_has_file(prettier_root_files),
|
||||||
|
})
|
||||||
|
|
||||||
null_ls.setup({
|
null_ls.setup({
|
||||||
sources = {
|
sources = {
|
||||||
formatting.stylua,
|
formatting.stylua,
|
||||||
|
formatting.prettier.with(formatting_with_prettier),
|
||||||
},
|
},
|
||||||
on_attach = function(client, bufnr)
|
on_attach = function(client, bufnr)
|
||||||
if client.supports_method("textDocument/formatting") then
|
if client.supports_method("textDocument/formatting") then
|
||||||
|
|||||||
@@ -24,22 +24,28 @@ return {
|
|||||||
else
|
else
|
||||||
cmd = "typescript-language-server"
|
cmd = "typescript-language-server"
|
||||||
end
|
end
|
||||||
|
local prettier_config = vim.fn.glob(cwd .. "/*prettierrc*", false, true)
|
||||||
|
|
||||||
typescript_tools.setup({
|
typescript_tools.setup({
|
||||||
capabilities = capabilities,
|
capabilities = capabilities,
|
||||||
on_attach = function(client, bufnr)
|
on_attach = function(client, bufnr)
|
||||||
on_attach(client, bufnr)
|
on_attach(client, bufnr)
|
||||||
vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr })
|
|
||||||
vim.api.nvim_create_autocmd("BufWritePre", {
|
|
||||||
group = augroup,
|
|
||||||
buffer = bufnr,
|
|
||||||
callback = function()
|
|
||||||
vim.lsp.buf.format({ async = false })
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
if cmd == "typescript-language-server" then
|
if cmd == "typescript-language-server" then
|
||||||
print("Using global tsserver")
|
print("Using global tsserver")
|
||||||
end
|
end
|
||||||
|
if prettier_config == "" then
|
||||||
|
print("Using prettier to format")
|
||||||
|
return
|
||||||
|
else
|
||||||
|
vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr })
|
||||||
|
vim.api.nvim_create_autocmd("BufWritePre", {
|
||||||
|
group = augroup,
|
||||||
|
buffer = bufnr,
|
||||||
|
callback = function()
|
||||||
|
vim.lsp.buf.format({ async = false })
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
settings = {
|
settings = {
|
||||||
cmd = { cmd, "--stdio" },
|
cmd = { cmd, "--stdio" },
|
||||||
|
|||||||
Reference in New Issue
Block a user