emacs

Fangrui Song 2018-10-26 20:12:38 -07:00
parent dd582a52a4
commit f1e39cf0a4

@ -1,9 +1,8 @@
1. See [[Getting started]] to build the `ccls` executable
2. Install [lsp-mode](https://github.com/emacs-lsp/lsp-mode) and (optional) [lsp-ui](https://github.com/emacs-lsp/lsp-ui)
3. (optionally) Install [company-lsp](https://github.com/tigersoldier/company-lsp)
4. Install [emacs-ccls](https://github.com/MaskRay/emacs-ccls) and [configure](#configure) it
5. Open a source file where either [[.ccls|Getting-started#ccls]] or [[compile_commands.json]] is in the project root (it may work without them, though not recommended)
6. `M-x lsp-ccls-enable`. Don't invoke `M-x lsp-mode`. `lsp-ccls-enable` will turn on `lsp-mode` for you
2. Install [lsp-mode](https://github.com/emacs-lsp/lsp-mode) and optionally, [lsp-ui](https://github.com/emacs-lsp/lsp-ui) + [company-lsp](https://github.com/tigersoldier/company-lsp)
3. Install [emacs-ccls](https://github.com/MaskRay/emacs-ccls) (ccls on Melpa) and [configure](#configure) it
4. Open a source file where either [[.ccls|Getting-started#ccls]] or [[compile_commands.json]] is in the project root (it works without them, if you don't need extra compiler command line options like `-I`)
5. `M-x lsp-ccls-enable`. Don't invoke `M-x lsp-mode`. `lsp-ccls-enable` will turn on `lsp-mode` for you
Alternatively, you may install https://github.com/joaotavora/eglot
@ -26,15 +25,13 @@ The only required configuration is `ccls-executable`. Others have good defaults.
;; (setq ccls-extra-args '("--log-file=/tmp/cq.log"))
;; ;; Cache directory, both relative and absolute paths are supported
;; (setq ccls-cache-dir ".ccls-cache")
;; ;; Initialization options
;; (setq ccls-extra-init-params '(:completion (:detailedLabel t)))
```
A more flexible way is to leave `ccls-executable` unchanged (default: `ccls`) and create a shell wrapper named `ccls` that is in your `PATH`:
```zsh
#!/bin/zsh
#export CCLS_TRACEME=1 # if you want to debug ccls, stop it right after main() is called
#export LD_LIBRARY_PATH=~/llvm/release/lib # if you link against shared library libLLVM.so, not statically
#export LD_LIBRARY_PATH=~/llvm/Release/lib # if you link against shared library libLLVM.so, not statically
exec ~/ccls/Release/ccls --log-file=/tmp/ccls.log "$@"
```
@ -61,7 +58,7 @@ If you do not mind files in subprojects are treated as part of the whole project
To turn on ccls for all C/C++ modes:
```elisp
(defun ccls//enable ()
(defun +ccls/enable ()
(condition-case nil
(lsp-ccls-enable)
(user-error nil)))
@ -69,10 +66,12 @@ To turn on ccls for all C/C++ modes:
(use-package ccls
:commands lsp-ccls-enable
:init
(add-hook 'c-mode-hook #'ccls//enable)
(add-hook 'c++-mode-hook #'ccls//enable)
(add-hook 'c-mode-hook #'+ccls/enable)
(add-hook 'c++-mode-hook #'+ccls/enable)
(add-hook 'objc-mode-hook #'+ccls/enable)
(add-hook 'cuda-mode-hook #'+ccls/enable)
)
;; Also see lsp-project-whitelist lsp-project-blacklist ccls-root-matchers
;; Also see lsp-project-whitelist lsp-project-blacklist
```
### Diagnostics
@ -203,14 +202,6 @@ Add `company-lsp` to `company-backends`. ccls has a fuzzy matching algorithm to
(setq company-transformers nil company-lsp-async t company-lsp-cache-candidates nil)
```
Type `#i"` (or `#include "`) for quote-style includes and `#i<` (or `#include <`) for system headers.
There is an alternative view (irony-mode style):
```elisp
(setq ccls-extra-init-params '(:completion (:detailedLabel t)))
```
![company-lsp + company-quickhelp](https://ptpb.pw/AC6J.jpg)
### lsp-ui-flycheck
@ -273,9 +264,15 @@ For the long story, refer to the corresponding [emacs-devel thread](https://list
![$ccls/inheritance hierarchy:true](https://ptpb.pw/JkyT.gif)
### Code lens
`M-x ccls-code-lens-mode`
You may customize `ccls-code-lens-position`. It is `'end` by default, which puts code lenses at line ends (implemented with overlay's `'display` property). There is an issue that opening new lines may drag the lens to the next line.
### `ccls-navigate`
Think of them as `sp-{down,previous,next,down}-sexp` for C/C++, roughly movement among declarations.
Think of them as `sp-{down,previous,next,down}-sexp` for C/C++, roughly semantic movement among declarations.
```elisp
(ccls-navigate "D") ;; roughly sp-down-sexp
@ -291,8 +288,6 @@ https://www.reddit.com/r/emacs/comments/9dg13i/cclsnavigate_semantic_navigation_
### Misc
For out-of-band changes to the files in the workspace that are not made in the LSP client (e.g. git pull), call
`(ccls-freshen-index)` to rebuild indexes for every file or `(ccls-freshen-index (list "^/tmp/c/"))` to rebuild indexes for files matched by a regex whitelist.
`(ccls-reload)` to reload/rebuild indexes for every file.
* Discussion of symbol hierarchies (member hierarchy, inheritance hierarchy, call hierarchy) https://github.com/emacs-lsp/lsp-ui/issues/73
* Performance of lsp-ui-flycheck https://github.com/emacs-lsp/lsp-ui/issues/45
* A proposal to mention ccls in eglot https://github.com/joaotavora/eglot/pull/94