File: SettingUpLSPEmacs.md

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (76 lines) | stat: -rw-r--r-- 2,555 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# How to setup LSP + Emacs as a C++ IDE for Swift

This document describes how to setup a new emacs installation to use LSP and
other modes to create a C++ IDE for working on the compiler code base. It
enables autocompletion, lookup API at point, as well as formatting, renaming,
and syntax highlighting.

## Setting up Package.el for MELPA

Before we do anything, we need to setup package.el so we can grab packages from
[https://melpa.org/](MELPA) and GNU. This can be done by
including the below in your elisp startup file. Make sure it is run before any
other code is run.

```
(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(add-to-list 'package-archives '("gnu" . "http://elpa.gnu.org/packages/") t)
(package-initialize)
```

## Download packages

The packages needed as of this document being written (Jun 2022) are:

* use-package
* company
* lsp-mode
* lsp-ui
* helm-lsp
* lsp-treemacs

One can install these by running the command `package-install` inside emacs.

## Configuring LSP

Finally, now we need to configure out installation so everything is setup
correctly. This can be done by including the following in ones .emacs:

```
(use-package company
  :ensure t
  :config
  ;; Enable completion-as-you-type behavior.
  ;; don't add any dely before trying to complete thing being typed
  ;; the call/response to gopls is asynchronous so this should have little
  ;; to no affect on edit latency
  (setq company-idle-delay 0.1)
  ;; start completing after a single character instead of 3
  (setq company-minimum-prefix-length 1)
  ;; align fields in completions
  (setq company-tooltip-align-annotations t)
  )
(use-package lsp-mode
  :ensure t
  :commands (lsp lsp-deferred)
  :hook (c-mode-common . lsp)
  :custom
  ;; Prevent lsp from inserting header decorators.
  (lsp-clients-clangd-args '("--header-insertion-decorators=0" "--header-insertion=never"))
  :init
  ;; Enable easy local renaming using LSP
  (bind-key "C-x l" 'lsp-rename)
  :config
  ;; The CAPF back-end provides a bridge to the standard
  ;; completion-at-point-functions facility, and thus works with any major mode
  ;; that defines a proper completion function.
  (setq lsp-completion-provider :capf)
  (add-hook 'go-mode-hook #'lsp-go-install-save-hooks))

(use-package lsp-ui :commands lsp-ui-mode)
(use-package helm-lsp :commands helm-lsp-workspace-symbol
  :config
  (define-key lsp-mode-map [remap xref-find-apropos] #'helm-lsp-workspace-symbol))
(use-package lsp-treemacs :commands lsp-treemacs-errors-list)
```