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