LanguageClient-neovim
LanguageClient-neovim copied to clipboard
Improve project root detection for C/C++ files
When trying to detect the project root of C/C++ files, LanguageClient traverses the file tree upwards, starting from the directory of the file itself, to search for the compile_commands.json file (as per the function get_rootPath() in src/utils.rs).
That makes sense as long as the compilation database file is stored in the project root, and not for instance in a subdirectory. However, the user might store the compilation database in a different directory, and inform LanguageClient using the settings.json file, e.g.:
{
"initializationOptions": {
"compilationDatabaseDirectory": "<some_relative_path>"
}
}
In this case, I believe it would be more appropriate for the function get_rootPath() to look for <some_relative_path>/compile_commands.json, rather than just compile_commands.json. This could be achieved by passing the initializationOptions object to get_rootPath(), and retrieving the value of compilationDatabaseDirectory from that (provided they both exist).
I'd try to implement this myself, but I'm not really familiar with Rust. Is anyone willing to help?
By the way, very useful and promising plugin ;).
EDIT: A workaround would be to add the following to the init.vim file:
let g:LanguageClient_rootMarkers = {
\ 'c': ['<some_relative_path>/compile_commands.json'],
\ 'cpp': ['<some_relative_path>/compile_commands.json']
\ }
That's kind of a hard-coded trick though, plus it would be better to minimize user configuration.