mirror of
https://github.com/josean-dev/dev-environment-files.git
synced 2025-01-08 01:11:12 +01:00
Added option for enabling none-ls if preferred
This commit is contained in:
parent
d35558eb2b
commit
8e87f84987
3 changed files with 78 additions and 5 deletions
|
@ -1,6 +1,7 @@
|
||||||
return {
|
return {
|
||||||
"stevearc/conform.nvim",
|
"stevearc/conform.nvim",
|
||||||
event = { "BufReadPre", "BufNewFile" },
|
lazy = true,
|
||||||
|
event = { "BufReadPre", "BufNewFile" }, -- to disable, comment this out
|
||||||
config = function()
|
config = function()
|
||||||
local conform = require("conform")
|
local conform = require("conform")
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
return {
|
return {
|
||||||
"mfussenegger/nvim-lint",
|
"mfussenegger/nvim-lint",
|
||||||
event = {
|
lazy = true,
|
||||||
"BufReadPre",
|
event = { "BufReadPre", "BufNewFile" }, -- to disable, comment this out
|
||||||
"BufNewFile",
|
|
||||||
},
|
|
||||||
config = function()
|
config = function()
|
||||||
local lint = require("lint")
|
local lint = require("lint")
|
||||||
|
|
||||||
|
|
74
.config/nvim/lua/josean/plugins/lsp/none-ls.lua
Normal file
74
.config/nvim/lua/josean/plugins/lsp/none-ls.lua
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
return {
|
||||||
|
"nvimtools/none-ls.nvim", -- configure formatters & linters
|
||||||
|
lazy = true,
|
||||||
|
-- event = { "BufReadPre", "BufNewFile" }, -- to enable uncomment this
|
||||||
|
dependencies = {
|
||||||
|
"jay-babu/mason-null-ls.nvim",
|
||||||
|
},
|
||||||
|
config = function()
|
||||||
|
local mason_null_ls = require("mason-null-ls")
|
||||||
|
|
||||||
|
local null_ls = require("null-ls")
|
||||||
|
|
||||||
|
local null_ls_utils = require("null-ls.utils")
|
||||||
|
|
||||||
|
mason_null_ls.setup({
|
||||||
|
ensure_installed = {
|
||||||
|
"prettier", -- prettier formatter
|
||||||
|
"stylua", -- lua formatter
|
||||||
|
"black", -- python formatter
|
||||||
|
"pylint", -- python linter
|
||||||
|
"eslint_d", -- js linter
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
-- 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({
|
||||||
|
-- add package.json as identifier for root (for typescript monorepos)
|
||||||
|
root_dir = null_ls_utils.root_pattern(".null-ls-root", "Makefile", ".git", "package.json"),
|
||||||
|
-- setup formatters & linters
|
||||||
|
sources = {
|
||||||
|
-- to disable file types use
|
||||||
|
-- "formatting.prettier.with({disabled_filetypes: {}})" (see null-ls docs)
|
||||||
|
formatting.prettier.with({
|
||||||
|
extra_filetypes = { "svelte" },
|
||||||
|
}), -- js/ts formatter
|
||||||
|
formatting.stylua, -- lua formatter
|
||||||
|
formatting.isort,
|
||||||
|
formatting.black,
|
||||||
|
diagnostics.pylint,
|
||||||
|
diagnostics.eslint_d.with({ -- js/ts linter
|
||||||
|
condition = function(utils)
|
||||||
|
return utils.root_has_file({ ".eslintrc.js", ".eslintrc.cjs" }) -- only enable if root has .eslintrc.js or .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,
|
||||||
|
})
|
||||||
|
end,
|
||||||
|
}
|
Loading…
Reference in a new issue