tools/lsp: minor refactor & doc revision

This commit is contained in:
Henrik Lissner 2020-08-22 15:31:38 -04:00
parent f83e6fe1cc
commit ffb21b18e5
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
4 changed files with 21 additions and 17 deletions

View file

@ -93,6 +93,7 @@ active, LSP is used to search a symbol indexed by the LSP server :
|-----------+-------------------------------------| |-----------+-------------------------------------|
| =SPC c j= | Jump to symbol in current workspace | | =SPC c j= | Jump to symbol in current workspace |
| =SPC c J= | Jump to symbol in any workspace | | =SPC c J= | Jump to symbol in any workspace |
** Differences between eglot and lsp-mode ** Differences between eglot and lsp-mode
Entering the debate about which one to use would be useless. Doom provides an Entering the debate about which one to use would be useless. Doom provides an
easy way to switch out lsp client implementations so you can test for yourself easy way to switch out lsp client implementations so you can test for yourself
@ -108,6 +109,7 @@ closer integration with "more basic" emacs packages (=eldoc=, =xref=, ...).
** My language server is not found ** My language server is not found
Check the entry in the [[../../../docs/faq.org][FAQ]] about "Doom can't find my executables/doesn't inherit Check the entry in the [[../../../docs/faq.org][FAQ]] about "Doom can't find my executables/doesn't inherit
the correct ~PATH~" the correct ~PATH~"
** LSP/Eglot is not started automatically in my buffer ** LSP/Eglot is not started automatically in my buffer
Make sure that you added the =+lsp= flag to the language you're using too in Make sure that you added the =+lsp= flag to the language you're using too in
your init.el : your init.el :

View file

@ -1,7 +1,7 @@
;;; flycheck-eglot --- Hacky eglot support in flycheck -*- lexical-binding: t; -*- ;;; flycheck-eglot --- Hacky eglot support in flycheck -*- lexical-binding: t; -*-
;;; Code: ;;; Code:
(defun flycheck-eglot--start (checker callback) (defun +lsp--flycheck-eglot-init (checker callback)
"Clean up errors when done. "Clean up errors when done.
CHECKER is the checker (eglot). CHECKER is the checker (eglot).
@ -31,26 +31,25 @@ CALLBACK is the function that we need to call when we are done, on all the error
;; NOTE: Forcefully trigger a check in the buffer (function name is confusing) ;; NOTE: Forcefully trigger a check in the buffer (function name is confusing)
(flycheck-buffer))) (flycheck-buffer)))
(defun flycheck-eglot--available-p () (defun +lsp--flycheck-eglot-available-p ()
(bound-and-true-p eglot--managed-mode)) (bound-and-true-p eglot--managed-mode))
(flycheck-define-generic-checker 'eglot (flycheck-define-generic-checker 'eglot
"Report `eglot' diagnostics using `flycheck'." "Report `eglot' diagnostics using `flycheck'."
:start #'flycheck-eglot--start :start #'+lsp--flycheck-eglot-init
:predicate #'flycheck-eglot--available-p :predicate #'+lsp--flycheck-eglot-available-p
:modes '(prog-mode text-mode)) :modes '(prog-mode text-mode))
(push 'eglot flycheck-checkers) (push 'eglot flycheck-checkers)
(defun +doom-eglot-prefer-flycheck-h () (add-hook! 'eglot--managed-mode-hook
(when eglot--managed-mode (defun +lsp-eglot-prefer-flycheck-h ()
(when-let ((current-checker (flycheck-get-checker-for-buffer))) (when eglot--managed-mode
(unless (equal current-checker 'eglot) (when-let ((current-checker (flycheck-get-checker-for-buffer)))
(flycheck-add-next-checker 'eglot current-checker))) (unless (equal current-checker 'eglot)
(flycheck-add-mode 'eglot major-mode) (flycheck-add-next-checker 'eglot current-checker)))
(flycheck-mode 1) (flycheck-add-mode 'eglot major-mode)
(flymake-mode -1))) (flycheck-mode 1)
(flymake-mode -1))))
(add-hook 'eglot--managed-mode-hook #'+doom-eglot-prefer-flycheck-h)
;;; flycheck-eglot.el ends here ;;; flycheck-eglot.el ends here

View file

@ -5,14 +5,15 @@
workspace buffer is closed. workspace buffer is closed.
This delay prevents premature server shutdown when a user still intends on This delay prevents premature server shutdown when a user still intends on
working on that project after closing the last buffer.") working on that project after closing the last buffer, or when programmatically
killing and opening many LSP/eglot-powered buffers.")
;; ;;
;;; Common ;;; Common
(defun +lsp-init-optimizations-h () (defun +lsp-init-optimizations-h ()
"Deploys universal optimizations for `lsp-mode' and `eglot'."
(when (or (bound-and-true-p eglot--managed-mode) (when (or (bound-and-true-p eglot--managed-mode)
(bound-and-true-p lsp-mode)) (bound-and-true-p lsp-mode))
;; `read-process-output-max' is only available on recent development ;; `read-process-output-max' is only available on recent development

View file

@ -1,3 +1,5 @@
;;; tools/lsp/doctor.el -*- lexical-binding: t; -*- ;;; tools/lsp/doctor.el -*- lexical-binding: t; -*-
(assert! (not (and (featurep! +eglot) (featurep! +peek))) "+eglot and +peek flags are not compatible. Peek uses lsp-mode, while Eglot is another package altogether for LSP.") (assert! (not (and (featurep! +eglot)
(featurep! +peek)))
"+eglot and +peek flags are not compatible. Peek uses lsp-mode, while Eglot is another package altogether for LSP.")