1# Editor integration for Zircon 2 3## YouCompleteMe 4 5[YouCompleteMe](https://valloric.github.io/YouCompleteMe/) is a semantic 6code-completion engine. YouCompleteMe works natively with Vim but it can also be 7integrated with other editors through [ycmd](https://github.com/Valloric/ycmd). 8 9### Install YouCompleteMe in your editor 10 11See the [installation 12guide](https://github.com/Valloric/YouCompleteMe#installation). 13 14**Note**: Installing YCM on MacOS with Homebrew is not recommended because of 15library compatibility errors. Use the official installation guide instead. 16 17#### gLinux (Googlers only) 18 19(This applies to anyone compiling on gLinux, even if editing over SSHFS on 20MacOS) Ignore the above. Search the Google intranet for "YouCompleteMe" for 21installation instructions. 22 23### Generate compilation database 24 25YouCompleteMe (and other tools like clang-tidy) require a [JSON compilation 26database](https://clang.llvm.org/docs/JSONCompilationDatabase.html) that 27specifies how each file is compiled. This database is normally stored in a file 28called `compile_commands.json`. There are multiple ways to generate this 29database for Zircon. 30 31#### compiledb-generator 32 33[compiledb-generator](https://github.com/nickdiego/compiledb-generator) is the 34recommended way to generate a compilation database. It works by running make in 35no-op mode and parsing the output. Thus it may be less accurate than bear, but 36it should be able to produce a complete database very quickly and without 37requiring a clean build. 38 39To use it, download it from GitHub and run (ensure that compiledb is in your PATH) 40 41```bash 42cd "${ZIRCON_DIR}" 43compiledb -o compile_commands.json -n make <make args> 44``` 45 46#### Bear 47 48Bear intercepts `exec(3)` calls made during a build and scrapes commandlines 49that look like C/C++ compiler invocations. Thus it is guaranteed to accurately 50capture the commands used during compilation. However it can't incrementally 51maintain a compilation database, so it requires performing a clean build. 52 53##### Install Bear 54 55You can try using your system's package manager (apt-get, brew) to install Bear, 56but you will need version 2.2.1 or later to match the compiler names that Zircon 57uses. Both homebrew's and Debian testing's versions are sufficiently new. You 58can also fall back to installing it from 59[GitHub](https://github.com/rizsotto/Bear). 60 61##### Invoke Bear on the Zircon build system 62 63You'll need to do this whenever the sources or makefiles change in a way that 64affects includes or types, or when you add/delete/move files, though it doesn't 65hurt to use a stale database. 66 67As easy as: 68 69```bash 70cd "${ZIRCON_DIR}" 71make clean 72bear make -j$(getconf _NPROCESSORS_ONLN) 73``` 74 75This will create a `compile_commands.json` file in the local directory. 76 77### Use it 78 79YouCompleteMe will use `compile_commands.json` to do code completion and find 80symbol definitions/declarations. See your editor's YouCompleteMe docs for 81details. 82 83It should pick up the `json` file automatically. If you want to move it out of 84the `zircon` tree, you can move the file to its parent directory. 85 86## See also 87 88For Fuchsia integration, see 89https://fuchsia.googlesource.com/scripts/+/master/vim/README.md 90