mirror of
https://github.com/dcarrillo/dotfiles.git
synced 2025-07-01 23:19:25 +00:00
[neovim] Use conform plugin for auto formatting
This commit is contained in:
@ -125,12 +125,9 @@ keymap(
|
||||
"<cmd>Lspsaga peek_definition<cr>",
|
||||
vim.tbl_extend("force", opts, { desc = "Peek the definition of the directive under the cursor" })
|
||||
)
|
||||
keymap(
|
||||
{ "n", "v" },
|
||||
"<leader>lf",
|
||||
"<cmd>lua vim.lsp.buf.format{ async=true }<cr>",
|
||||
vim.tbl_extend("force", opts, { desc = "Format the current buffer or selection" })
|
||||
)
|
||||
keymap({ "n", "v" }, "<leader>lf", function()
|
||||
require("conform").format({ async = true, lsp_fallback = true })
|
||||
end, vim.tbl_extend("force", opts, { desc = "Format the current buffer or selection" }))
|
||||
|
||||
-- Neotest
|
||||
keymap(
|
||||
|
@ -114,7 +114,7 @@ require("lazy").setup({
|
||||
{ "numToStr/Comment.nvim", version = "v0.*" },
|
||||
{ "JoosepAlviste/nvim-ts-context-commentstring" },
|
||||
{ "nvim-tree/nvim-web-devicons", lazy = true },
|
||||
{ "akinsho/bufferline.nvim", event = "VeryLazy", branch = "main" }, -- version = "v4.*" },
|
||||
{ "akinsho/bufferline.nvim", event = "VeryLazy", version = "v4.*" },
|
||||
{ "moll/vim-bbye" },
|
||||
{ "nvim-lualine/lualine.nvim", event = "VeryLazy" },
|
||||
{ "lukas-reineke/indent-blankline.nvim", event = "BufReadPost", main = "ibl" },
|
||||
@ -185,6 +185,11 @@ require("lazy").setup({
|
||||
{ "folke/trouble.nvim" },
|
||||
{ "glepnir/lspsaga.nvim", event = "BufRead" },
|
||||
{ "arkav/lualine-lsp-progress" },
|
||||
{
|
||||
"stevearc/conform.nvim",
|
||||
event = { "BufWritePre" },
|
||||
cmd = { "ConformInfo" },
|
||||
},
|
||||
|
||||
-- Telescope
|
||||
{ "nvim-telescope/telescope.nvim", cmd = "Telescope" },
|
||||
|
@ -45,9 +45,9 @@ cmp.setup({
|
||||
["<C-Space>"] = cmp.mapping.complete(),
|
||||
["<C-q>"] = cmp.mapping.abort(),
|
||||
["<CR>"] = cmp.mapping.confirm(),
|
||||
["<Tab>"] = cmp.mapping(function(fallback)
|
||||
cmp.select_next_item()
|
||||
end),
|
||||
-- ["<Tab>"] = cmp.mapping(function(fallback)
|
||||
-- cmp.select_next_item()
|
||||
-- end),
|
||||
["<C-CR>"] = function(fallback)
|
||||
cmp.abort()
|
||||
fallback()
|
||||
|
@ -28,6 +28,7 @@ dapui.setup({
|
||||
})
|
||||
|
||||
vim.fn.sign_define("DapBreakpoint", { text = "", texthl = "DiagnosticSignError", linehl = "", numhl = "" })
|
||||
vim.fn.sign_define("DapStopped", { text = "", texthl = "DiagnosticSignWarn", linehl = "", numhl = "" })
|
||||
|
||||
dap.listeners.after.event_initialized.dapui_config = function()
|
||||
dapui.open()
|
||||
|
@ -8,15 +8,3 @@ require("go").setup({
|
||||
require("guihua.maps").setup({
|
||||
maps = { close_view = "<C-x>" },
|
||||
})
|
||||
|
||||
vim.cmd("autocmd FileType go nmap <Leader>gf :lua require('go.format').goimport()<CR>")
|
||||
|
||||
local format_sync_grp = vim.api.nvim_create_augroup("GoFormat", {})
|
||||
vim.api.nvim_create_autocmd("BufWritePre", {
|
||||
pattern = "*.go",
|
||||
callback = function()
|
||||
require('go.format').goimports()
|
||||
end,
|
||||
group = format_sync_grp,
|
||||
})
|
||||
|
||||
|
26
.config/nvim/lua/plugins/lsp/conform.lua
Normal file
26
.config/nvim/lua/plugins/lsp/conform.lua
Normal file
@ -0,0 +1,26 @@
|
||||
require("conform").setup({
|
||||
formatters_by_ft = {
|
||||
go = { "goimports", "gofumpt" },
|
||||
javascript = { "prettier" },
|
||||
json = { "prettier" },
|
||||
lua = { "stylua" },
|
||||
markdown = { "prettier" },
|
||||
python = { "isort", "black" },
|
||||
typescript = { "prettier" },
|
||||
yaml = { "prettier" },
|
||||
},
|
||||
formatters = {
|
||||
{
|
||||
command = "black",
|
||||
args = { "--line-length", "100" },
|
||||
},
|
||||
},
|
||||
format_on_save = function(bufnr)
|
||||
local filetypes = { "go", "typescript", "lua" }
|
||||
if not vim.tbl_contains(filetypes, vim.bo[bufnr].filetype) then
|
||||
return
|
||||
end
|
||||
|
||||
return { timeout_ms = 500, lsp_fallback = false }
|
||||
end,
|
||||
})
|
@ -1,6 +1,7 @@
|
||||
require("plugins.lsp.mason")
|
||||
require("plugins.lsp.handlers").setup()
|
||||
require("plugins.lsp.none-ls")
|
||||
require("plugins.lsp.conform")
|
||||
require("plugins.lsp.lsp-saga")
|
||||
|
||||
local win = require("lspconfig.ui.windows")
|
||||
|
@ -1,6 +1,4 @@
|
||||
local none_ls = require("null-ls")
|
||||
-- https://github.com/nvimtools/none-ls.nvim/tree/main/lua/null-ls/builtins/formatting
|
||||
local formatting = none_ls.builtins.formatting
|
||||
-- https://github.com/nvimtools/none-ls.nvim/tree/main/lua/null-ls/builtins/diagnostics
|
||||
local diagnostics = none_ls.builtins.diagnostics
|
||||
|
||||
@ -13,11 +11,6 @@ end
|
||||
none_ls.setup({
|
||||
debug = false,
|
||||
sources = {
|
||||
formatting.black.with({
|
||||
extra_args = { "--fast", "--line-length", "100" },
|
||||
}),
|
||||
formatting.stylua,
|
||||
formatting.prettier,
|
||||
diagnostics.hadolint,
|
||||
diagnostics.markdownlint,
|
||||
diagnostics.revive.with({
|
||||
|
Reference in New Issue
Block a user