add some formatting and linting config
This commit is contained in:
parent
11da71e073
commit
8b167eb8d5
|
@ -12,7 +12,7 @@ local servers = {
|
||||||
gopls = {},
|
gopls = {},
|
||||||
-- pyright = {},
|
-- pyright = {},
|
||||||
-- rust_analyzer = {},
|
-- rust_analyzer = {},
|
||||||
tsserver = {},
|
-- tsserver = {},
|
||||||
-- html = { filetypes = { 'html', 'twig', 'hbs'} },
|
-- html = { filetypes = { 'html', 'twig', 'hbs'} },
|
||||||
|
|
||||||
lua_ls = {
|
lua_ls = {
|
||||||
|
@ -48,3 +48,20 @@ mason_lspconfig.setup_handlers {
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-- import mason-null-ls plugin safely
|
||||||
|
local mason_null_ls_status, mason_null_ls = pcall(require, "mason-null-ls")
|
||||||
|
if not mason_null_ls_status then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
mason_null_ls.setup({
|
||||||
|
-- List of formatters and linters for Mason to install
|
||||||
|
ensure_installed = {
|
||||||
|
"prettier", -- ts/js formatter
|
||||||
|
"stylua", -- lua formatter
|
||||||
|
"eslint_d", -- ts/js linter
|
||||||
|
},
|
||||||
|
-- auto-install configured formatters & linters (with null-ls)
|
||||||
|
automatic_installation = true,
|
||||||
|
})
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
-- import null-ls plugin safely
|
||||||
|
local setup, null_ls = pcall(require, "null-ls")
|
||||||
|
if not setup then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- for conciseness
|
||||||
|
local formatting = null_ls.builtins.formatting -- to setup formatters
|
||||||
|
local diagnostics = null_ls.builtins.diagnostics -- to setup linters
|
||||||
|
|
||||||
|
-- to setup format on save
|
||||||
|
local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
|
||||||
|
|
||||||
|
-- configure null_ls
|
||||||
|
null_ls.setup({
|
||||||
|
-- setup formatters & linters
|
||||||
|
sources = {
|
||||||
|
-- to disable file types use
|
||||||
|
-- "formatting.prettier.with({disabled_filetypes = {}})" (see null-ls docs)
|
||||||
|
formatting.prettier, -- js/ts formatter
|
||||||
|
formatting.stylua, -- lua formatter
|
||||||
|
diagnostics.eslint_d.with({ -- js/ts linter
|
||||||
|
-- only enable eslint if root has .eslintrc.js or .eslintrc.cjs
|
||||||
|
condition = function(utils)
|
||||||
|
return utils.root_has_file(".eslintrc.js") or utils.root_has_file(".eslintrc.cjs")
|
||||||
|
end,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
-- configure format on save
|
||||||
|
on_attach = function(current_client, bufnr)
|
||||||
|
if current_client.supports_method("textDocument/formatting") then
|
||||||
|
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({
|
||||||
|
filter = function(client)
|
||||||
|
-- only use null-ls for formatting instead of lsp server
|
||||||
|
return client.name == "null-ls"
|
||||||
|
end,
|
||||||
|
bufnr = bufnr,
|
||||||
|
})
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
|
@ -6,4 +6,11 @@ return {
|
||||||
'tpope/vim-surround',
|
'tpope/vim-surround',
|
||||||
'szw/vim-maximizer',
|
'szw/vim-maximizer',
|
||||||
'vim-scripts/ReplaceWithRegister',
|
'vim-scripts/ReplaceWithRegister',
|
||||||
|
{
|
||||||
|
"pmizio/typescript-tools.nvim",
|
||||||
|
dependencies = { "nvim-lua/plenary.nvim", "neovim/nvim-lspconfig" },
|
||||||
|
opts = {},
|
||||||
|
},
|
||||||
|
'jose-elias-alvarez/null-ls.nvim',
|
||||||
|
"jayp0521/mason-null-ls.nvim",
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue