diff --git a/after/plugin/code-tools.lua b/after/plugin/code-tools.lua new file mode 100644 index 0000000..6a48e81 --- /dev/null +++ b/after/plugin/code-tools.lua @@ -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" }, "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", + }, +}) diff --git a/after/plugin/conform.lua b/after/plugin/conform.lua deleted file mode 100644 index a980036..0000000 --- a/after/plugin/conform.lua +++ /dev/null @@ -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" }, "f", function() - conform.format({ - lsp_fallback = true, - }) -end, { desc = "Format file or range (in visual mode)" }) diff --git a/after/plugin/lsp.lua b/after/plugin/lsp.lua index b0f1d91..453baa5 100644 --- a/after/plugin/lsp.lua +++ b/after/plugin/lsp.lua @@ -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, }, diff --git a/after/plugin/nvim-lint.lua b/after/plugin/nvim-lint.lua deleted file mode 100644 index 0fbb1e4..0000000 --- a/after/plugin/nvim-lint.lua +++ /dev/null @@ -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, -}) diff --git a/lua/crony/lazy.lua b/lua/crony/lazy.lua index fd7231d..bc6d163 100644 --- a/lua/crony/lazy.lua +++ b/lua/crony/lazy.lua @@ -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" },