mirror of
https://github.com/LazyVim/LazyVim.git
synced 2026-07-22 12:31:07 +00:00
## Description
As discussed in
23b9cdeb34 (r165937336),
it'd be better to remove clang configuration files from influencing root
dir detection. I've also added meson and ninja files to the extra's
recommendation detection
## Related Issue(s)
## Screenshots
## Checklist
- [x] I've read the
[CONTRIBUTING](https://github.com/LazyVim/LazyVim/blob/main/CONTRIBUTING.md)
guidelines.
164 lines
4.2 KiB
Lua
164 lines
4.2 KiB
Lua
return {
|
|
recommended = function()
|
|
return LazyVim.extras.wants({
|
|
ft = { "c", "cpp", "objc", "objcpp", "cuda", "proto" },
|
|
root = {
|
|
".clangd",
|
|
".clang-tidy",
|
|
".clang-format",
|
|
"compile_commands.json",
|
|
"compile_flags.txt",
|
|
"configure.ac", -- AutoTools
|
|
"meson.build",
|
|
"build.ninja",
|
|
},
|
|
})
|
|
end,
|
|
|
|
-- Add C/C++ to treesitter
|
|
{
|
|
"nvim-treesitter/nvim-treesitter",
|
|
opts = { ensure_installed = { "cpp" } },
|
|
},
|
|
|
|
{
|
|
"p00f/clangd_extensions.nvim",
|
|
lazy = true,
|
|
config = function() end,
|
|
opts = {
|
|
inlay_hints = {
|
|
inline = false,
|
|
},
|
|
ast = {
|
|
--These require codicons (https://github.com/microsoft/vscode-codicons)
|
|
role_icons = {
|
|
type = "",
|
|
declaration = "",
|
|
expression = "",
|
|
specifier = "",
|
|
statement = "",
|
|
["template argument"] = "",
|
|
},
|
|
kind_icons = {
|
|
Compound = "",
|
|
Recovery = "",
|
|
TranslationUnit = "",
|
|
PackExpansion = "",
|
|
TemplateTypeParm = "",
|
|
TemplateTemplateParm = "",
|
|
TemplateParamObject = "",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
|
|
-- Correctly setup lspconfig for clangd 🚀
|
|
{
|
|
"neovim/nvim-lspconfig",
|
|
opts = {
|
|
servers = {
|
|
-- Ensure mason installs the server
|
|
clangd = {
|
|
keys = {
|
|
{ "<leader>ch", "<cmd>ClangdSwitchSourceHeader<cr>", desc = "Switch Source/Header (C/C++)" },
|
|
},
|
|
root_markers = {
|
|
"compile_commands.json",
|
|
"compile_flags.txt",
|
|
"configure.ac", -- AutoTools
|
|
"Makefile",
|
|
"configure.ac",
|
|
"configure.in",
|
|
"config.h.in",
|
|
"meson.build",
|
|
"meson_options.txt",
|
|
"build.ninja",
|
|
".git",
|
|
},
|
|
capabilities = {
|
|
offsetEncoding = { "utf-16" },
|
|
},
|
|
cmd = {
|
|
"clangd",
|
|
"--background-index",
|
|
"--clang-tidy",
|
|
"--header-insertion=iwyu",
|
|
"--completion-style=detailed",
|
|
"--function-arg-placeholders",
|
|
"--fallback-style=llvm",
|
|
},
|
|
init_options = {
|
|
usePlaceholders = true,
|
|
completeUnimported = true,
|
|
clangdFileStatus = true,
|
|
},
|
|
},
|
|
},
|
|
setup = {
|
|
clangd = function(_, opts)
|
|
local clangd_ext_opts = LazyVim.opts("clangd_extensions.nvim")
|
|
require("clangd_extensions").setup(vim.tbl_deep_extend("force", clangd_ext_opts or {}, { server = opts }))
|
|
return false
|
|
end,
|
|
},
|
|
},
|
|
},
|
|
|
|
{
|
|
"hrsh7th/nvim-cmp",
|
|
optional = true,
|
|
opts = function(_, opts)
|
|
opts.sorting = opts.sorting or {}
|
|
opts.sorting.comparators = opts.sorting.comparators or {}
|
|
table.insert(opts.sorting.comparators, 1, require("clangd_extensions.cmp_scores"))
|
|
end,
|
|
},
|
|
|
|
{
|
|
"mfussenegger/nvim-dap",
|
|
optional = true,
|
|
dependencies = {
|
|
-- Ensure C/C++ debugger is installed
|
|
"mason-org/mason.nvim",
|
|
optional = true,
|
|
opts = { ensure_installed = { "codelldb" } },
|
|
},
|
|
opts = function()
|
|
local dap = require("dap")
|
|
if not dap.adapters["codelldb"] then
|
|
require("dap").adapters["codelldb"] = {
|
|
type = "server",
|
|
host = "localhost",
|
|
port = "${port}",
|
|
executable = {
|
|
command = "codelldb",
|
|
args = {
|
|
"--port",
|
|
"${port}",
|
|
},
|
|
},
|
|
}
|
|
end
|
|
for _, lang in ipairs({ "c", "cpp" }) do
|
|
dap.configurations[lang] = {
|
|
{
|
|
type = "codelldb",
|
|
request = "launch",
|
|
name = "Launch file",
|
|
program = function()
|
|
return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/", "file")
|
|
end,
|
|
cwd = "${workspaceFolder}",
|
|
},
|
|
{
|
|
type = "codelldb",
|
|
request = "attach",
|
|
name = "Attach to process",
|
|
pid = require("dap.utils").pick_process,
|
|
cwd = "${workspaceFolder}",
|
|
},
|
|
}
|
|
end
|
|
end,
|
|
},
|
|
}
|