2020-01-27 02:11:10 +01:00
|
|
|
;;; lsp.el --- Language Server Protocol. -*- lexical-binding: t; -*-
|
|
|
|
|
|
|
|
;;; 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)
|
2021-01-20 07:31:31 +01:00
|
|
|
(require 'text/common)
|
2020-01-27 02:11:10 +01:00
|
|
|
|
2020-12-08 13:17:06 +01:00
|
|
|
;; Client for Language Server Protocol servers.
|
|
|
|
(use-package lsp-mode
|
|
|
|
: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.
|
2021-03-23 16:22:47 +01:00
|
|
|
(lsp-eldoc-render-all nil)
|
2020-12-08 13:17:06 +01:00
|
|
|
(lsp-restart 'auto-restart)
|
|
|
|
(lsp-enable-semantic-highlighting t) ; Needs clangd 11(?).
|
|
|
|
(lsp-semantic-tokens-apply-modifiers t)
|
|
|
|
(lsp-keymap-prefix "C-c l")
|
2021-01-08 03:08:10 +01:00
|
|
|
(lsp-keep-workspace-alive nil)
|
|
|
|
(lsp-headerline-breadcrumb-segments
|
2021-03-24 22:41:29 +01:00
|
|
|
'(path-up-to-project file symbols))
|
|
|
|
(lsp-bash-highlight-parsing-errors t))
|
2020-12-08 13:17:06 +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))))
|
|
|
|
(lsp-face-semhl-member ((t (:inherit default :weight semibold))))
|
2021-01-20 07:35:13 +01:00
|
|
|
;; (lsp-face-semhl-enum ((t (:inherit font-lock-type-face))))
|
2020-12-08 13:17:06 +01:00
|
|
|
:config (progn
|
|
|
|
(setq lsp-clients-clangd-args '("--compile-commands-dir=build"))
|
|
|
|
(when (>= (my/clangd-version) 9.0)
|
|
|
|
(add-to-list 'lsp-clients-clangd-args "--clang-tidy" t))
|
2021-04-16 03:58:41 +02:00
|
|
|
;; Ranking algorithm trained on snippets from a large C++ codebase.
|
|
|
|
(when (>= (my/clangd-version) 12.0)
|
|
|
|
(add-to-list 'lsp-clients-clangd-args
|
|
|
|
"--ranking-model=decision_forest" t))
|
|
|
|
;; Always enabled in >= 12.0
|
|
|
|
(when (< (my/clangd-version) 12.0)
|
|
|
|
(add-to-list 'lsp-clients-clangd-args "--recovery-ast" t)
|
|
|
|
(add-to-list 'lsp-clients-clangd-args "--background-index" t))
|
2020-12-08 13:17:06 +01:00
|
|
|
;; Mark lsp-clients-clangd-args as safe to override.
|
2021-02-08 23:07:16 +01:00
|
|
|
(put 'lsp-clients-clangd-args 'safe-local-variable #'consp)
|
|
|
|
|
|
|
|
(defun my/rebind-other-file-maybe ()
|
|
|
|
"Rebind C-: to LSP equivalent."
|
|
|
|
(when (equal major-mode 'c++-mode)
|
|
|
|
(bind-key "C-:" #'lsp-clangd-find-other-file 'c++-mode-map))))
|
2020-12-08 13:17:06 +01:00
|
|
|
:bind ("C-c C-f" . lsp-execute-code-action)
|
|
|
|
:hook ((c++-mode . lsp)
|
|
|
|
(c-mode . lsp)
|
|
|
|
(python-mode . lsp)
|
|
|
|
(nxml-mode . lsp)
|
2021-01-08 03:08:50 +01:00
|
|
|
(json-mode . lsp)
|
2021-02-08 16:29:08 +01:00
|
|
|
(web-mode . lsp)
|
|
|
|
(css-mode . lsp)
|
2021-03-14 10:56:47 +01:00
|
|
|
(js-mode . lsp)
|
2021-02-08 23:07:16 +01:00
|
|
|
(lsp-mode . lsp-enable-which-key-integration)
|
|
|
|
(lsp-mode . my/rebind-other-file-maybe)))
|
2020-01-27 02:11:10 +01:00
|
|
|
|
2020-12-08 13:17:06 +01:00
|
|
|
;; Eye-candy and flycheck support for lsp-mode.
|
|
|
|
(use-package lsp-ui
|
|
|
|
:after (lsp-mode flycheck whitespace)
|
|
|
|
:functions (my/whitespace-mode-on my/whitespace-mode-off)
|
2021-05-27 10:44:00 +02:00
|
|
|
:custom ((lsp-ui-sideline-enable t) ; Documentation in buffer.
|
2021-04-25 10:06:37 +02:00
|
|
|
(lsp-ui-doc-include-signature nil)
|
2021-03-23 16:22:47 +01:00
|
|
|
(lsp-ui-doc-max-width 100)
|
|
|
|
(lsp-ui-doc-max-height 20)
|
2021-05-25 07:55:01 +02:00
|
|
|
(lsp-ui-doc-enable t) ; Documentation popup.
|
2021-05-27 10:44:00 +02:00
|
|
|
(lsp-ui-doc-show-with-mouse nil)
|
|
|
|
(lsp-ui-sideline-show-diagnostics nil))
|
2020-12-08 13:17:06 +01:00
|
|
|
: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)
|
2021-05-27 10:50:14 +02:00
|
|
|
("C-M-," . lsp-ui-peek-find-implementation)
|
|
|
|
("M-i" . lsp-ui-imenu))
|
2020-12-08 13:17:06 +01:00
|
|
|
:hook ((lsp-mode . lsp-ui-mode)
|
|
|
|
(lsp-ui-peek-mode . my/lsp-ws-toggle)))
|
2020-01-27 02:11:10 +01:00
|
|
|
|
2020-12-08 13:17:06 +01:00
|
|
|
;; ivy interface to lsp-mode.
|
|
|
|
(use-package lsp-ivy
|
|
|
|
:demand t
|
|
|
|
:after (lsp-mode ivy))
|
2020-01-27 02:11:10 +01:00
|
|
|
|
2020-12-08 13:17:06 +01:00
|
|
|
;; 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)))
|
2020-01-27 02:11:10 +01:00
|
|
|
|
|
|
|
(provide 'programming/lsp)
|
|
|
|
;;; lsp.el ends here
|