I'm new to neovim and I want to set it up for a c++ project. I'm using kickstart.nvim and have enabled clangd and added cpp to treesitter.
I'm having an issue where the LSP suggestion for std::endl
is not clever enough to see that I have already imported <iostream>
and that I'm using operator<<
on the stream so it should just select the symbol and not autocomplete to a function call.
How can I fix this to just autocomplete to std::endl
when the option is selected?
std::endl
is in fact a function, and can be used in this way:
std::endl(std::cout);
To implement the more common usage pattern:
std::cout << std::endl;
the standard library overloads operator<<
for std::endl
's function type.
From the point of view of editor tooling like clangd, std::endl
is no different than any other function, and clangd behaviours associated with functions (such as inserting parentheses and argument placeholders when accepting a code completion proposal) will apply to std::endl
as well.
Clangd does have an option to disable insertion of argument placeholders (for all functions, not just std::endl
): the command-line argument --function-arg-placeholders=false
. Note that parentheses will still be inserted; https://github.com/llvm/llvm-project/issues/63565 is on file about adding a more flexible option for governing this.
There is also https://github.com/clangd/clangd/issues/439 on file about changing behaviour for std::endl
specifically.