How to make clangd support more file types(different file extensions).
e.g. .ixx
、.mpp
(C++20 Modules)
override filetypes
in the setup {} call to be a list that includes all filetypes you wish clangd to operate on. I would copy the defaults from clangd.lua
Hmm… It’s not OK.
This is my config:
require 'lspconfig'.clangd.setup {
filetypes = { "c", "cpp", "cc", "mpp", "ixx" }
}
It’s OK for c, cpp and cc, but not OK for mpp or ixx.
What is :set ft?
in an mpp/ixx file? What does :LspInfo
say when you open one of those files? Make sure you are not calling setup {}
twice.
:set ft?
filetype=
:LspInfo
0 client(s) attached to this buffer:
It looks like you haven’t set up a filetype plugin for mpp or ixx. Trivially you can add the following two lines to your config, but you probably want to search around for a vim-mpp/ixx.
vim.cmd [[ autocmd BufRead,BufNewFile *.mpp set filetype=mpp ]]
vim.cmd [[ autocmd BufRead,BufNewFile *.ixx set filetype=ixx ]]
I added them to my init.vim
file, but then I got an error: E682: Invalid search pattern or delimiter
I deleted vim.cmd [[ ]]
then the error disappeared.
But the clangd
said:"Unable to handle compilation, expected exactly one compiler job in ’ ’ "
:set ft?
filetype=mpp
:LspInfo
1 client(s) attached to this buffer:
Client: clangd (id: 1, pid: 8596, bufnr: [1])
filetypes: c, cpp, objc, objcpp, cc, mpp, ixx
autostart: true
root directory: C:/Users/***/AppData/Local/nvim
cmd: clangd
Did you succesfully generate a compile_commands.json for your project?
No, I don’t.
But I try to add a compile_commands.json
And then, it’s ok.
Thank you!