cpp.lua 903 B

12345678910111213141516171819202122232425262728
  1. -- 在 ~/.config/nvim/lua/plugins/lsp.lua 中添加或修改
  2. return {
  3. {
  4. "neovim/nvim-lspconfig",
  5. opts = {
  6. servers = {
  7. clangd = {
  8. cmd = {
  9. "clangd",
  10. "--background-index",
  11. "--clang-tidy",
  12. "--header-insertion=never",
  13. "--completion-style=detailed",
  14. "--query-driver=/usr/bin/gcc,/usr/bin/g++,/usr/bin/clang,/usr/bin/clang++",
  15. "--all-scopes-completion",
  16. "--cross-file-rename",
  17. },
  18. filetypes = { "c", "cpp", "objc", "objcpp", "cuda" },
  19. -- 设置编译命令目录为CMake生成的compile_commands.json所在目录
  20. root_dir = function(fname)
  21. return require("lspconfig.util").root_pattern("compile_commands.json", "compile_flags.txt", ".git")(fname)
  22. or vim.fn.getcwd()
  23. end,
  24. },
  25. },
  26. },
  27. },
  28. }