From 450995098bfc1b8978f5ed390301e62e7d6583a0 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Wed, 2 Oct 2019 19:24:55 -0700 Subject: [PATCH] lsp-mode: update contents and screenshot links --- lsp-mode.md | 42 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/lsp-mode.md b/lsp-mode.md index 3e04143..faeb1cd 100644 --- a/lsp-mode.md +++ b/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`) 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 +#### doom-emacs + +Set `(cc +lsp)` in your `~/.config/doom/init.el` + #### spacemacs 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 ccls - :hook ((c-mode c++-mode objc-mode) . + :hook ((c-mode c++-mode objc-mode cuda-mode) . (lambda () (require 'ccls) (lsp)))) ``` 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 (setq ccls-executable "/path/to/ccls/Release/ccls") ;; (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). -Some common settings to lsp-mode lsp-ui and emacs-ccls: - -* doom-emacs https://github.com/hlissner/doom-emacs/pull/716 -* MaskRay's doom-emacs configuration: +`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. #### 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-references](https://ptpb.pw/KUYz.jpg) - -![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/...) @@ -104,9 +96,10 @@ The identifier (or user-defined operator) at point is highlighted with its other ### 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. @@ -114,7 +107,9 @@ For a symbol named `Name::FooBar`, all of `FooBar`, `foo bar`, `nafoba` find the ### 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 ;; direct callers (lsp-find-custom "$ccls/call") @@ -183,7 +178,7 @@ Hierarchies provide a flattened xref interface: ### Documentation (comments) lsp-ui-doc.el renders comments in a child frame (Emacs >= 26) or inline (< 26). -![](https://camo.githubusercontent.com/fe1e12f9be72c2295d732d6265b42bde0d121ee8/68747470733a2f2f707470622e70772f5a6275462e6a7067) + ```elisp (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) ``` -![company-lsp + company-quickhelp](https://ptpb.pw/AC6J.jpg) +Install `company-quickhelp` to see the attached comments for the selected completion item. + + If completion does not work for you, make sure company-lsp is used: run M-x `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 `M-x ccls-member-hierarchy` -![$ccls/member hierarchy:true](http://fars.ee/qurU.jpg) + ```elisp (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) -Side notes: `ccls-inheritance-hierarchy` also works fine with jumping between primary template and partial specialization. ### Code lens