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-11-17 17:57:46 +00:00
cquery is a highly-scalable, low-latency language server for C/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-04-18 04:57:16 +00:00
![Demo ](/images/demo.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
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-04-18 04:53:34 +00:00
$ git clone https://github.com/jacobdufault/cquery --recursive
$ cd cquery
$ ./waf configure
$ ./waf build
```
2017-05-12 07:15:17 +00:00
## Install extension
2017-04-25 20:54:37 +00:00
2017-05-12 07:15:17 +00:00
cquery includes a vscode extension; it is part of the repository. Launch vscode
and install the `vscode-extension.tsix` 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
**IMPORTANT:** Please reinstall the extension when you sync the code base - it is
still being developed.
2017-04-18 04:53:34 +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-17 15:52:30 +00:00
### compile_commands.json (Best)
2017-04-18 04:53:34 +00:00
To get the most accurate index possible, you can give cquery a compilation
database emitted from your build system of choice. For example, here's how to
generate one in ninja. When you sync your code you should regenerate this file.
```bash
2017-05-11 06:36:34 +00:00
$ ninja -C out/Release -t compdb cxx cc > compile_commands.json
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-17 15:52:30 +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-17 15:52:30 +00:00
### clang_args
2017-04-18 04:53:34 +00:00
If for whatever reason you cannot generate a `compile_commands.json` file, you
can add the flags to a file called `clang_args` located in the top-level
workspace directory.
Each argument in that file is separated by a newline. Lines starting with `#`
are skipped. Here's an example:
```
# Language
-xc++
-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
There are some additional tips on the [wiki ](https://github.com/jacobdufault/cquery/wiki ).
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