p00f / clangd_extensions.nvim

Clangd's off-spec features for neovim's LSP client. Use https://sr.ht/~p00f/clangd_extensions.nvim instead
MIT License
448 stars 16 forks source link

[Help wanted] pass c++17 standard to clangd server in init.lua #35

Closed sekirocc closed 1 year ago

sekirocc commented 1 year ago

Hi, in my init.lua i have the following config.

require("clangd_extensions").setup{}

but i get this warning in my c++11 project. image

after i set c++ standards in .clangd file, like this

CompileFlags:
  Add: [-xc++, -Wall, -std=c++17]
  Compiler: clang++

the warning gone! but i really don't want to add this extra file in every projects...

How can i set this in the init.lua config?

Maybe need to tweak something in the setup{}, but i'm really new in vim lsp stuff... i googled and tried the following, still have no luck..

local clangd_defaults = require "lspconfig.server_configurations.clangd"
local clangd_configs = vim.tbl_deep_extend("force", clangd_defaults["default_config"], {
    cmd = {
        "clangd",
        "-j=4",
        "--background-index",
        "--clang-tidy",
        "--fallback-style=llvm",
        "--all-scopes-completion",
        "--completion-style=detailed",
        "--header-insertion=iwyu",
        "--header-insertion-decorators",
        "--pch-storage=memory",
    },
    initialization_options = {
        fallback_flags = { "-std=c++17" },
    },
})
require("clangd_extensions").setup{
    server = clangd_configs,
}
p00f commented 1 year ago

you want

require("clangd_extensions").setup{
   server = {
      cmd = {
         "clangd",
         "-j=4",
         "--background-index",
         "--clang-tidy",
         "--fallback-style=llvm",
         "--all-scopes-completion",
         "--completion-style=detailed",
         "--header-insertion=iwyu",
         "--header-insertion-decorators",
         "--pch-storage=memory",
      },
      initialization_options = {
         fallback_flags = { "-std=c++17" },
      },
   },
}
sekirocc commented 1 year ago

Hi, thanks for your reply! but sorry i tried the settings, it didn't work either.

p00f commented 1 year ago

For standard you can also add

If:
  PathMatch: [.*\.cpp, .\*.cc, .\*.cxx, .\*.hh, .\*.hpp, .\*.hxx]
CompileFlags:
  Add: [-std=c++17]

to your clangd config file (which is ~/.config/clangd/config.yaml on linux)

That said, I don't know why that doesn't work for you, it works for #15

sekirocc commented 1 year ago

ok, put it in ~/.config/clangd/config.yaml is a good & simple way to enable compile flags globally, thanks!