diff --git a/lvim/config.lua b/lvim/config.lua index 281da60..1e3600b 100644 --- a/lvim/config.lua +++ b/lvim/config.lua @@ -4,8 +4,9 @@ -- Forum: https://www.reddit.com/r/lunarvim/ -- Discord: https://discord.com/invite/Xb9B4Ny -require("config.go") -require("config.py") +-- require("config.go") +-- require("config.py") +-- require("config.c") lvim.plugins = { "askfiy/visual_studio_code", diff --git a/lvim/lua/config/c.lua b/lvim/lua/config/c.lua new file mode 100644 index 0000000..3af4c7d --- /dev/null +++ b/lvim/lua/config/c.lua @@ -0,0 +1,115 @@ +lvim.format_on_save = false +lvim.lsp.diagnostics.virtual_text = true + +lvim.builtin.treesitter.highlight.enable = true + +-- auto install treesitter parsers +lvim.builtin.treesitter.ensure_installed = { "cpp", "c" } + +-- Additional Plugins +table.insert(lvim.plugins, { + "p00f/clangd_extensions.nvim", +}) + +vim.list_extend(lvim.lsp.automatic_configuration.skipped_servers, { "clangd" }) + +-- some settings can only passed as commandline flags, see `clangd --help` +local clangd_flags = { + "--background-index", + "--fallback-style=Google", + "--all-scopes-completion", + "--clang-tidy", + "--log=error", + "--suggest-missing-includes", + "--cross-file-rename", + "--completion-style=detailed", + "--pch-storage=memory", -- could also be disk + "--folding-ranges", + "--enable-config", -- clangd 11+ supports reading from .clangd configuration file + "--offset-encoding=utf-16", --temporary fix for null-ls + -- "--limit-references=1000", + -- "--limit-resutls=1000", + -- "--malloc-trim", + -- "--clang-tidy-checks=-*,llvm-*,clang-analyzer-*,modernize-*,-modernize-use-trailing-return-type", + -- "--header-insertion=never", + -- "--query-driver=" +} + +local provider = "clangd" + +local custom_on_attach = function(client, bufnr) + require("lvim.lsp").common_on_attach(client, bufnr) + + local opts = { noremap = true, silent = true, buffer = bufnr } + vim.keymap.set("n", "lh", "ClangdSwitchSourceHeader", opts) + vim.keymap.set("x", "lA", "ClangdAST", opts) + vim.keymap.set("n", "lH", "ClangdTypeHierarchy", opts) + vim.keymap.set("n", "lt", "ClangdSymbolInfo", opts) + vim.keymap.set("n", "lm", "ClangdMemoryUsage", opts) + + require("clangd_extensions.inlay_hints").setup_autocmd() + require("clangd_extensions.inlay_hints").set_inlay_hints() +end + +local status_ok, project_config = pcall(require, "rhel.clangd_wrl") +if status_ok then + clangd_flags = vim.tbl_deep_extend("keep", project_config, clangd_flags) +end + +local custom_on_init = function(client, bufnr) + require("lvim.lsp").common_on_init(client, bufnr) + require("clangd_extensions.config").setup {} + require("clangd_extensions.ast").init() + vim.cmd [[ + command ClangdToggleInlayHints lua require('clangd_extensions.inlay_hints').toggle_inlay_hints() + command -range ClangdAST lua require('clangd_extensions.ast').display_ast(, ) + command ClangdTypeHierarchy lua require('clangd_extensions.type_hierarchy').show_hierarchy() + command ClangdSymbolInfo lua require('clangd_extensions.symbol_info').show_symbol_info() + command -nargs=? -complete=customlist,s:memuse_compl ClangdMemoryUsage lua require('clangd_extensions.memory_usage').show_memory_usage('' == 'expand_preamble') + ]] +end + +local opts = { + cmd = { provider, unpack(clangd_flags) }, + on_attach = custom_on_attach, + on_init = custom_on_init, +} + +require("lvim.lsp.manager").setup("clangd", opts) + +-- install codelldb with :MasonInstall codelldb +-- configure nvim-dap (codelldb) +lvim.builtin.dap.on_config_done = function(dap) + dap.adapters.codelldb = { + type = "server", + port = "${port}", + executable = { + -- provide the absolute path for `codelldb` command if not using the one installed using `mason.nvim` + command = "codelldb", + args = { "--port", "${port}" }, + + -- On windows you may have to uncomment this: + -- detached = false, + }, + } + + dap.configurations.cpp = { + { + name = "Launch file", + type = "codelldb", + request = "launch", + program = function() + local path + vim.ui.input({ prompt = "Path to executable: ", default = vim.loop.cwd() .. "/build/" }, function(input) + path = input + end) + vim.cmd [[redraw]] + return path + end, + cwd = "${workspaceFolder}", + stopOnEntry = false, + }, + } + + dap.configurations.c = dap.configurations.cpp +end