cquery doesnt understand relative paths in compile_commands.json
Build cquery:
% cd cquery
% ./waf configure
% ./waf build
# generates build/app
neovim configuration:
Install https://github.com/autozimu/LanguageClient-neovim
# Courtesy of https://github.com/autozimu/LanguageClient-neovim/wiki/cquery
let g:LanguageClient_serverCommands = {
\ 'cpp': ['..../cquery/build/app', '--language-server'],
\ }
let g:LanguageClient_loadSettings = 1
% cd $PROJECT
% cat .vim/settings.json
{
"initializationOptions": {
"cacheDirectory": "/tmp/cquery"
}
}
% mkdir /tmp/cquery
Editing in neovim
Edit an file with neovim.
% cd /tmp/c
% cat > a.cc <<e
int foo() { return 42; }
int main() { return foo(); }
e
% echo 'a: a.cc' > Makefile
% bear make # courtesy of https://github.com/rizsotto/Bear
# generates compile_commands.json
% cd /tmp; ln -s ~/Dev/Util/cquery/clang_resource_dir # by default, cquery somehow sets -resource-dir=/tmp/c/../clang_resource_dir # I have to use the hack here
% nvim a.cc
:LanguageClientStart
:call LanguageClient_textDocument_hover()
neovim complains {"jsonrpc": "2.0", "error": {"code": -32603, "message": "Unable to find file /tmp/c/a.cc"}, "id": 1}
compile_commands.json:
[
{
"arguments": [
"c++",
"-c",
"-o",
"a",
"a.cc"
],
"directory": "/tmp/c",
"file": "a.cc"
}
]
cquery_diagnostics.log:
arguments: /home/maskray/Dev/Util/cquery/build/app --language-server
Current dir: /tmp/c
File verbosity level: 9
date time ( uptime ) [ thread name/id ] file:line v|
2017-11-18 22:34:42.796 ( 0.000s) [main thread ] loguru.hpp:1952 0| Logging to 'cquery_diagnostics.log', mode: 'w', verbosity: 9
2017-11-18 22:34:42.797 ( 0.001s) [querydb ] command_line.cc:1429 0| [querydb] Initialize in directory /tmp/c with uri file:///tmp/c
2017-11-18 22:34:42.797 ( 0.001s) [querydb ] command_line.cc:1480 0| Using -resource-dir=/home/maskray/Dev/Util/cquery/clang_resource_dir
2017-11-18 22:34:42.797 ( 0.001s) [stdout ] timer.cc:38 0| [e2e] Running initialize took 0.383ms
2017-11-18 22:34:42.797 ( 0.001s) [querydb ] command_line.cc:1557 0| Starting 3 indexers
2017-11-18 22:34:42.797 ( 0.001s) [querydb ] project.cc:235 0| Trying to load compile_commands.json
2017-11-18 22:34:42.798 ( 0.001s) [querydb ] timer.cc:38 0| compile_commands.json clang time took 0.40ms
2017-11-18 22:34:42.798 ( 0.001s) [querydb ] timer.cc:38 0| compile_commands.json our time took 0.31ms
2017-11-18 22:34:42.798 ( 0.001s) [querydb ] timer.cc:38 0| [perf] Loaded compilation entries (1 files) took 0.303ms
2017-11-18 22:34:42.798 ( 0.002s) [querydb ] timer.cc:38 0| [perf] Dispatched initial index requests took 0.5ms
2017-11-18 22:34:42.798 ( 0.002s) [include_scanner ] timer.cc:38 0| [perf] Scanning for includes took 0.428ms
2017-11-18 22:34:42.799 ( 0.002s) [indexer2 ] command_line.cc:950 0| Parsing /tmp/c/a.cc
2017-11-18 22:34:42.802 ( 0.006s) [stdin ] language_server_api.cc:164 ERR| Unable to find registered handler for method "workspace/didChangeConfiguration"
2017-11-18 22:34:42.806 ( 0.010s) [querydb ] command_line.cc:118 0| Unable to find file "/tmp/c/a.cc"
2017-11-18 22:34:42.806 ( 0.010s) [querydb ] timer.cc:38 0| [querydb] Loading cached index file for DidOpen (blocks CodeLens) took 0.137ms
2017-11-18 22:34:42.806 ( 0.010s) [completeparse ] clang_complete.cc:273 0| Creating completion session with arguments c++, a.cc, -xc++, -std=c++11, -resource-dir=/home/maskray/Dev/Util/cquery/clang_resource_dir, -fparse-all-comments, -fspell-checking
2017-11-18 22:34:42.806 ( 0.010s) [indexer0 ] command_line.cc:950 0| Parsing /tmp/c/a.cc
2017-11-18 22:34:42.830 ( 0.034s) [indexer2 ]clang_translation_unit.cc:49 ERR| libclang had ast read error for /tmp/c/a.cc with args c++, a.cc, -xc++, -std=c++11, -resource-dir=/home/maskray/Dev/Util/cquery/clang_resource_dir
2017-11-18 22:34:42.831 ( 0.035s) [indexer0 ]clang_translation_unit.cc:49 ERR| libclang had ast read error for /tmp/c/a.cc with args c++, a.cc, -xc++, -std=c++11, -resource-dir=/home/maskray/Dev/Util/cquery/clang_resource_dir
2017-11-18 22:34:42.832 ( 0.036s) [completeparse ]clang_translation_unit.cc:49 ERR| libclang had ast read error for /tmp/c/a.cc with args c++, a.cc, -xc++, -std=c++11, -resource-dir=/home/maskray/Dev/Util/cquery/clang_resource_dir, -fparse-all-comments, -fspell-checking
2017-11-18 22:34:48.720 ( 5.924s) [querydb ] command_line.cc:118 0| Unable to find file "/tmp/c/a.cc"
2017-11-18 22:35:01.246 ( 18.450s) [querydb ] command_line.cc:118 0| Unable to find file "/tmp/c/a.cc"
Stack trace:
7 0x7fe08534aa8f clone + 63
6 0x7fe0860a9494 /lib/x86_64-linux-gnu/libpthread.so.0(+0x7494) [0x7fe0860a9494]
5 0x7fe085bd5e6f /usr/lib/x86_64-linux-gnu/libstdc++.so.6(+0xb9e6f) [0x7fe085bd5e6f]
4 0x52ef8d /home/maskray/Dev/Util/cquery/build/app() [0x52ef8d]
3 0x43b509 /home/maskray/Dev/Util/cquery/build/app() [0x43b509]
2 0x47d6ea /home/maskray/Dev/Util/cquery/build/app() [0x47d6ea]
1 0x47c1bc /home/maskray/Dev/Util/cquery/build/app() [0x47c1bc]
0 0x47ff46 /home/maskray/Dev/Util/cquery/build/app() [0x47ff46]
2017-11-18 22:36:12.495 ( 89.699s) [stdin ] language_server_api.cc:129 FATL| std::cin.good() is false; exiting
i think this happens when it tries to go through symlinks - could that be the case?
This is the compile_commands.json generated by bear.
[
{
"arguments": [
"c++",
"-c",
"-o",
"a",
"a.cc"
],
"directory": "/tmp/c",
"file": "a.cc"
}
]
a.cc not being an absolute path makes cquery failing to parse it.
If /tmp/c/a.cc is used instead, it will work.
Another problem that gives this error, is editing a file from a symlink.
I have cquery at /opt/cquery, and a symlink at ~/Documents/Programming/cquery
If i index the files from /opt/cquery and then edit a file from the symlink, cquery doesnt follow the link, and reports a Unable to find file
What is the solution to this issue ("Unable to find file ****",...) ?
I have downloaded the master branch and rebuilt cquery but still getting the same issue.
Can you post a new issue with your a fragment of your compile_commands.json?
cquery may report unable to find file until parsing is done.