Skip to content

Commit 1228265

Browse files
authored
Merge pull request #59412 from gottesmm/pr-42c3a6f19df445d0ceab9eecc10e1d84a8d8f7f4
[docs] Add a small howto on setting up LSP/Emacs as a C++ IDE for working on the compiler code base.
2 parents ae2b660 + 2342804 commit 1228265

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

docs/HowToGuides/SettingUpLSPEmacs.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# How to setup LSP + Emacs as a C++ IDE for Swift
2+
3+
This document describes how to setup a new emacs installation to use LSP and
4+
other modes to create a C++ IDE for working on the compiler code base. It
5+
enables autocompletion, lookup API at point, as well as formatting, renaming,
6+
and syntax highlighting.
7+
8+
## Setting up Package.el for MELPA
9+
10+
Before we do anything, we need to setup package.el so we can grab packages from
11+
[https://melpa.org/](MELPA) and GNU. This can be done by
12+
including the below in your elisp startup file. Make sure it is run before any
13+
other code is run.
14+
15+
```
16+
(require 'package)
17+
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
18+
(add-to-list 'package-archives '("gnu" . "http://elpa.gnu.org/packages/") t)
19+
(package-initialize)
20+
```
21+
22+
## Download packages
23+
24+
The packages needed as of this document being written (Jun 2022) are:
25+
26+
* use-package
27+
* company
28+
* lsp-mode
29+
* lsp-ui
30+
* helm-lsp
31+
* lsp-treemacs
32+
33+
One can install these by running the command `package-install` inside emacs.
34+
35+
## Configuring LSP
36+
37+
Finally, now we need to configure out installation so everything is setup
38+
correctly. This can be done by including the following in ones .emacs:
39+
40+
```
41+
(use-package company
42+
:ensure t
43+
:config
44+
;; Enable completion-as-you-type behavior.
45+
;; don't add any dely before trying to complete thing being typed
46+
;; the call/response to gopls is asynchronous so this should have little
47+
;; to no affect on edit latency
48+
(setq company-idle-delay 0.1)
49+
;; start completing after a single character instead of 3
50+
(setq company-minimum-prefix-length 1)
51+
;; align fields in completions
52+
(setq company-tooltip-align-annotations t)
53+
)
54+
(use-package lsp-mode
55+
:ensure t
56+
:commands (lsp lsp-deferred)
57+
:hook (c-mode-common . lsp)
58+
:custom
59+
;; Prevent lsp from inserting header decorators.
60+
(lsp-clients-clangd-args '("--header-insertion-decorators=0" "--header-insertion=never"))
61+
:init
62+
;; Enable easy local renaming using LSP
63+
(bind-key "C-x l" 'lsp-rename)
64+
:config
65+
;; The CAPF back-end provides a bridge to the standard
66+
;; completion-at-point-functions facility, and thus works with any major mode
67+
;; that defines a proper completion function.
68+
(setq lsp-completion-provider :capf)
69+
(add-hook 'go-mode-hook #'lsp-go-install-save-hooks))
70+
71+
(use-package lsp-ui :commands lsp-ui-mode)
72+
(use-package helm-lsp :commands helm-lsp-workspace-symbol
73+
:config
74+
(define-key lsp-mode-map [remap xref-find-apropos] #'helm-lsp-workspace-symbol))
75+
(use-package lsp-treemacs :commands lsp-treemacs-errors-list)
76+
```

0 commit comments

Comments
 (0)