add: migrate cpp & java formatter to conform

This commit is contained in:
asep.komarudin 2024-06-23 23:11:52 +07:00
parent ab36e30b69
commit e9d75bd429
5 changed files with 39 additions and 16 deletions

View file

@ -18,7 +18,7 @@
"dressing.nvim": { "branch": "master", "commit": "71349f24c6e07b39f33600985843c289ca735308" },
"friendly-snippets": { "branch": "main", "commit": "682157939e57bd6a2c86277dfd4d6fbfce63dbac" },
"gitsigns.nvim": { "branch": "main", "commit": "0b04035bb7b3c83e999b9676e2fb46fd0aa9f910" },
"indent-blankline.nvim": { "branch": "master", "commit": "d98f537c3492e87b6dc6c2e3f66ac517528f406f" },
"indent-blankline.nvim": { "branch": "master", "commit": "4036c8ae9cc29faf8e6443fa5b23e679db055d24" },
"lazy.nvim": { "branch": "main", "commit": "4ea9fe060042f345960ad0c01aa7bca91405e10a" },
"lsp-progress.nvim": { "branch": "main", "commit": "55a04895ea20c365b670051a3128265d43bdfa3d" },
"lualine.nvim": { "branch": "master", "commit": "0a5a66803c7407767b799067986b4dc3036e1983" },
@ -28,6 +28,7 @@
"mini.indentscope": { "branch": "main", "commit": "56d42be090e8fcc68eda69cfe55af8c5e562300e" },
"neoscroll.nvim": { "branch": "master", "commit": "a731f66f1d39ec6175fd201c5bf849e54abda99c" },
"neotest": { "branch": "master", "commit": "f30bab1faef13d47f3905e065215c96a42d075ad" },
"neotest-gtest": { "branch": "main", "commit": "b44c8afc26cea75ffc80617ce07b4e745a56e589" },
"neotest-java": { "branch": "main", "commit": "320f31c71b183f2c584198f33f93542fd0e5a768" },
"noice.nvim": { "branch": "main", "commit": "8f1d9966762e62fa8788e5fb1a5f6a86784221d9" },
"none-ls-extras.nvim": { "branch": "main", "commit": "336e84b9e43c0effb735b08798ffac382920053b" },
@ -44,7 +45,7 @@
"nvim-notify": { "branch": "master", "commit": "d333b6f167900f6d9d42a59005d82919830626bf" },
"nvim-scrollview": { "branch": "main", "commit": "fd334e5ad0c616987d1b9114890a59c97165cf83" },
"nvim-tree.lua": { "branch": "master", "commit": "2086e564c4d23fea714e8a6d63b881e551af2f41" },
"nvim-treesitter": { "branch": "master", "commit": "55d5772a6c514bd19cd4587352799b0783798c04" },
"nvim-treesitter": { "branch": "master", "commit": "0941c1147a1c8d7f9c8f712a9856412db3fbc560" },
"nvim-treesitter-textobjects": { "branch": "master", "commit": "34867c69838078df7d6919b130c0541c0b400c47" },
"nvim-ts-autotag": { "branch": "main", "commit": "ddfccbf0df1b9349c2b9e9b17f4afa8f9b6c1ed1" },
"nvim-ts-context-commentstring": { "branch": "main", "commit": "cb064386e667def1d241317deed9fd1b38f0dc2e" },

View file

@ -159,7 +159,7 @@ pcode.active_javascript_config = {
pcode.active_php_config = false
pcode.active_golang_config = false
pcode.active_python_config = false
pcode.active_cpp_config = false
pcode.active_cpp_config = true
pcode.active_java_config = {
active = true,
project = "gradle", -- gradle or maven

View file

@ -43,6 +43,30 @@ if pcode.active_cpp_config then
{ "<leader>rc", "<cmd>terminal<cr>g++ --debug main.cpp -o main<cr>", desc = "Compile Debug main.cpp" },
},
},
{
"stevearc/conform.nvim",
event = { "BufReadPre", "BufNewFile" },
opts = function(_, opts)
opts.formatters_by_ft = opts.formatters_by_ft or {}
opts.formatters_by_ft.cpp = { "clang-format" }
opts.format_on_save = {
timeout_ms = 500,
lsp_fallback = true,
}
return opts
end,
config = function(_, opts)
local conform = require("conform")
conform.setup(opts)
vim.keymap.set({ "n", "v" }, "<leader>lF", function()
conform.format({
lsp_fallback = true,
async = false,
timeout_ms = 500,
})
end, { desc = "Format file or range (in visual mode)" })
end,
},
}
end
return M

View file

@ -49,18 +49,18 @@ if pcode.active_java_config.active then
{
"stevearc/conform.nvim",
event = { "BufReadPre", "BufNewFile" },
config = function()
local conform = require("conform")
conform.setup({
formatters_by_ft = {
java = { "google-java-format" },
},
format_on_save = {
-- These options will be passed to conform.format()
opts = function(_, opts)
opts.formatters_by_ft = opts.formatters_by_ft or {}
opts.formatters_by_ft.java = { "google-java-format" }
opts.format_on_save = {
timeout_ms = 500,
lsp_fallback = true,
},
})
}
return opts
end,
config = function(_, opts)
local conform = require("conform")
conform.setup(opts)
vim.keymap.set({ "n", "v" }, "<leader>lF", function()
conform.format({
lsp_fallback = true,

View file

@ -79,7 +79,6 @@ if pcode.active_cpp_config then
table.insert(pcode.treesitter_ensure_installed, "cpp")
table.insert(pcode.treesitter_ensure_installed, "c")
table.insert(pcode.mason_ensure_installed, "clangd")
table.insert(pcode.null_ls_ensure_installed, "clang_format")
table.insert(pcode.dap_ensure_installed, "codelldb")
pcode.nvim_dap = true
end
@ -88,7 +87,6 @@ if pcode.active_java_config then
table.insert(pcode.treesitter_ensure_installed, "java")
table.insert(pcode.mason_ensure_installed, "jdtls")
table.insert(pcode.dap_ensure_installed, "javadbg")
table.insert(pcode.dap_ensure_installed, "javatest")
table.insert(pcode.unregister_lsp, "jdtls")
end
return {}