]> git.rmz.io Git - dotfiles.git/blob - nvim/lua/plugins/lang/cpp.lua
ff6624ef3a216ad5f4e6d3e9638bf9d178d77613
[dotfiles.git] / nvim / lua / plugins / lang / cpp.lua
1 return {
2 -- Add C/C++ to treesitter
3 {
4 "nvim-treesitter/nvim-treesitter",
5 opts = function(_, opts)
6 if type(opts.ensure_installed) == "table" then
7 vim.list_extend(opts.ensure_installed, { "c", "cpp" })
8 end
9 end,
10 },
11
12 {
13 "p00f/clangd_extensions.nvim",
14 lazy = true,
15 config = function() end,
16 opts = {
17 inlay_hints = {
18 inline = false,
19 },
20 ast = {
21 --These require codicons (https://github.com/microsoft/vscode-codicons)
22 role_icons = {
23 type = "",
24 declaration = "",
25 expression = "",
26 specifier = "",
27 statement = "",
28 ["template argument"] = "",
29 },
30 kind_icons = {
31 Compound = "",
32 Recovery = "",
33 TranslationUnit = "",
34 PackExpansion = "",
35 TemplateTypeParm = "",
36 TemplateTemplateParm = "",
37 TemplateParamObject = "",
38 },
39 },
40 },
41 },
42
43 -- Correctly setup lspconfig for clangd 🚀
44 {
45 "neovim/nvim-lspconfig",
46 opts = {
47 servers = {
48 -- Ensure mason installs the server
49 clangd = {
50 keys = {
51 { "<leader>cR", "<cmd>ClangdSwitchSourceHeader<cr>", desc = "Switch Source/Header (C/C++)" },
52 },
53 root_dir = function(fname)
54 return require("lspconfig.util").root_pattern( "compile_commands.json", "compile_flags.txt")(fname)
55 or require("lspconfig.util").root_pattern(
56 "Makefile",
57 "configure.ac",
58 "configure.in",
59 "config.h.in",
60 "meson.build",
61 "meson_options.txt",
62 "build.ninja"
63 )(fname)
64 or require("lspconfig.util").find_git_ancestor(fname)
65 end,
66 capabilities = {
67 offsetEncoding = { "utf-16" },
68 },
69 cmd = {
70 "clangd",
71 "--background-index",
72 "--clang-tidy",
73 "--header-insertion=iwyu",
74 "--completion-style=detailed",
75 "--function-arg-placeholders",
76 "--fallback-style=llvm",
77 },
78 init_options = {
79 usePlaceholders = true,
80 completeUnimported = true,
81 clangdFileStatus = true,
82 },
83 },
84 },
85 setup = {
86 clangd = function(_, opts)
87 local clangd_ext_opts = require("lazyvim.util").opts("clangd_extensions.nvim")
88 require("clangd_extensions").setup(vim.tbl_deep_extend("force", clangd_ext_opts or {}, { server = opts }))
89 return false
90 end,
91 },
92 },
93 },
94
95 {
96 "nvim-cmp",
97 opts = function(_, opts)
98 table.insert(opts.sorting.comparators, 1, require("clangd_extensions.cmp_scores"))
99 end,
100 },
101
102 {
103 "mfussenegger/nvim-dap",
104 dependencies = {
105 -- Ensure C/C++ debugger is installed
106 "williamboman/mason.nvim",
107 opts = function(_, opts)
108 if type(opts.ensure_installed) == "table" then
109 vim.list_extend(opts.ensure_installed, { "codelldb" })
110 end
111 end,
112 },
113 opts = function()
114 local dap = require("dap")
115 if not dap.adapters["codelldb"] then
116 require("dap").adapters["codelldb"] = {
117 type = "server",
118 host = "localhost",
119 port = "${port}",
120 executable = {
121 command = "codelldb",
122 args = {
123 "--port",
124 "${port}",
125 },
126 },
127 }
128 end
129 for _, lang in ipairs({ "c", "cpp" }) do
130 dap.configurations[lang] = {
131 {
132 type = "codelldb",
133 request = "launch",
134 name = "Launch file",
135 program = function()
136 return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/", "file")
137 end,
138 cwd = "${workspaceFolder}",
139 },
140 {
141 type = "codelldb",
142 request = "attach",
143 name = "Attach to process",
144 processId = require("dap.utils").pick_process,
145 cwd = "${workspaceFolder}",
146 },
147 }
148 end
149 end,
150 },
151 }