Emacs: Refactor lsp.el.

This commit is contained in:
tastytea 2020-03-09 15:14:43 +01:00
parent 54c1b466cf
commit 65671f96a7
1 changed files with 35 additions and 56 deletions

View File

@ -1,6 +1,6 @@
;;; lsp.el --- Language Server Protocol. -*- lexical-binding: t; -*-
;; Time-stamp: <2020-03-09T15:04:37+0100>
;; Time-stamp: <2020-03-09T15:14:33+0100>
;;; Commentary:
@ -12,78 +12,57 @@
;; Client for Language Server Protocol servers.
(use-package lsp-mode
:if (executable-find "clangd")
:after (whitespace)
:defines (lsp-clients-clangd-args)
:diminish lsp-mode
:custom
(lsp-prefer-flymake nil) ; Disable flymake.
(lsp-auto-guess-root t) ; Don't ask for project root.
(lsp-eldoc-render-all t) ; Display all eldoc information.
(lsp-restart 'auto-restart) ; Automatically restart server.
:config
(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)
(defun my/lsp-ws-toggle ()
(if lsp-ui-peek-mode
(my/whitespace-mode-off)
(my/whitespace-mode-on)))
:hook
(c++-mode . lsp)
(c-mode . lsp)
(lsp-ui-peek-mode . my/lsp-ws-toggle) ; Dots in wrong color.
)
:custom ((lsp-prefer-flymake nil) ; Disable flymake.
(lsp-auto-guess-root t) ; Don't ask for project root.
(lsp-eldoc-render-all t) ; Display all eldoc information.
(lsp-restart 'auto-restart)) ; Automatically restart server.
: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))
:hook ((c++-mode . lsp)
(c-mode . lsp)))
;; Eye-candy and flycheck support for lsp-mode.
(use-package lsp-ui
:after (lsp-mode flycheck)
: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.
: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)
)
: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)))
;; Completions with lsp-mode.
(use-package company-lsp
:after (lsp-mode company)
:custom (company-lsp-cache-candidates 'auto)
:config (push 'company-lsp company-backends)
)
:config (push 'company-lsp company-backends))
;; ivy interface to lsp-mode.
(use-package lsp-ivy
:after (lsp-mode ivy)
)
:after (lsp-mode ivy))
;; Integration between lsp-mode and treemacs.
(use-package lsp-treemacs
:after (treemacs lsp-ui)
:bind
(:map lsp-ui-mode-map
("<f7>" . lsp-treemacs-errors-list) ; Use treemacs for error list.
("M-i" . lsp-treemacs-symbols) ; Display symbols using treemacs.
)
)
:bind (:map lsp-ui-mode-map
("<f7>" . lsp-treemacs-errors-list)
("M-i" . lsp-treemacs-symbols)))
) ; unless slow-computer.
(provide 'programming/lsp)