2023-07-15 00:41:08 +00:00
|
|
|
vim.list_extend(lvim.lsp.automatic_configuration.skipped_servers, { "clangd" })
|
|
|
|
|
|
|
|
-- some settings can only passed as commandline flags, see `clangd --help`
|
|
|
|
local clangd_flags = {
|
|
|
|
"--background-index",
|
2023-07-16 17:15:50 +00:00
|
|
|
"--fallback-style=LLVM",
|
2023-07-15 00:41:08 +00:00
|
|
|
"--all-scopes-completion",
|
|
|
|
"--clang-tidy",
|
|
|
|
"--log=error",
|
|
|
|
"--suggest-missing-includes",
|
|
|
|
"--cross-file-rename",
|
|
|
|
"--completion-style=detailed",
|
|
|
|
"--pch-storage=memory", -- could also be disk
|
|
|
|
"--folding-ranges",
|
|
|
|
"--enable-config", -- clangd 11+ supports reading from .clangd configuration file
|
|
|
|
"--offset-encoding=utf-16", --temporary fix for null-ls
|
|
|
|
-- "--limit-references=1000",
|
|
|
|
-- "--limit-resutls=1000",
|
|
|
|
-- "--malloc-trim",
|
|
|
|
-- "--clang-tidy-checks=-*,llvm-*,clang-analyzer-*,modernize-*,-modernize-use-trailing-return-type",
|
|
|
|
-- "--header-insertion=never",
|
|
|
|
-- "--query-driver=<list-of-white-listed-complers>"
|
|
|
|
}
|
|
|
|
|
|
|
|
local provider = "clangd"
|
|
|
|
|
|
|
|
local custom_on_attach = function(client, bufnr)
|
|
|
|
require("lvim.lsp").common_on_attach(client, bufnr)
|
|
|
|
|
|
|
|
local opts = { noremap = true, silent = true, buffer = bufnr }
|
|
|
|
vim.keymap.set("n", "<leader>lh", "<cmd>ClangdSwitchSourceHeader<cr>", opts)
|
|
|
|
vim.keymap.set("x", "<leader>lA", "<cmd>ClangdAST<cr>", opts)
|
|
|
|
vim.keymap.set("n", "<leader>lH", "<cmd>ClangdTypeHierarchy<cr>", opts)
|
|
|
|
vim.keymap.set("n", "<leader>lt", "<cmd>ClangdSymbolInfo<cr>", opts)
|
|
|
|
vim.keymap.set("n", "<leader>lm", "<cmd>ClangdMemoryUsage<cr>", opts)
|
|
|
|
|
|
|
|
require("clangd_extensions.inlay_hints").setup_autocmd()
|
|
|
|
require("clangd_extensions.inlay_hints").set_inlay_hints()
|
|
|
|
end
|
|
|
|
|
|
|
|
local status_ok, project_config = pcall(require, "rhel.clangd_wrl")
|
|
|
|
if status_ok then
|
|
|
|
clangd_flags = vim.tbl_deep_extend("keep", project_config, clangd_flags)
|
|
|
|
end
|
|
|
|
|
|
|
|
local custom_on_init = function(client, bufnr)
|
|
|
|
require("lvim.lsp").common_on_init(client, bufnr)
|
|
|
|
require("clangd_extensions.config").setup {}
|
|
|
|
require("clangd_extensions.ast").init()
|
|
|
|
vim.cmd [[
|
|
|
|
command ClangdToggleInlayHints lua require('clangd_extensions.inlay_hints').toggle_inlay_hints()
|
|
|
|
command -range ClangdAST lua require('clangd_extensions.ast').display_ast(<line1>, <line2>)
|
|
|
|
command ClangdTypeHierarchy lua require('clangd_extensions.type_hierarchy').show_hierarchy()
|
|
|
|
command ClangdSymbolInfo lua require('clangd_extensions.symbol_info').show_symbol_info()
|
|
|
|
command -nargs=? -complete=customlist,s:memuse_compl ClangdMemoryUsage lua require('clangd_extensions.memory_usage').show_memory_usage('<args>' == 'expand_preamble')
|
|
|
|
]]
|
|
|
|
end
|
|
|
|
|
|
|
|
local opts = {
|
|
|
|
cmd = { provider, unpack(clangd_flags) },
|
|
|
|
on_attach = custom_on_attach,
|
|
|
|
on_init = custom_on_init,
|
|
|
|
}
|
|
|
|
|
|
|
|
require("lvim.lsp.manager").setup("clangd", opts)
|
|
|
|
|
|
|
|
-- install codelldb with :MasonInstall codelldb
|
|
|
|
-- configure nvim-dap (codelldb)
|
|
|
|
lvim.builtin.dap.on_config_done = function(dap)
|
|
|
|
dap.adapters.codelldb = {
|
|
|
|
type = "server",
|
|
|
|
port = "${port}",
|
|
|
|
executable = {
|
|
|
|
-- provide the absolute path for `codelldb` command if not using the one installed using `mason.nvim`
|
|
|
|
command = "codelldb",
|
|
|
|
args = { "--port", "${port}" },
|
|
|
|
|
|
|
|
-- On windows you may have to uncomment this:
|
|
|
|
-- detached = false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
dap.configurations.cpp = {
|
|
|
|
{
|
|
|
|
name = "Launch file",
|
|
|
|
type = "codelldb",
|
|
|
|
request = "launch",
|
|
|
|
program = function()
|
|
|
|
local path
|
|
|
|
vim.ui.input({ prompt = "Path to executable: ", default = vim.loop.cwd() .. "/build/" }, function(input)
|
|
|
|
path = input
|
|
|
|
end)
|
|
|
|
vim.cmd [[redraw]]
|
|
|
|
return path
|
|
|
|
end,
|
|
|
|
cwd = "${workspaceFolder}",
|
|
|
|
stopOnEntry = false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
dap.configurations.c = dap.configurations.cpp
|
|
|
|
end
|