# YouCompleteMe integration

[YouCompleteMe](http://ycm-core.github.io/YouCompleteMe/) is a semantic
code-completion engine. YouCompleteMe works natively with Vim but it can also be
integrated with other editors through [ycmd](https://github.com/Valloric/ycmd).

## Install YouCompleteMe in your editor

See the [installation
guide](https://github.com/Valloric/YouCompleteMe#installation).

> [!NOTE]
> **Note:** Installing YCM on MacOS with Homebrew is not recommended because of library compatibility errors. Use the official installation guide instead.

## Generate compilation database

YouCompleteMe (and other tools like clang-tidy) require a [JSON compilation
database](https://clang.llvm.org/docs/JSONCompilationDatabase.html) that
specifies how each file is compiled. `fx` will automatically symlink the database,
`compile_commands.json`, from your current build directory to your source root.

If this database is not present, then Vim can be configured to fall back to the configuration
in [/scripts/youcompleteme/ycm_extra_conf.py](https://cs.opensource.google/fuchsia/fuchsia/+/main:/scripts/youcompleteme/ycm_extra_conf.py). See
[Vim configuration](https://fuchsia.dev/fuchsia-src/reference/tools/editors/vim) for how to set this up.

## Use it

YouCompleteMe will use `compile_commands.json` to do code completion and find
symbol definitions/declarations. See your editor's YouCompleteMe docs for
details. The editor should pick up `compile_commands.json` file automatically.

See [Vim setup](https://fuchsia.dev/fuchsia-src/reference/tools/editors/vim) for instructions on configuring Vim for Fuchsia development.

## Other editors (ycmd)

You'll need to set the ycmd config option `global_ycm_extra_conf` to point to
`${FUCHSIA_DIR}/scripts/youcompleteme/ycm_extra_conf.py`.
Note you may need to manually replace `${FUCHSIA_DIR}` with the correct path.

Alternatively, you can create a `.ycm_extra_conf.py` symbolic link to let YCM
automatically find the config for any fuchsia repository:

    ln -s $FUCHSIA_DIR/scripts/youcompleteme/ycm_extra_conf.py $FUCHSIA_DIR/.ycm_extra_conf.py

[](https://issues.fuchsia.dev/issues/new?component=1439230&template=1881640&description=Issue+on:+https://fuchsia.dev/docs/reference/tools/editors/youcompleteme.md "Report a bug or suggest improvements on this page") [](https://cs.opensource.google/fuchsia/fuchsia/+/main:docs/reference/tools/editors/youcompleteme.md "View the source code of this page") [](https://ci.android.com/edit?repo=fuchsia/fuchsia/main&file=docs/reference/tools/editors/youcompleteme.md&cloneRepo=fuchsia/fuchsia:refs/heads/main&fullPath=fuchsia/docs/reference/tools/editors/youcompleteme.md "Edit the source code of this page")