]> git.rmz.io Git - dotfiles.git/blob - nvim/lua/plugins/lang/cpp.lua
vim: do not set pastetoggle in nvim
[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_dir = function(fname)
50 return require("lspconfig.util").root_pattern( "compile_commands.json", "compile_flags.txt")(fname)
51 or require("lspconfig.util").root_pattern(
52 "Makefile",
53 "configure.ac",
54 "configure.in",
55 "config.h.in",
56 "meson.build",
57 "meson_options.txt",
58 "build.ninja"
59 )(fname)
60 or require("lspconfig.util").find_git_ancestor(fname)
61 end,
62 capabilities = {
63 offsetEncoding = { "utf-16" },
64 },
65 cmd = {
66 "clangd",
67 "--background-index",
68 "--clang-tidy",
69 "--header-insertion=iwyu",
70 "--completion-style=detailed",
71 "--function-arg-placeholders",
72 "--fallback-style=llvm",
73 },
74 init_options = {
75 usePlaceholders = true,
76 completeUnimported = true,
77 clangdFileStatus = true,
78 },
79 },
80 },
81 setup = {
82 clangd = function(_, opts)
83 local clangd_ext_opts = rmz.lazy.opts("clangd_extensions.nvim")
84 require("clangd_extensions").setup(vim.tbl_deep_extend("force", clangd_ext_opts or {}, { server = opts }))
85 return false
86 end,
87 },
88 },
89 },
90 -- { "blink.cmp",
91 -- opts = function(_, opts)
92 -- -- TODO: make sure this works
93 -- table.insert(opts.fuzzy.sorts, 1, require("clangd_extensions.cmp_scores"))
94 -- end,
95 -- },
96 { "mfussenegger/nvim-dap",
97 dependencies = {
98 -- Ensure C/C++ debugger is installed
99 "williamboman/mason.nvim",
100 opts = { ensure_installed = { "codelldb" } },
101 },
102 opts = function()
103 local dap = require("dap")
104 if not dap.adapters["codelldb"] then
105 require("dap").adapters["codelldb"] = {
106 type = "server",
107 host = "localhost",
108 port = "${port}",
109 executable = {
110 command = "codelldb",
111 args = {
112 "--port",
113 "${port}",
114 },
115 },
116 }
117 end
118 for _, lang in ipairs({ "c", "cpp" }) do
119 dap.configurations[lang] = {
120 {
121 type = "codelldb",
122 request = "launch",
123 name = "Launch file",
124 program = function()
125 return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/", "file")
126 end,
127 cwd = "${workspaceFolder}",
128 },
129 {
130 type = "codelldb",
131 request = "attach",
132 name = "Attach to process",
133 pid = require("dap.utils").pick_process,
134 cwd = "${workspaceFolder}",
135 },
136 }
137 end
138 end,
139 },
140 }