2020-05-28 11:03:49 +02:00
|
|
|
;;; tools/lsp/+eglot.el -*- lexical-binding: t; -*-
|
|
|
|
|
|
|
|
(use-package! eglot
|
2020-05-28 15:30:20 -04:00
|
|
|
:commands eglot eglot-ensure
|
2020-10-11 18:13:59 -04:00
|
|
|
:hook (eglot-managed-mode . +lsp-optimization-mode)
|
2020-05-28 11:03:49 +02:00
|
|
|
:init
|
|
|
|
(setq eglot-sync-connect 1
|
|
|
|
eglot-autoshutdown t
|
2024-03-11 20:39:38 -04:00
|
|
|
;; NOTE: We disable eglot-auto-display-help-buffer because :select t in
|
|
|
|
;; its popup rule causes eglot to steal focus too often.
|
2020-05-28 11:03:49 +02:00
|
|
|
eglot-auto-display-help-buffer nil)
|
2022-08-16 20:12:45 +01:00
|
|
|
(when (and (modulep! :checkers syntax)
|
|
|
|
(not (modulep! :checkers syntax +flymake)))
|
2021-04-14 09:09:37 +02:00
|
|
|
(setq eglot-stay-out-of '(flymake)))
|
2020-05-28 15:30:20 -04:00
|
|
|
|
2020-05-28 11:03:49 +02:00
|
|
|
:config
|
2020-08-20 14:07:47 -04:00
|
|
|
(set-popup-rule! "^\\*eglot-help" :size 0.15 :quit t :select t)
|
2020-05-28 15:30:20 -04:00
|
|
|
(set-lookup-handlers! 'eglot--managed-mode
|
2021-08-06 14:50:33 +07:00
|
|
|
:definition #'xref-find-definitions
|
|
|
|
:references #'xref-find-references
|
2020-05-29 16:52:31 +09:00
|
|
|
:implementations #'eglot-find-implementation
|
|
|
|
:type-definition #'eglot-find-typeDefinition
|
2021-08-06 14:50:33 +07:00
|
|
|
:documentation #'+eglot-lookup-documentation)
|
2020-08-21 00:09:59 -04:00
|
|
|
|
2024-03-13 06:51:35 -04:00
|
|
|
;; NOTE: This setting disable the eglot-events-buffer enabling more consistent
|
|
|
|
;; performance on long running emacs instance. Default is 2000000 lines.
|
|
|
|
;; After each new event the whole buffer is pretty printed which causes
|
|
|
|
;; steady performance decrease over time. CPU is spent on pretty priting and
|
|
|
|
;; Emacs GC is put under high pressure.
|
|
|
|
(cl-callf plist-put eglot-events-buffer-config :size 0)
|
|
|
|
|
2024-03-13 01:08:56 -04:00
|
|
|
(add-to-list 'doom-debug-variables '(eglot-events-buffer-config :size 2000000 :format full))
|
2020-08-21 00:09:59 -04:00
|
|
|
|
2021-08-04 01:18:06 -04:00
|
|
|
(defadvice! +lsp--defer-server-shutdown-a (fn &optional server)
|
2020-08-20 22:00:53 -04:00
|
|
|
"Defer server shutdown for a few seconds.
|
|
|
|
This gives the user a chance to open other project files before the server is
|
2024-03-20 12:28:00 -04:00
|
|
|
auto-killed (which is a potentially expensive process). It also spares the
|
|
|
|
server an expensive restart when its buffer is reverted."
|
2020-08-20 22:00:53 -04:00
|
|
|
:around #'eglot--managed-mode
|
|
|
|
(letf! (defun eglot-shutdown (server)
|
|
|
|
(if (or (null +lsp-defer-shutdown)
|
|
|
|
(eq +lsp-defer-shutdown 0))
|
2020-10-11 18:13:59 -04:00
|
|
|
(prog1 (funcall eglot-shutdown server)
|
|
|
|
(+lsp-optimization-mode -1))
|
2020-08-20 22:00:53 -04:00
|
|
|
(run-at-time
|
|
|
|
(if (numberp +lsp-defer-shutdown) +lsp-defer-shutdown 3)
|
|
|
|
nil (lambda (server)
|
|
|
|
(unless (eglot--managed-buffers server)
|
2020-10-11 18:13:59 -04:00
|
|
|
(prog1 (funcall eglot-shutdown server)
|
|
|
|
(+lsp-optimization-mode -1))))
|
2020-08-20 22:00:53 -04:00
|
|
|
server)))
|
2021-08-04 01:18:06 -04:00
|
|
|
(funcall fn server))))
|
2021-08-22 22:28:42 +03:00
|
|
|
|
|
|
|
|
|
|
|
(use-package! consult-eglot
|
2022-08-12 20:29:19 +02:00
|
|
|
:when (modulep! :completion vertico)
|
2024-06-28 23:07:57 -04:00
|
|
|
:defer t
|
|
|
|
:init
|
|
|
|
(map! :after eglot
|
|
|
|
:map eglot-mode-map
|
|
|
|
[remap xref-find-apropos] #'consult-eglot-symbols))
|
2023-02-21 03:16:54 -05:00
|
|
|
|
|
|
|
|
|
|
|
(use-package! flycheck-eglot
|
2023-07-25 00:19:12 +01:00
|
|
|
:when (and (modulep! :checkers syntax)
|
|
|
|
(not (modulep! :checkers syntax +flymake)))
|
2023-02-21 03:16:54 -05:00
|
|
|
:hook (eglot-managed-mode . flycheck-eglot-mode))
|