Reputation: 105
I have installed nvim-lspconfig and nvim-cmp plugins for Neovim. A code completion with ccls works pretty well for .cpp
and .hpp
file extensions. I want to make code completion to also work with .tpp
file extension. I have created tpp.vim
file inside ~/.config/nvim/ftdetect
directory, which contains au BufRead,BufNewFile *.tpp set filetype=cpp
Vim script. After doing this, syntax highlighting started to work for .tpp
file, but code completion not.
vim.filetype.add({
extension = {
tpp = "cpp",
},
})
I have also added these lines of code inside ~/.config/nvim/init.lua
file, code completion still not wants to start working. So with all of that I have done - only syntax highlighting started to work for .tpp
file extension, but code completion not. How can I make code completion to also start working for this file extension?
lspconfig: require("lspconfig.health").check()
LSP configs active in this session (globally) ~
- Configured servers: ccls
- OK Deprecated servers: (none)
LSP configs active in this buffer (bufnr: 1) ~
- Language client log: ~/.local/state/nvim/lsp.log
- Detected filetype: `cpp`
- 1 client(s) attached to this buffer
- Client: `ccls` (id: 1, bufnr: [1])
root directory: ~/TurboINI/
filetypes: c, cpp, objc, objcpp, cuda
cmd: /usr/local/bin/ccls
version: `Debian ccls version 0.20241108-2-g4331c895`
executable: true
autostart: true
Even tho LSP detected that this file's extension is related to C++, but code completion still not wants to work:
I assume that solution to this is hiding in ccls and not in Neovim plugins.
P.S. I have found an article on how to make a specific file extensions behave exactly like standard C++ extensions on vi.stackexchange.com, I have tried it out and ccls still not wants to do code completion. In principe code completion works, but as database it takes already what you have typed in a file, as an example if I typed #include <iostream>
its database will only contain #include
and <iostream>
and nothing else.
Upvotes: 2
Views: 91
Reputation: 105
As @HighCommander4 mentioned on GitHub
.tpp
is not a file extension that clang recognizes as a C++ file type.You can nonetheless get clangd to process a
.tpp
file as C++ if you specify a-xc++
flag explicitly in the compile command (using, for example, a clangd config file).
To make code completion work for non-standard C++ file extension, I have to specify -xc++
argument to a compiler, e.g. g++ -xc++
or clang -xc++
, because GCC and clang are not recognizing .tpp
as C++ file extension.
So for clangd, in .clangd
config file I have to add an -xc++
argument and it will look like this:
CompileFlags:
Add: [-xc++]
And for ccls .ccls
configuration file using GCC compiler it will look like this:
g++
-xc++
Hooray! Finally code completion for .tpp
file started to work!
Upvotes: 0