From 24a6e3822cf9c178d980405f06bd411b358fc957 Mon Sep 17 00:00:00 2001 From: Laurence Warne Date: Sun, 26 Feb 2023 16:09:46 +0000 Subject: [PATCH] Add custom desktop minor mode handler for lsp-deferred Use lsp-deferred instead of lsp-mode even in the case that lsp-mode appears in the list of minor modes for a file in a user's desktop file by adding the buffer-local variable lsp--buffer-deferred (which tracks whether a given buffer was started using lsp-deferred) to the variable desktop-locals-to-save so that it is persisted in a user's desktop file, and adding a custom handler to desktop-minor-mode-handlers which uses this persisted variable to determine whether to use lsp-deferred of lsp-mode when re-opening a file from the desktop file. --- lsp-mode.el | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lsp-mode.el b/lsp-mode.el index 3b27a86b413..9b48caaea61 100644 --- a/lsp-mode.el +++ b/lsp-mode.el @@ -31,6 +31,7 @@ (require 'cl-lib) (require 'compile) (require 'dash) +(require 'desktop) (require 'epg) (require 'ewoc) (require 'f) @@ -9124,6 +9125,13 @@ This avoids overloading the server with many files when starting Emacs." (unless (lsp--init-if-visible) (add-hook 'window-configuration-change-hook #'lsp--init-if-visible nil t)))))))) +(add-to-list 'desktop-locals-to-save 'lsp--buffer-deferred) +(add-to-list 'desktop-minor-mode-handlers + '(lsp-mode . (lambda (desktop-buffer-locals) + (if (alist-get 'lsp--buffer-deferred desktop-buffer-locals) + (lsp-deferred) + (lsp-mode))))) + (defvar lsp-file-truename-cache (ht))