mirror of
https://github.com/pojokcodeid/nvim-lazy.git
synced 2025-06-21 08:35:48 +02:00
enc: cpp confug default
This commit is contained in:
parent
22fef75144
commit
f7c84d58f8
6 changed files with 46 additions and 39 deletions
|
@ -161,6 +161,6 @@ pcode.active_golang_config = false
|
||||||
pcode.active_python_config = false
|
pcode.active_python_config = false
|
||||||
pcode.active_cpp_config = true
|
pcode.active_cpp_config = true
|
||||||
pcode.active_java_config = {
|
pcode.active_java_config = {
|
||||||
active = true,
|
active = false,
|
||||||
project = "gradle", -- gradle or maven
|
project = "gradle", -- gradle or maven
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,33 +43,6 @@ if pcode.active_cpp_config then
|
||||||
{ "<leader>rc", "<cmd>terminal<cr>g++ --debug main.cpp -o main<cr>", desc = "Compile Debug main.cpp" },
|
{ "<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)
|
|
||||||
local psave = pcode.format_on_save or 0
|
|
||||||
opts.formatters_by_ft = opts.formatters_by_ft or {}
|
|
||||||
opts.formatters_by_ft.cpp = { "clang-format" }
|
|
||||||
if psave == 1 then
|
|
||||||
opts.format_on_save = {
|
|
||||||
timeout_ms = pcode.format_timeout_ms or 500,
|
|
||||||
lsp_fallback = true,
|
|
||||||
}
|
|
||||||
end
|
|
||||||
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
|
end
|
||||||
return M
|
return M
|
||||||
|
|
|
@ -52,7 +52,7 @@ if pcode.active_java_config.active then
|
||||||
opts = function(_, opts)
|
opts = function(_, opts)
|
||||||
local psave = pcode.format_on_save or 0
|
local psave = pcode.format_on_save or 0
|
||||||
opts.formatters_by_ft = opts.formatters_by_ft or {}
|
opts.formatters_by_ft = opts.formatters_by_ft or {}
|
||||||
opts.formatters_by_ft.java = { "google-java-format" }
|
opts.formatters_by_ft.java = { "lsp_fmt" }
|
||||||
if psave == 1 then
|
if psave == 1 then
|
||||||
opts.format_on_save = {
|
opts.format_on_save = {
|
||||||
timeout_ms = pcode.format_timeout_ms or 500,
|
timeout_ms = pcode.format_timeout_ms or 500,
|
||||||
|
@ -68,7 +68,7 @@ if pcode.active_java_config.active then
|
||||||
conform.format({
|
conform.format({
|
||||||
lsp_fallback = true,
|
lsp_fallback = true,
|
||||||
async = false,
|
async = false,
|
||||||
timeout_ms = 500,
|
timeout_ms = pcode.format_timeout_ms or 500,
|
||||||
})
|
})
|
||||||
end, { desc = "Format file or range (in visual mode)" })
|
end, { desc = "Format file or range (in visual mode)" })
|
||||||
end,
|
end,
|
||||||
|
|
|
@ -79,6 +79,7 @@ if pcode.active_cpp_config then
|
||||||
table.insert(pcode.treesitter_ensure_installed, "cpp")
|
table.insert(pcode.treesitter_ensure_installed, "cpp")
|
||||||
table.insert(pcode.treesitter_ensure_installed, "c")
|
table.insert(pcode.treesitter_ensure_installed, "c")
|
||||||
table.insert(pcode.mason_ensure_installed, "clangd")
|
table.insert(pcode.mason_ensure_installed, "clangd")
|
||||||
|
table.insert(pcode.null_ls_ensure_installed, "clang_format")
|
||||||
table.insert(pcode.dap_ensure_installed, "codelldb")
|
table.insert(pcode.dap_ensure_installed, "codelldb")
|
||||||
pcode.nvim_dap = true
|
pcode.nvim_dap = true
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,6 +12,34 @@ if next(buf_clients) == nil then
|
||||||
end
|
end
|
||||||
|
|
||||||
if run == 1 then
|
if run == 1 then
|
||||||
|
-- function FORMAT_FILTER(client)
|
||||||
|
-- local filetype = vim.bo.filetype
|
||||||
|
-- local n = require("null-ls")
|
||||||
|
-- local s = require("null-ls.sources")
|
||||||
|
-- local method = n.methods.FORMATTING
|
||||||
|
-- local available_formatters = s.get_available(filetype, method)
|
||||||
|
--
|
||||||
|
-- if #available_formatters > 0 then
|
||||||
|
-- return client.name == "null-ls"
|
||||||
|
-- elseif client.supports_method("textDocument/formatting") then
|
||||||
|
-- return true
|
||||||
|
-- else
|
||||||
|
-- return false
|
||||||
|
-- end
|
||||||
|
-- end
|
||||||
|
--
|
||||||
|
-- vim.cmd([[
|
||||||
|
-- augroup _lsp
|
||||||
|
-- autocmd!
|
||||||
|
-- " autocmd BufWritePre * lua vim.lsp.buf.format{timeout_ms =200, filter=format_filter}
|
||||||
|
-- autocmd BufWritePre * lua vim.lsp.buf.format{timeout_ms=pcode.format_timeout_ms or 5000 ,filter=FORMAT_FILTER}
|
||||||
|
-- augroup end
|
||||||
|
-- ]])
|
||||||
|
|
||||||
|
---filter passed to vim.lsp.buf.format
|
||||||
|
---always selects null-ls if it's available and caches the value per buffer
|
||||||
|
---@param client table client attached to a buffer
|
||||||
|
---@return boolean if client matches
|
||||||
function FORMAT_FILTER(client)
|
function FORMAT_FILTER(client)
|
||||||
local filetype = vim.bo.filetype
|
local filetype = vim.bo.filetype
|
||||||
local n = require("null-ls")
|
local n = require("null-ls")
|
||||||
|
@ -27,12 +55,17 @@ if run == 1 then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
vim.api.nvim_create_autocmd("BufWritePre", {
|
||||||
vim.cmd([[
|
group = "lsp_format_on_save",
|
||||||
augroup _lsp
|
pattern = "*",
|
||||||
autocmd!
|
callback = function()
|
||||||
" autocmd BufWritePre * lua vim.lsp.buf.format{timeout_ms =200, filter=format_filter}
|
vim.lsp.buf.format({ timeout_ms = pcode.format_timeout_ms or 5000, filter = FORMAT_FILTER })
|
||||||
autocmd BufWritePre * lua vim.lsp.buf.format{timeout_ms=pcode.format_timeout_ms or 5000 ,filter=FORMAT_FILTER}
|
end,
|
||||||
augroup end
|
})
|
||||||
]])
|
else
|
||||||
|
vim.schedule(function()
|
||||||
|
pcall(function()
|
||||||
|
vim.api.nvim_clear_autocmds({ group = "lsp_format_on_save" })
|
||||||
|
end)
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
|
@ -108,7 +108,7 @@ return {
|
||||||
|
|
||||||
-- add conform.nvim
|
-- add conform.nvim
|
||||||
local status, conform = pcall(require, "conform")
|
local status, conform = pcall(require, "conform")
|
||||||
if status then
|
if status and supported_formatters and #supported_formatters == 0 then
|
||||||
local formatters = conform.list_formatters_for_buffer()
|
local formatters = conform.list_formatters_for_buffer()
|
||||||
if formatters and #formatters > 0 then
|
if formatters and #formatters > 0 then
|
||||||
vim.list_extend(buf_client_names, formatters)
|
vim.list_extend(buf_client_names, formatters)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue