Add clangd LSP support
dblume

dblume commited on 2025-05-20 13:24:26
Showing 2 changed files, with 17 additions and 0 deletions.


This is a feature in progress. Hopefully it fails gracefully when
clangd is not available.

LSP uses floating windows, so had to add styles for them.
I'm not done with settings or they keymaps.
... ...
@@ -40,6 +40,9 @@ hi htmlBold     term=bold cterm=bold ctermfg=white ctermbg=237 gui=bold
40 40
 hi htmlBoldItalic term=bold,italic cterm=bold,italic ctermfg=white ctermbg=24 gui=bold,italic
41 41
 hi htmlStrike   ctermfg=248 ctermbg=235
42 42
 
43
+hi NormalFloat  cterm=NONE ctermbg=236
44
+hi FloatBorder cterm=NONE ctermbg=233
45
+
43 46
 hi MyTagListTagName ctermbg=25
44 47
 
45 48
 "vim: sw=4
... ...
@@ -453,6 +453,17 @@ let g:rainbow_active = 1 "set to 0 if you want to enable it later via :RainbowTo
453 453
 
454 454
 " See https://wiki.dlma.com/neovim#cscope
455 455
 lua << EOF
456
+
457
+  vim.lsp.config.clangd = {
458
+    cmd = { 'clangd', '--background-index' },
459
+    root_markers = { '.git', '.clang-format', '.editorconfig' },
460
+    filetypes = { 'c', 'cpp' },
461
+  }
462
+  vim.keymap.set("n", "<Leader>d", ":lua vim.diagnostic.open_float(0, {scope='line'})<CR>", { desc = "Show diagnostics" })
463
+  vim.keymap.set("n", "gl", ":lua vim.diagnostic.open_float({ border = 'rounded' })<CR>", { desc = "Show diagnostic fixes" })
464
+  
465
+  vim.lsp.enable({'clangd'})
466
+
456 467
   require('cscope_maps').setup({ 
457 468
     disable_maps = true, -- Mapping C-] to :Cstag <cword> worse than :tag <cword>
458 469
   -- Alternatively, if we liked the mappings, then customise these two:
... ...
@@ -489,6 +500,9 @@ lua << EOF
489 500
       -- https://github.com/CopilotC-Nvim/CopilotChat.nvim
490 501
       chat.setup({
491 502
         model = 'claude-3.7-sonnet',
503
+--        question_header = " 👤 ",
504
+--        answer_header = " 🤖 ",
505
+--        error_header = " ❗ ", 
492 506
         question_header = '  ',
493 507
         answer_header = '   ',
494 508
         error_header = '  '
495 509