This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
spacemacs/layers/+tools/ycmd/README.org

96 lines
3.9 KiB
Org Mode
Raw Normal View History

#+TITLE: YCMD layer
2015-06-10 16:44:30 +00:00
2016-03-31 02:59:55 +00:00
* Table of Contents :TOC_4_gh:noexport:
- [[#description][Description]]
- [[#install][Install]]
- [[#layer][Layer]]
- [[#ycmd][YCMD]]
- [[#other-requirements][Other Requirements]]
- [[#configuration][Configuration]]
2016-08-29 14:23:34 +00:00
- [[#activating-ycmd-in-a-major-mode][Activating ycmd in a major mode]]
- [[#getting-the-compilation-flags][Getting the compilation flags]]
2016-03-31 02:59:55 +00:00
- [[#key-bindings][Key Bindings]]
2015-06-10 16:44:30 +00:00
* Description
2016-12-28 04:31:47 +00:00
This layer adds [[https://github.com/abingham/emacs-ycmd][emacs-ycmd]] support, including its integrations with company,
flycheck, and eldoc.
2015-06-10 16:44:30 +00:00
* Install
** Layer
To use this configuration layer, add it to your =~/.spacemacs=. You will need to
add =ycmd= to the existing =dotspacemacs-configuration-layers= list in this
file.
2015-06-10 16:44:30 +00:00
** YCMD
1) Install the =ycm= server. Installation instructions can be found [[https://github.com/Valloric/ycmd#building][here]].
2) Set the =ycmd-server-command= variable to reflect the path to the installation:
#+BEGIN_SRC emacs-lisp
(setq ycmd-server-command '("python" "/path/to/YouCompleteMe/third_party/ycmd/ycmd"))
#+END_SRC
Note that no filename expansions are done, so =~=-paths will not work out of the box.
If you need expansions, you can use Emacs's =file-truename= like this:
#+BEGIN_SRC emacs-lisp
(setq ycmd-server-command (list "python" (file-truename "~/some/path")))
#+END_SRC
2016-08-29 14:23:34 +00:00
3) By default, spacemacs configures ycmd for getting the compilation flags from either
a compile_commands.json or a .clang_complete file and get additionnal flags from a
.ycm_extra_flags file. If you do not like this behaviour, you can write your own
[[https://github.com/Valloric/YouCompleteMe/blob/master/README.md#c-family-semantic-completion][.ycm_extra_conf.py file]]. See [[#configuration][Configuration]] for more details.
4) Whitelist the file by adding the following to =.spacemacs=:
#+BEGIN_SRC emacs-lisp
;; In this example we whitelist everything in the Develop folder
(setq ycmd-extra-conf-whitelist '("~/Develop/*"))
#+END_SRC
5) The completion is not going to work automatically until we actually force it:
#+BEGIN_SRC emacs-lisp
(setq ycmd-force-semantic-completion t)
#+END_SRC
2015-06-10 16:44:30 +00:00
** Other Requirements
This package requires the =auto-completion= layer in order to get actual
completion. The =syntax-checking= layer is required for flycheck support.
* Configuration
2016-08-29 14:23:34 +00:00
** Activating ycmd in a major mode
By default this layer only activates ycmd for =c++-mode= and =c-mode=.
2015-06-10 16:44:30 +00:00
2016-04-21 03:18:12 +00:00
If you want ycmd support in other modes you might just want to add it for
2015-06-10 16:44:30 +00:00
specific languages like:
#+BEGIN_SRC emacs-lisp
(add-hook 'c++-mode-hook 'ycmd-mode)
#+END_SRC
2016-08-29 14:23:34 +00:00
** Getting the compilation flags
Spacemacs uses its own ycmd global configuration file. If you prefer, you can
write your own [[https://github.com/Valloric/YouCompleteMe/blob/master/README.md#c-family-semantic-completion][.ycm_extra_conf.py]].
Spacemacs will search for a compile_command.json or fall back to a
.clang_complete file in all parent directories of the current translation unit.
Spacemacs will try to make up for missing files in the compile_commands.json
using heuristics described in global_conf.py.
The user can provide additionnal flags by writing a .ycm_extra_flags in any
parent directory of the current translation unit. This is particularly useful
when cross-compiling.
Example .ycm_extra_flags:
#+BEGIN_SRC conf
# Additionnal flags for ycmd
--sysroot="/path/to/your/toolchain/libc" # if you are cross-compiling
#+END_SRC
If your build system doesn't handle the creation of a compile_commands.json,
you can use tools such as [[https://github.com/rizsotto/Bear][Bear]] or [[https://pypi.python.org/pypi/scan-build][scan-build]] to generate it, which both work
with almost any build system.
2015-06-10 16:44:30 +00:00
* Key Bindings
Adds ~SPC m g g~ go to definition binding to =c++-mode= as well as ~SPC m g G~
for the more imprecise but faster version.