2020-01-27 02:11:10 +01:00
|
|
|
;;; lsp.el --- Language Server Protocol. -*- lexical-binding: t; -*-
|
|
|
|
|
2020-12-07 15:28:43 +01:00
|
|
|
;; Time-stamp: <2020-12-07T15:03:32+0100>
|
2020-01-27 02:11:10 +01:00
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
2020-03-18 15:00:17 +01:00
|
|
|
(require 'basics/package-management)
|
2020-01-27 02:11:10 +01:00
|
|
|
(require 'basics/global-variables)
|
2020-03-10 13:00:22 +01:00
|
|
|
(require 'programming/common)
|
2020-01-27 02:11:10 +01:00
|
|
|
|
|
|
|
(unless slow-computer
|
|
|
|
;; Client for Language Server Protocol servers.
|
|
|
|
(use-package lsp-mode
|
|
|
|
:if (executable-find "clangd")
|
|
|
|
:defines (lsp-clients-clangd-args)
|
2020-02-11 17:59:12 +01:00
|
|
|
:diminish lsp-mode
|
2020-03-09 15:14:43 +01:00
|
|
|
:custom ((lsp-prefer-flymake nil) ; Disable flymake.
|
|
|
|
(lsp-auto-guess-root t) ; Don't ask for project root.
|
2020-07-07 05:31:05 +02:00
|
|
|
(lsp-eldoc-render-all t)
|
|
|
|
(lsp-restart 'auto-restart)
|
2020-07-07 05:34:19 +02:00
|
|
|
(lsp-enable-semantic-highlighting t) ; Needs clangd 11(?).
|
2020-12-01 18:27:57 +01:00
|
|
|
(lsp-semantic-tokens-apply-modifiers t)
|
2020-08-28 03:42:28 +02:00
|
|
|
(lsp-prefer-capf t)
|
2020-12-02 09:06:22 +01:00
|
|
|
(lsp-keymap-prefix "C-c l")
|
|
|
|
(lsp-keep-workspace-alive nil))
|
2020-12-01 18:27:57 +01:00
|
|
|
:custom-face
|
|
|
|
;; Semantic highlighting. TODO: Check later if better options are available.
|
|
|
|
(lsp-face-semhl-variable ((t (:inherit font-lock-variable-name-face
|
|
|
|
:italic t))))
|
|
|
|
(lsp-face-semhl-parameter ((t (:inherit font-lock-variable-name-face
|
|
|
|
:italic t :underline t))))
|
2020-12-01 19:47:50 +01:00
|
|
|
(lsp-face-semhl-member ((t (:inherit default :weight semibold))))
|
|
|
|
(lsp-face-semhl-enum ((t (:inherit font-lock-type-face))))
|
2020-03-09 15:14:43 +01:00
|
|
|
:config (progn
|
|
|
|
(setq lsp-clients-clangd-args '("--compile-commands-dir=build"))
|
|
|
|
;; Add “-clang-tidy” to clangd args if the version supports it.
|
|
|
|
(when (>= (my/clangd-version) 9.0)
|
|
|
|
(add-to-list 'lsp-clients-clangd-args "--clang-tidy" t))
|
|
|
|
;; Mark lsp-clients-clangd-args as safe to override.
|
|
|
|
(put 'lsp-clients-clangd-args 'safe-local-variable #'consp))
|
2020-03-27 17:04:09 +01:00
|
|
|
:bind ("C-c C-f" . lsp-execute-code-action)
|
2020-03-09 15:14:43 +01:00
|
|
|
:hook ((c++-mode . lsp)
|
2020-07-07 05:34:19 +02:00
|
|
|
(c-mode . lsp)
|
2020-12-01 21:00:37 +01:00
|
|
|
(python-mode . lsp)
|
2020-12-07 15:28:43 +01:00
|
|
|
(nxml-mode . lsp)
|
2020-08-28 03:42:28 +02:00
|
|
|
(lsp-mode . lsp-enable-which-key-integration)))
|
2020-01-27 02:11:10 +01:00
|
|
|
|
|
|
|
;; Eye-candy and flycheck support for lsp-mode.
|
|
|
|
(use-package lsp-ui
|
2020-03-09 15:14:43 +01:00
|
|
|
:after (lsp-mode flycheck whitespace)
|
|
|
|
:functions (my/whitespace-mode-on my/whitespace-mode-off)
|
|
|
|
:custom ((lsp-ui-sideline-enable nil) ; Do not insert doc into buffer.
|
|
|
|
(lsp-ui-doc-include-signature t) ; Include signature in doc popup.
|
|
|
|
(lsp-ui-doc-enable nil)) ; Disable doc popup.
|
|
|
|
:config (defun my/lsp-ws-toggle ()
|
|
|
|
"Works around the dots-in-wrong-color bug."
|
|
|
|
(if lsp-ui-peek-mode
|
|
|
|
(my/whitespace-mode-off)
|
|
|
|
(my/whitespace-mode-on)))
|
|
|
|
:bind (:map lsp-ui-mode-map
|
|
|
|
("M-." . lsp-ui-peek-find-definitions)
|
|
|
|
("C-M-." . lsp-ui-peek-find-references)
|
|
|
|
("C-M-," . lsp-ui-peek-find-implementation))
|
|
|
|
:hook ((lsp-mode . lsp-ui-mode)
|
|
|
|
(lsp-ui-peek-mode . my/lsp-ws-toggle)))
|
2020-01-27 02:11:10 +01:00
|
|
|
|
|
|
|
;; ivy interface to lsp-mode.
|
|
|
|
(use-package lsp-ivy
|
2020-05-24 22:59:31 +02:00
|
|
|
:demand t
|
2020-03-09 15:14:43 +01:00
|
|
|
:after (lsp-mode ivy))
|
2020-01-27 02:11:10 +01:00
|
|
|
|
|
|
|
;; Integration between lsp-mode and treemacs.
|
|
|
|
(use-package lsp-treemacs
|
|
|
|
:after (treemacs lsp-ui)
|
2020-03-09 15:14:43 +01:00
|
|
|
:bind (:map lsp-ui-mode-map
|
2020-11-13 14:52:03 +01:00
|
|
|
("<f7>" . lsp-treemacs-errors-list)))
|
2020-01-27 02:11:10 +01:00
|
|
|
) ; unless slow-computer.
|
|
|
|
|
|
|
|
(provide 'programming/lsp)
|
|
|
|
;;; lsp.el ends here
|