]> git.rmz.io Git - dotfiles.git/blob - nvim/lua/plugins/lang/cpp.lua
596c2ea4845536aecb27673e45df602c737c3187
[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 -- "blink.cmp",
97 -- opts = function(_, opts)
98 -- -- TODO: make sure this works
99 -- table.insert(opts.fuzzy.sorts, 1, require("clangd_extensions.cmp_scores"))
100 -- end,
101 -- },
102
103 {
104 "mfussenegger/nvim-dap",
105 dependencies = {
106 -- Ensure C/C++ debugger is installed
107 "williamboman/mason.nvim",
108 opts = function(_, opts)
109 if type(opts.ensure_installed) == "table" then
110 vim.list_extend(opts.ensure_installed, { "codelldb" })
111 end
112 end,
113 },
114 opts = function()
115 local dap = require("dap")
116 if not dap.adapters["codelldb"] then
117 require("dap").adapters["codelldb"] = {
118 type = "server",
119 host = "localhost",
120 port = "${port}",
121 executable = {
122 command = "codelldb",
123 args = {
124 "--port",
125 "${port}",
126 },
127 },
128 }
129 end
130 for _, lang in ipairs({ "c", "cpp" }) do
131 dap.configurations[lang] = {
132 {
133 type = "codelldb",
134 request = "launch",
135 name = "Launch file",
136 program = function()
137 return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/", "file")
138 end,
139 cwd = "${workspaceFolder}",
140 },
141 {
142 type = "codelldb",
143 request = "attach",
144 name = "Attach to process",
145 processId = require("dap.utils").pick_process,
146 cwd = "${workspaceFolder}",
147 },
148 }
149 end
150 end,
151 },
152 }