mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-22 07:35:08 +00:00
lsp-mode: update contents and screenshot links
parent
085ff9bad3
commit
450995098b
42
lsp-mode.md
42
lsp-mode.md
@ -3,14 +3,12 @@
|
|||||||
3. Open a source file where either [[.ccls|Project-Setup#ccls-file]] or [[compile_commands.json|Project-Setup#compile_commandsjson]] is in the project root (it works without them, if you don't need extra compiler command line options like `-I`)
|
3. Open a source file where either [[.ccls|Project-Setup#ccls-file]] or [[compile_commands.json|Project-Setup#compile_commandsjson]] is in the project root (it works without them, if you don't need extra compiler command line options like `-I`)
|
||||||
4. `(require 'ccls)`, `M-x lsp`
|
4. `(require 'ccls)`, `M-x lsp`
|
||||||
|
|
||||||
`ccls.el` used to be based on the old interface `lsp-mode.el` of lsp-mode and the entry was `lsp-ccls-enable`.
|
|
||||||
|
|
||||||
`(require 'lsp)` and `M-x lsp` should be used instead now. See https://github.com/emacs-lsp/lsp-mode/issues/479 , the old interface `lsp-mode.el` is deperecated.
|
|
||||||
|
|
||||||
Alternatively, you may install https://github.com/joaotavora/eglot
|
|
||||||
|
|
||||||
### Configure
|
### Configure
|
||||||
|
|
||||||
|
#### doom-emacs
|
||||||
|
|
||||||
|
Set `(cc +lsp)` in your `~/.config/doom/init.el`
|
||||||
|
|
||||||
#### spacemacs
|
#### spacemacs
|
||||||
|
|
||||||
set `c-c++-backend` to `lsp-ccls` in the `+lang/c-c++` layer
|
set `c-c++-backend` to `lsp-ccls` in the `+lang/c-c++` layer
|
||||||
@ -23,14 +21,12 @@ set `c-c++-backend` to `lsp-ccls` in the `+lang/c-c++` layer
|
|||||||
(use-package company-lsp :commands company-lsp)
|
(use-package company-lsp :commands company-lsp)
|
||||||
|
|
||||||
(use-package ccls
|
(use-package ccls
|
||||||
:hook ((c-mode c++-mode objc-mode) .
|
:hook ((c-mode c++-mode objc-mode cuda-mode) .
|
||||||
(lambda () (require 'ccls) (lsp))))
|
(lambda () (require 'ccls) (lsp))))
|
||||||
```
|
```
|
||||||
|
|
||||||
The only required configuration is `ccls-executable`. Others have good defaults.
|
The only required configuration is `ccls-executable`. Others have good defaults.
|
||||||
|
|
||||||
`xref-find-definitions` (default: `M-.`) / highlighting of the symbol at point / type signature in echo area should work out-of-box. Read on for customization and more features.
|
|
||||||
|
|
||||||
```elisp
|
```elisp
|
||||||
(setq ccls-executable "/path/to/ccls/Release/ccls")
|
(setq ccls-executable "/path/to/ccls/Release/ccls")
|
||||||
;; (setq ccls-args '("--log-file=/tmp/ccls.log"))
|
;; (setq ccls-args '("--log-file=/tmp/ccls.log"))
|
||||||
@ -38,10 +34,7 @@ The only required configuration is `ccls-executable`. Others have good defaults.
|
|||||||
|
|
||||||
You may leave `ccls-executable` unchanged (default: `ccls`) and create a [shell script wrapper](Install#shell-script-wrapper).
|
You may leave `ccls-executable` unchanged (default: `ccls`) and create a [shell script wrapper](Install#shell-script-wrapper).
|
||||||
|
|
||||||
Some common settings to lsp-mode lsp-ui and emacs-ccls:
|
`xref-find-definitions` (default: `M-.`) / highlighting of the symbol at point / type signature in echo area should work out-of-box. Read on for customization and more features.
|
||||||
|
|
||||||
* doom-emacs https://github.com/hlissner/doom-emacs/pull/716
|
|
||||||
* MaskRay's doom-emacs configuration: <https://github.com/MaskRay/Config/blob/master/home/.config/doom/modules/private/my-cc/config.el>
|
|
||||||
|
|
||||||
#### Projects with subprojects
|
#### Projects with subprojects
|
||||||
|
|
||||||
@ -91,9 +84,8 @@ There are Helm/Ivy alternatives for `xref-find-{definitions,references,apropos}`
|
|||||||
|
|
||||||
`lsp-ui-peek-find-{definitions,references}` from [lsp-ui-peek.el](https://github.com/emacs-lsp/lsp-ui/blob/master/lsp-ui-peek.el) provide peek views. An additional benefit is you get a window local jump list dedicated to cross references (`lsp-ui-peek-jump-forward` `lsp-ui-peek-jump-backward`)
|
`lsp-ui-peek-find-{definitions,references}` from [lsp-ui-peek.el](https://github.com/emacs-lsp/lsp-ui/blob/master/lsp-ui-peek.el) provide peek views. An additional benefit is you get a window local jump list dedicated to cross references (`lsp-ui-peek-jump-forward` `lsp-ui-peek-jump-backward`)
|
||||||
|
|
||||||
![lsp-ui-peek-find-references](https://ptpb.pw/KUYz.jpg)
|
<img src="https://raw.githubusercontent.com/MaskRay/ccls-static/master/emacs-ccls/lsp-ui-xref.webp" title="lsp-ui-peek-find-references" width=70%>
|
||||||
|
<img src="https://raw.githubusercontent.com/MaskRay/ccls-static/master/emacs-ccls/reference-hydra.webp" title="references+hydra" width=70%>
|
||||||
![references + hydra](https://ptpb.pw/fhWh.jpg)
|
|
||||||
|
|
||||||
Refer to [MaskRay's doom-emacs configuration](https://github.com/MaskRay/Config/blob/master/home/.config/doom/modules/private/my-cc/autoload.el) for fine-grained `textDocument/references` (different roles: Read/Write/Dynamic/...)
|
Refer to [MaskRay's doom-emacs configuration](https://github.com/MaskRay/Config/blob/master/home/.config/doom/modules/private/my-cc/autoload.el) for fine-grained `textDocument/references` (different roles: Read/Write/Dynamic/...)
|
||||||
|
|
||||||
@ -104,9 +96,10 @@ The identifier (or user-defined operator) at point is highlighted with its other
|
|||||||
|
|
||||||
### imenu/workspace symbol search
|
### imenu/workspace symbol search
|
||||||
|
|
||||||
Use [lsp-imenu.el](https://github.com/emacs-lsp/lsp-mode/blob/master/lsp-imenu.el) for `textDocument/documentSymbol` (outline). [lsp-ui-imenu.el](https://github.com/emacs-lsp/lsp-ui/blob/master/lsp-ui-imenu.el) provides a sidebar.
|
There are two ways to invoke `textDocument/documentSymbol` (outline):
|
||||||
|
|
||||||
![lsp-imenu + hydra](https://ptpb.pw/XWw7.jpg)
|
* `M-x imenu`. Requires [lsp-imenu.el](https://github.com/emacs-lsp/lsp-mode/blob/master/lsp-imenu.el)
|
||||||
|
* `M-x lsp-ui-imenu`. Requires [lsp-ui-imenu.el](https://github.com/emacs-lsp/lsp-ui/blob/master/lsp-ui-imenu.el).
|
||||||
|
|
||||||
`xref-find-apropos` (default: `C-M-.`) invokes `workspace/symbol` to fuzzy-find symbols in the project. However, the function tries to be smart and splits the pattern and `regexp-quote` them for you, which actually gets in the way. Consider using `lsp-ui{,-peek}-workspace-symbol` in the lsp-ui package.
|
`xref-find-apropos` (default: `C-M-.`) invokes `workspace/symbol` to fuzzy-find symbols in the project. However, the function tries to be smart and splits the pattern and `regexp-quote` them for you, which actually gets in the way. Consider using `lsp-ui{,-peek}-workspace-symbol` in the lsp-ui package.
|
||||||
|
|
||||||
@ -114,7 +107,9 @@ For a symbol named `Name::FooBar`, all of `FooBar`, `foo bar`, `nafoba` find the
|
|||||||
|
|
||||||
### Cross reference extensions
|
### Cross reference extensions
|
||||||
|
|
||||||
Aside from definitions/references/workspace symbol, ccls provides some LSP extensions that find base/derived classes/methods, vars of a type, callers of a function. You may call:
|
See [[LSP Extensions]] for the description of these extensions.
|
||||||
|
|
||||||
|
You may call:
|
||||||
```elisp
|
```elisp
|
||||||
;; direct callers
|
;; direct callers
|
||||||
(lsp-find-custom "$ccls/call")
|
(lsp-find-custom "$ccls/call")
|
||||||
@ -183,7 +178,7 @@ Hierarchies provide a flattened xref interface:
|
|||||||
### Documentation (comments)
|
### Documentation (comments)
|
||||||
|
|
||||||
lsp-ui-doc.el renders comments in a child frame (Emacs >= 26) or inline (< 26).
|
lsp-ui-doc.el renders comments in a child frame (Emacs >= 26) or inline (< 26).
|
||||||
![](https://camo.githubusercontent.com/fe1e12f9be72c2295d732d6265b42bde0d121ee8/68747470733a2f2f707470622e70772f5a6275462e6a7067)
|
<img src="https://raw.githubusercontent.com/MaskRay/ccls-static/master/emacs-ccls/lsp-ui-doc.webp" title="lsp-ui-doc" width=70%>
|
||||||
|
|
||||||
```elisp
|
```elisp
|
||||||
(setq lsp-ui-doc-include-signature nil) ; don't include type signature in the child frame
|
(setq lsp-ui-doc-include-signature nil) ; don't include type signature in the child frame
|
||||||
@ -198,7 +193,9 @@ 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)
|
(setq company-transformers nil company-lsp-async t company-lsp-cache-candidates nil)
|
||||||
```
|
```
|
||||||
|
|
||||||
![company-lsp + company-quickhelp](https://ptpb.pw/AC6J.jpg)
|
Install `company-quickhelp` to see the attached comments for the selected completion item.
|
||||||
|
|
||||||
|
<img src="https://raw.githubusercontent.com/MaskRay/ccls-static/master/emacs-ccls/company-lsp.webp" title="company-lsp" width=50%>
|
||||||
|
|
||||||
If completion does not work for you, make sure company-lsp is used: run <kbd>M-x</kbd> `company-diag` and make sure`Used backend:` includes `company-lsp`.
|
If completion does not work for you, make sure company-lsp is used: run <kbd>M-x</kbd> `company-diag` and make sure`Used backend:` includes `company-lsp`.
|
||||||
|
|
||||||
@ -243,7 +240,7 @@ For the long story, refer to the corresponding [emacs-devel thread](https://list
|
|||||||
### Call/member/inheritance Hierarchies || primary template/partial specialization
|
### Call/member/inheritance Hierarchies || primary template/partial specialization
|
||||||
|
|
||||||
`M-x ccls-member-hierarchy`
|
`M-x ccls-member-hierarchy`
|
||||||
![$ccls/member hierarchy:true](http://fars.ee/qurU.jpg)
|
<img src="https://raw.githubusercontent.com/MaskRay/ccls-static/master/emacs-ccls/ccls-member.webp" title="$ccls/member hierarchy:true" width=70%>
|
||||||
|
|
||||||
```elisp
|
```elisp
|
||||||
(ccls-call-hierarchy nil) ; caller hierarchy
|
(ccls-call-hierarchy nil) ; caller hierarchy
|
||||||
@ -257,7 +254,6 @@ For the long story, refer to the corresponding [emacs-devel thread](https://list
|
|||||||
```
|
```
|
||||||
|
|
||||||
![$ccls/inheritance hierarchy:true](http://fars.ee/5pQO.jpg)
|
![$ccls/inheritance hierarchy:true](http://fars.ee/5pQO.jpg)
|
||||||
Side notes: `ccls-inheritance-hierarchy` also works fine with jumping between primary template and partial specialization.
|
|
||||||
|
|
||||||
### Code lens
|
### Code lens
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user