Using the latest C standard with clang lsp in nvim

Table of Contents

Tags:

I found the default clang language server does not adhere to the latest C standard (c23) and therefore cries about the use of bool - which is a new keyword in c231. Since I am using neovim and its lsp api 2, its a quick fix, at least with my config3.

Warning

I am using a nightly build of neovim, some apis and/or options may not be available in the latest stable build:

TEXT
1NVIM v0.11.0-dev-2074+gc982608226
2Build type: Release
3LuaJIT 2.1.1741730670
4Run "nvim -V1 -v" for more info

Previously I just kept a list of language servers I need and neovim does the rest (if the binary is installed and has the executable bit - mind you).

LUA
 1-- dotfiles/nvim/lua/teo/lsp.lua
 2local lspconfig = require "lspconfig"
 3local lsps = {
 4    "rust_analyzer",
 5    "gopls",
 6    "ts_ls",
 7    "html",
 8    "cssls",
 9    "lua_ls",
10    "clangd" -- this is removed in the next step
11    "hls"
12}
13for _, lsp in pairs(lsps) do
14    lspconfig[lsp].setup {}
15end

I didn’t think about the need of setting specific options for a single one of these, so I just define clangd and its option by hand - I dont need to overengineer this:

LUA
1lspconfig.clangd.setup {
2    init_options = {
3        fallbackFlags = { '--std=c23' }
4    },
5}