diff --git a/modules/tools/lsp/+eglot.el b/modules/tools/lsp/+eglot.el index 9bb4eb92a..8e9ccb329 100644 --- a/modules/tools/lsp/+eglot.el +++ b/modules/tools/lsp/+eglot.el @@ -5,6 +5,7 @@ (use-package! eglot :commands eglot eglot-ensure + :hook (eglot-managed-mode . +lsp-init-optimizations-h) :init (setq eglot-sync-connect 1 eglot-connect-timeout 10 diff --git a/modules/tools/lsp/+lsp.el b/modules/tools/lsp/+lsp.el index e89c44122..014d19463 100644 --- a/modules/tools/lsp/+lsp.el +++ b/modules/tools/lsp/+lsp.el @@ -104,25 +104,14 @@ should be a deliberate act (as is flipping this variable).") (apply orig-fn args))) (add-hook! 'lsp-mode-hook - (defun +lsp-init-optimizations-h () - "Increase `read-process-output-max' and `gcmh-high-cons-threshold'." - ;; `read-process-output-max' is only available on recent development - ;; builds of Emacs 27 and above. - (unless (boundp 'read-process-output-max) - (setq-local read-process-output-max (* 1024 1024))) - ;; REVIEW LSP causes a lot of allocations, with or without Emacs 27+'s - ;; native JSON library, so we up the GC threshold to stave off - ;; GC-induced slowdowns/freezes. Doom uses `gcmh' to enforce its GC - ;; strategy, so we modify its variables rather than - ;; `gc-cons-threshold' directly. - (setq-local gcmh-high-cons-threshold (* 2 (default-value 'gcmh-high-cons-threshold)))) (defun +lsp-display-guessed-project-root-h () "Log what LSP things is the root of the current project." ;; Makes it easier to detect root resolution issues. (when-let (path (buffer-file-name (buffer-base-buffer))) (if-let (root (lsp--calculate-root (lsp-session) path)) (lsp--info "Guessed project root is %s" (abbreviate-file-name root)) - (lsp--info "Could not guess project root."))))) + (lsp--info "Could not guess project root.")))) + #'+lsp-init-optimizations-h) (add-hook! 'lsp-completion-mode-hook (defun +lsp-init-company-backends-h () diff --git a/modules/tools/lsp/config.el b/modules/tools/lsp/config.el index 3d26aa100..d2d472cbf 100644 --- a/modules/tools/lsp/config.el +++ b/modules/tools/lsp/config.el @@ -8,6 +8,24 @@ This delay prevents premature server shutdown when a user still intends on working on that project after closing the last buffer.") + +;; +;;; Common + +(defun +lsp-init-optimizations-h () + (when (or (bound-and-true-p eglot--managed-mode) + (bound-and-true-p lsp-mode)) + ;; `read-process-output-max' is only available on recent development + ;; builds of Emacs 27 and above. + (setq-local read-process-output-max (* 1024 1024)) + ;; REVIEW LSP causes a lot of allocations, with or without Emacs 27+'s + ;; native JSON library, so we up the GC threshold to stave off + ;; GC-induced slowdowns/freezes. Doom uses `gcmh' to enforce its GC + ;; strategy, so we modify its variables rather than + ;; `gc-cons-threshold' directly. + (setq-local gcmh-high-cons-threshold (* 2 (default-value 'gcmh-high-cons-threshold))))) + + ;; ;;; Implementations