2017-04-18 04:53:34 +00:00
# cquery
2017-04-26 01:47:10 +00:00
[![Join the chat at https://gitter.im/cquery-project/Lobby ](https://badges.gitter.im/Join%20Chat.svg )](https://gitter.im/cquery-project/Lobby?utm_source=badge& utm_medium=badge& utm_campaign=pr-badge& utm_content=badge)
2017-12-22 00:07:32 +00:00
cquery is a highly-scalable, low-latency language server for C/C++/Objective-C. It is tested
2017-06-14 07:08:25 +00:00
and designed for large code bases like
[Chromium ](https://chromium.googlesource.com/chromium/src/ ). cquery provides
accurate and fast semantic analysis without interrupting workflow.
2017-04-18 04:53:34 +00:00
2017-12-31 09:54:51 +00:00
![Demo ](https://ptpb.pw/GlSQ.png?raw=true )
2017-04-18 04:53:34 +00:00
2017-06-14 07:08:25 +00:00
cquery implements almost the entire language server protocol and provides
some extra features to boot:
2017-05-15 07:31:44 +00:00
* code completion (with both signature help and snippets)
2017-04-18 04:53:34 +00:00
* references
2017-06-14 07:08:25 +00:00
* type hierarchy (parent type, derived types, expandable tree view)
* calls to functions, calls to base and derived functions, call tree
* symbol rename
2017-04-18 04:53:34 +00:00
* goto definition, goto base method
2017-06-14 07:08:25 +00:00
* document and global symbol search
* hover tooltips showing symbol type
2017-05-10 06:13:56 +00:00
* diagnostics
2017-05-20 19:31:07 +00:00
* code actions (clang FixIts)
2017-05-20 21:45:46 +00:00
* darken/fade code disabled by preprocessor
2017-06-14 07:08:25 +00:00
* #include auto-complete, undefined type include insertion, include quick-jump
(goto definition, document links)
2017-05-29 23:57:56 +00:00
* auto-implement functions without a definition
2018-01-10 08:01:31 +00:00
* semantic highlighting, including support for [rainbow semantic highlighting ](https://medium.com/@evnbr/coding-in-color-3a6db2743a1e )
2017-04-18 04:53:34 +00:00
2017-05-12 07:15:17 +00:00
# Setup - build cquery, install extension, setup project
2017-04-18 04:53:34 +00:00
2017-05-12 07:15:17 +00:00
There are three steps to get cquery up and running. Eventually, cquery will be
published in the vscode extension marketplace which will reduce these three
steps to only project setup.
2017-04-18 04:53:34 +00:00
2017-05-12 07:15:17 +00:00
## Build cquery
Building cquery is simple. The external dependencies are few:
2017-06-14 07:08:25 +00:00
- relatively modern c++11 compiler (ie, clang 3.4 or greater)
2017-05-12 07:15:17 +00:00
- python
- git
2017-04-18 04:53:34 +00:00
```bash
2017-06-17 00:20:55 +00:00
$ clang --version # if missing, sudo apt-get install clang
2017-12-31 10:04:15 +00:00
$ git clone https://github.com/jacobdufault/cquery --single-branch
2017-04-18 04:53:34 +00:00
$ cd cquery
2017-12-31 10:04:15 +00:00
$ git submodule update --init
2017-12-12 08:11:46 +00:00
$ ./waf configure --prefix ~/.local/stow/cquery # --prefix is optional, it specifies install directory
$ ./waf build # -g -O3, built build/release/bin/cquery
$ ./waf install # optional, copies the executable to $PREFIX/bin/cquery
2017-12-12 05:14:13 +00:00
```
For a debug build:
```bash
$ ./waf configure --variant=debug
2017-12-12 08:11:46 +00:00
$ ./waf build --variant=debug # -g -O0, built build/debug/bin/cquery
2017-04-18 04:53:34 +00:00
```
2017-12-17 03:39:51 +00:00
See [wiki ](https://github.com/jacobdufault/cquery/wiki ) for more build instructions
(e.g. using system clang instead of bundled clang+llvm) and other topics.
2017-05-12 07:15:17 +00:00
## Install extension
2017-04-25 20:54:37 +00:00
2017-12-31 09:34:16 +00:00
cquery includes a vscode extension; it is released in < https: / / github . com / jacobdufault / cquery / releases > . Launch vscode
and install the `vscode-extension.vsix` extension. To do this:
2017-04-19 00:05:14 +00:00
2017-05-12 07:15:17 +00:00
- Hit `F1` ; execute the command `Install from VSIX` .
2017-07-06 21:19:22 +00:00
- Select `vscode-extension.vsix` in the file chooser.
2017-05-12 07:15:17 +00:00
2017-12-31 09:34:16 +00:00
**IMPORTANT:** Please reinstall the extension when you download it - it is
2017-05-12 07:15:17 +00:00
still being developed.
2017-04-18 04:53:34 +00:00
2018-01-10 07:30:05 +00:00
See the [wiki ](https://github.com/jacobdufault/cquery/wiki/Visual-Studio-Code#setting-up-the-extension ) for additional details on setting up the extension.
2018-01-05 17:00:30 +00:00
2017-04-18 05:03:48 +00:00
If you run into issues, you can view debug output by running the
(`F1`) `View: Toggle Output` command and opening the `cquery` output section.
2017-11-17 15:52:30 +00:00
## Project setup
2017-05-12 07:15:17 +00:00
2017-11-27 06:56:23 +00:00
### `compile_commands.json` (Best)
2017-04-18 04:53:34 +00:00
2017-11-27 06:56:23 +00:00
See [wiki ](https://github.com/jacobdufault/cquery/wiki ) for how to generate `compile_commands.json` with CMake, Build EAR, Ninja, ...
2017-04-18 04:53:34 +00:00
2017-11-27 12:14:01 +00:00
If the `compile_commands.json` is not in the top-level workspace directory,
then the `cquery.misc.compilationDatabaseDirectory` setting can be used to
specify its location.
2017-04-18 04:53:34 +00:00
2017-11-27 06:56:23 +00:00
### `cquery.index.extraClangArguments`
2017-04-18 04:53:34 +00:00
If for whatever reason you cannot generate a `compile_commands.json` file, you
2017-06-14 07:08:25 +00:00
can add the flags to the `cquery.index.extraClangArguments` configuration
option.
2017-04-18 04:53:34 +00:00
2017-11-27 06:56:23 +00:00
### `.cquery`
2017-04-18 04:53:34 +00:00
If for whatever reason you cannot generate a `compile_commands.json` file, you
2017-11-27 06:56:23 +00:00
can add the flags to a file called `.cquery` located in the top-level
2017-04-18 04:53:34 +00:00
workspace directory.
Each argument in that file is separated by a newline. Lines starting with `#`
2017-12-19 06:27:15 +00:00
are skipped. The first line can optionally be the path to the intended compiler,
which can help if the standard library paths are relative to the binary.
Here's an example:
2017-04-18 04:53:34 +00:00
```
2017-12-19 06:27:15 +00:00
# Driver
/usr/bin/clang++-4.0
2017-04-18 04:53:34 +00:00
# Language
2017-11-27 16:20:42 +00:00
-xc++
2017-04-18 04:53:34 +00:00
-std=c++11
# Includes
-I/work/cquery/third_party
```
2017-05-12 07:15:17 +00:00
# Building extension
If you wish to modify the vscode extension, you will need to build it locally.
Luckily, it is pretty easy - the only dependency is npm.
```bash
# Build extension
$ cd vscode-client
$ npm install
$ code .
```
When VSCode is running, you can hit `F5` to build and launch the extension
locally.
2017-04-18 04:53:34 +00:00
# Limitations
cquery is able to respond to queries quickly because it caches a huge amount of
information. When a request comes in, cquery just looks it up in the cache
without running many computations. As a result, there's a large memory overhead.
For example, a full index of Chrome will take about 10gb of memory. If you
2017-04-18 05:18:46 +00:00
exclude v8, webkit, and third_party, it goes down to about 6.5gb.
2017-04-18 04:53:34 +00:00
2017-11-26 20:28:41 +00:00
# Wiki
2017-11-27 06:56:23 +00:00
For Emacs/Vim/other editors integration and some additional tips, see [wiki ](https://github.com/jacobdufault/cquery/wiki ).
2017-11-26 20:28:41 +00:00
2017-06-16 23:41:06 +00:00
# Chromium tips
2017-06-17 00:20:55 +00:00
Chromium is a very large codebase, so cquery benefits from a bit of tuning.
Optionally add these to your settings:
```js
// Set slightly lower than your CPU core count to keep other tools responsive.
"cquery.misc.indexerCount": 50,
// Remove uncommonly used directories with large numbers of files.
"cquery.index.blacklist": [
".*/src/base/third_party/.*",
".*/src/native_client/.*",
".*/src/native_client_sdk/.*",
".*/src/third_party/.*",
".*/src/v8/.*",
".*/src/webkit/.*"
]
```
2017-06-16 23:41:06 +00:00
2017-04-18 04:53:34 +00:00
# License
2017-04-18 04:57:16 +00:00
MIT