Added prettier back and limited it
This commit is contained in:
@@ -32,6 +32,7 @@ return {
|
||||
mason_null_ls.setup({
|
||||
ensure_installed = {
|
||||
"stylua",
|
||||
"prettier",
|
||||
},
|
||||
automatic_installation = true,
|
||||
})
|
||||
|
||||
@@ -9,9 +9,29 @@ return {
|
||||
local formatting = null_ls.builtins.formatting
|
||||
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({
|
||||
sources = {
|
||||
formatting.stylua,
|
||||
formatting.prettier.with(formatting_with_prettier),
|
||||
},
|
||||
on_attach = function(client, bufnr)
|
||||
if client.supports_method("textDocument/formatting") then
|
||||
|
||||
@@ -24,11 +24,19 @@ return {
|
||||
else
|
||||
cmd = "typescript-language-server"
|
||||
end
|
||||
local prettier_config = vim.fn.glob(cwd .. "/*prettierrc*", false, true)
|
||||
|
||||
typescript_tools.setup({
|
||||
capabilities = capabilities,
|
||||
on_attach = function(client, bufnr)
|
||||
on_attach(client, bufnr)
|
||||
if cmd == "typescript-language-server" then
|
||||
print("Using global tsserver")
|
||||
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,
|
||||
@@ -37,8 +45,6 @@ return {
|
||||
vim.lsp.buf.format({ async = false })
|
||||
end,
|
||||
})
|
||||
if cmd == "typescript-language-server" then
|
||||
print("Using global tsserver")
|
||||
end
|
||||
end,
|
||||
settings = {
|
||||
|
||||
Reference in New Issue
Block a user