Move linter and formater to one config. Add mason tool autoinstallerr
This commit is contained in:
parent
c3aa716388
commit
949dde4a91
57
after/plugin/code-tools.lua
Normal file
57
after/plugin/code-tools.lua
Normal file
@ -0,0 +1,57 @@
|
||||
-- [[ Formatters Setup ]]
|
||||
local conform = require("conform")
|
||||
|
||||
conform.setup({
|
||||
formatters_by_ft = {
|
||||
python = { "isort", "black" },
|
||||
lua = { "stylua" },
|
||||
sh = { "shfmt" },
|
||||
bash = { "shfmt" },
|
||||
},
|
||||
})
|
||||
|
||||
-- only format with keybinding, don't like code chaning everytime I save
|
||||
vim.keymap.set({ "n", "v" }, "<leader>f", function()
|
||||
conform.format({
|
||||
lsp_fallback = true,
|
||||
})
|
||||
end, { desc = "Format file or range (in visual mode)" })
|
||||
|
||||
-- [[ Linter's Setup ]]
|
||||
local lint = require("lint")
|
||||
|
||||
-- fix mypy import's error
|
||||
lint.linters.mypy.args = {
|
||||
function()
|
||||
local virtual = os.getenv("VIRTUAL_ENV") or os.getenv("CONDA_PREFIX") or "/usr"
|
||||
return "--python-executable", virtual .. "/bin/python3"
|
||||
end,
|
||||
}
|
||||
|
||||
lint.linters_by_ft = {
|
||||
python = { "mypy", "ruff" },
|
||||
}
|
||||
|
||||
-- setup auto linting
|
||||
local lint_augroup = vim.api.nvim_create_augroup("lint", { clear = true })
|
||||
|
||||
vim.api.nvim_create_autocmd({ "BufEnter", "BufWritePost", "InsertLeave" }, {
|
||||
group = lint_augroup,
|
||||
callback = function()
|
||||
lint.try_lint()
|
||||
end,
|
||||
})
|
||||
|
||||
-- [[ Mason Tools Installer ]]
|
||||
local mason_tool_installer = require("mason-tool-installer")
|
||||
|
||||
mason_tool_installer.setup({
|
||||
ensure_installed = {
|
||||
"isort",
|
||||
"black",
|
||||
"stylua",
|
||||
"shfmt",
|
||||
"mypy",
|
||||
"ruff",
|
||||
},
|
||||
})
|
@ -1,16 +0,0 @@
|
||||
local conform = require("conform")
|
||||
|
||||
conform.setup({
|
||||
formatters_by_ft = {
|
||||
python = { "isort", "black" },
|
||||
lua = { "stylua" },
|
||||
sh = { "shfmt" },
|
||||
bash = { "shfmt" },
|
||||
},
|
||||
})
|
||||
|
||||
vim.keymap.set({ "n", "v" }, "<leader>f", function()
|
||||
conform.format({
|
||||
lsp_fallback = true,
|
||||
})
|
||||
end, { desc = "Format file or range (in visual mode)" })
|
@ -75,7 +75,7 @@ vim.diagnostic.config({
|
||||
|
||||
require("mason").setup({})
|
||||
require("mason-lspconfig").setup({
|
||||
ensure_installed = { "lua_ls" },
|
||||
ensure_installed = { "lua_ls", "jsonls", "bashls", "pyright" },
|
||||
handlers = {
|
||||
lsp.default_setup,
|
||||
},
|
||||
|
@ -1,21 +0,0 @@
|
||||
local lint = require("lint")
|
||||
|
||||
lint.linters.mypy.args = {
|
||||
function()
|
||||
local virtual = os.getenv("VIRTUAL_ENV") or os.getenv("CONDA_PREFIX") or "/usr"
|
||||
return "--python-executable", virtual .. "/bin/python3"
|
||||
end,
|
||||
}
|
||||
|
||||
lint.linters_by_ft = {
|
||||
python = { "mypy", "ruff" },
|
||||
}
|
||||
|
||||
local lint_augroup = vim.api.nvim_create_augroup("lint", { clear = true })
|
||||
|
||||
vim.api.nvim_create_autocmd({ "BufEnter", "BufWritePost", "InsertLeave" }, {
|
||||
group = lint_augroup,
|
||||
callback = function()
|
||||
lint.try_lint()
|
||||
end,
|
||||
})
|
@ -152,6 +152,9 @@ require("lazy").setup({
|
||||
|
||||
-- additional linter support
|
||||
"mfussenegger/nvim-lint",
|
||||
|
||||
-- mason autoinstaller for formatter's and linter's
|
||||
"WhoIsSethDaniel/mason-tool-installer.nvim"
|
||||
}, {
|
||||
install = {
|
||||
colorscheme = { "catppuccin" },
|
||||
|
Loading…
Reference in New Issue
Block a user