-
Notifications
You must be signed in to change notification settings - Fork 162
FAQ
There are at least three sets of implicit include paths. They take effect without your -I
option in .cquery
or compile_commands.json
// a.cc
// system C header, usually in /usr/include
#include <stdio.h>
// system C++ header. The location varies among distributions, e.g. /usr/include/c++/{6,7.2.1}
#include <new>
// In Clang resource directory
#include <stddef.h>
Put a.cc
in some directory with echo clang++ > .cquery
. Open the file, you should be able to jump to stdio.h
new
stddef.h
when you trigger textDocument/definition
on the include lines.
If cacheDirectory
is /tmp/cquery
(Emacs: .cquery_cached_index
), and the source file is /tmp/c/a.cc
, jq . < /tmp/cquery/@tmp@c/a.cc.json
to see if -resource-dir
is correct, e.g. "-resource-dir=/home/ray/Dev/Util/cquery/build/debug/lib/clang+llvm-5.0.1-x86_64-linux-gnu-ubuntu-14.04/lib/clang/5.0.1"
system C/C++ headers can be detected reliably. For Clang resource directory, there is logic in wscript
to detect it when you run ./waf configure [OPTIONS]
- For
--bundled-clang=5.0.1
:../lib/clang+llvm-5.0.1-x86_64-linux-gnu-ubuntu-14.04/lib/clang/5.0.1
which is relative to thebuild/release/bin/cquery
executable. The relative path ofbuild/release/bin/cquery
andbuild/release/lib/
cannot change, otherwise libclang.so used by cquery cannot find the Clang resource directory. - For
--use-system-clang
: it is recognized from-resource-dir
option in the output ofclang++ '-###' -xc /dev/null
)
./waf configure --prefix /tmp/opt && ./waf install
If you want the cquery binary at a specific location use a symlink - do not move the binary itself.
For C++ projects, compile_commands.json
is used by emacs-cquery to mark the project root. This is usually a symlink to the real compile_commands.json
in a build directory:
proj
build
gen
generated_file_in_build.cc
compile_commands.json
compile_commands.json -> build/compile_commands.json
In this example, the :rootUri
of the generated C++ file is proj/build/
because of proj/build/compile_commands.json
. However, the user wants it to be proj/
.
textDocument/definition
can be used in many places. Some are current implementation details and may subject to change.
-
void foo();
A declaration jumps to the definition -
void foo() {}
The definition lists all declarations -
A a;
For variables of custom types, besides declarations of the variable, both the type and the variable jump to the declaration/definition of its typeA
-
class C {
jumps to declarations (and constructors/destructors) -
a.field
jumps to the member in the struct declaration -
#include <map>
jumps to the header -
std::string a = "a";
takes you to the constructor. Many implicit constructors can also be jumped in this way. -
a == b
operator==
for user defined operators -
namespace ns {
find original or extension namespaces -
// ns::foo
in comments, it recognizes the identifier around the cursor, approximately finds the best matching symbol and jumps to it; onns
, it jumps to the namespace
-
#include <iostream>
lists all#include
lines in the project pointing to the included file -
[](){}
lists all(?) lambda expressions thanks to implicitstd::function
move constructor -
extern int a;
IfReferenceContext.includeDeclaration
is true, the definition and declarations are also listed.
-
struct A:B{void f()override;};
listsB
orB::f()
-
struct B{virtual void f();};
derived classes or virtual function overrides
-
A a;
lists all instances of user-definedA
. -
int i;
lists all instances ofint
.
Recursively list members of a record type. 😂 nobody has implemented UI for the feature. Help wanted!