config
This commit is contained in:
parent
90375de069
commit
6fbca010b2
|
@ -1,79 +1,78 @@
|
||||||
return {
|
return {
|
||||||
"nvimtools/none-ls.nvim", -- configure formatters & linters
|
'nvimtools/none-ls.nvim', -- configure formatters & linters
|
||||||
lazy = true,
|
lazy = true,
|
||||||
event = { "BufReadPre", "BufNewFile" }, -- to enable uncomment this
|
event = { 'BufReadPre', 'BufNewFile' }, -- to enable uncomment this
|
||||||
dependencies = {
|
dependencies = {
|
||||||
"jay-babu/mason-null-ls.nvim",
|
'jay-babu/mason-null-ls.nvim',
|
||||||
},
|
},
|
||||||
config = function()
|
config = function()
|
||||||
local mason_null_ls = require("mason-null-ls")
|
local mason_null_ls = require 'mason-null-ls'
|
||||||
|
|
||||||
local null_ls = require("null-ls")
|
local null_ls = require 'null-ls'
|
||||||
|
|
||||||
local null_ls_utils = require("null-ls.utils")
|
local null_ls_utils = require 'null-ls.utils'
|
||||||
|
|
||||||
mason_null_ls.setup({
|
mason_null_ls.setup {
|
||||||
ensure_installed = {
|
ensure_installed = {
|
||||||
"prettier", -- prettier formatter
|
'prettier', -- prettier formatter
|
||||||
"stylua", -- lua formatter
|
'stylua', -- lua formatter
|
||||||
"eslint-lsp", -- js linter
|
'eslint-lsp', -- js linter
|
||||||
"golangci-lint",
|
'golangci-lint',
|
||||||
"gofumpt",
|
'gofumpt',
|
||||||
"goimports",
|
'goimports',
|
||||||
"goimports-reviser",
|
'goimports-reviser',
|
||||||
"golines",
|
'golines',
|
||||||
"gomodifytags",
|
'gomodifytags',
|
||||||
"jsonls"
|
'jsonls',
|
||||||
},
|
},
|
||||||
})
|
}
|
||||||
|
|
||||||
-- for conciseness
|
-- for conciseness
|
||||||
local formatting = null_ls.builtins.formatting -- to setup formatters
|
local formatting = null_ls.builtins.formatting -- to setup formatters
|
||||||
local diagnostics = null_ls.builtins.diagnostics -- to setup linters
|
local diagnostics = null_ls.builtins.diagnostics -- to setup linters
|
||||||
|
|
||||||
-- to setup format on save
|
-- to setup format on save
|
||||||
local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
|
local augroup = vim.api.nvim_create_augroup('LspFormatting', {})
|
||||||
|
|
||||||
-- configure null_ls
|
-- configure null_ls
|
||||||
null_ls.setup({
|
null_ls.setup {
|
||||||
-- add package.json as identifier for root (for typescript monorepos)
|
-- add package.json as identifier for root (for typescript monorepos)
|
||||||
root_dir = null_ls_utils.root_pattern(".null-ls-root", "Makefile", ".git", "package.json"),
|
root_dir = null_ls_utils.root_pattern('.null-ls-root', 'Makefile', '.git', 'package.json'),
|
||||||
-- setup formatters & linters
|
-- setup formatters & linters
|
||||||
sources = {
|
sources = {
|
||||||
-- to disable file types use
|
-- to disable file types use
|
||||||
-- "formatting.prettier.with({disabled_filetypes: {}})" (see null-ls docs)
|
-- "formatting.prettier.with({disabled_filetypes: {}})" (see null-ls docs)
|
||||||
formatting.prettier.with({
|
formatting.prettier.with {
|
||||||
extra_filetypes = { "svelte" },
|
extra_filetypes = { 'svelte' },
|
||||||
}), -- js/ts formatter
|
}, -- js/ts formatter
|
||||||
formatting.stylua, -- lua formatter
|
formatting.stylua, -- lua formatter
|
||||||
formatting.isort,
|
formatting.isort,
|
||||||
formatting.black,
|
diagnostics.golangci_lint,
|
||||||
diagnostics.pylint,
|
formatting.gofumpt,
|
||||||
diagnostics.eslint_d.with({ -- js/ts linter
|
formatting.goimports,
|
||||||
condition = function(utils)
|
formatting.goimports_reviser,
|
||||||
return utils.root_has_file({ ".eslintrc.js", ".eslintrc.cjs" }) -- only enable if root has .eslintrc.js or .eslintrc.cjs
|
formatting.golines,
|
||||||
end,
|
null_ls.builtins.code_actions.gomodifytags
|
||||||
}),
|
},
|
||||||
},
|
-- configure format on save
|
||||||
-- configure format on save
|
on_attach = function(current_client, bufnr)
|
||||||
on_attach = function(current_client, bufnr)
|
if current_client.supports_method 'textDocument/formatting' then
|
||||||
if current_client.supports_method("textDocument/formatting") then
|
vim.api.nvim_clear_autocmds { group = augroup, buffer = bufnr }
|
||||||
vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr })
|
vim.api.nvim_create_autocmd('BufWritePre', {
|
||||||
vim.api.nvim_create_autocmd("BufWritePre", {
|
group = augroup,
|
||||||
group = augroup,
|
buffer = bufnr,
|
||||||
buffer = bufnr,
|
callback = function()
|
||||||
callback = function()
|
vim.lsp.buf.format {
|
||||||
vim.lsp.buf.format({
|
filter = function(client)
|
||||||
filter = function(client)
|
-- only use null-ls for formatting instead of lsp server
|
||||||
-- only use null-ls for formatting instead of lsp server
|
return client.name == 'null-ls'
|
||||||
return client.name == "null-ls"
|
end,
|
||||||
end,
|
bufnr = bufnr,
|
||||||
bufnr = bufnr,
|
}
|
||||||
})
|
end,
|
||||||
end,
|
})
|
||||||
})
|
end
|
||||||
end
|
end,
|
||||||
end,
|
}
|
||||||
})
|
end,
|
||||||
end,
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue