Add +lsp-defer-shutdown variable

This commit is contained in:
Henrik Lissner 2020-04-01 13:57:04 -04:00
parent 4ca30d50e2
commit b3af9dbc3c
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -16,6 +16,13 @@ excluded servers' identifiers to `+lsp-capf-blacklist'.")
"Language servers listed here will always use the `company-lsp' backend, "Language servers listed here will always use the `company-lsp' backend,
irrespective of what `+lsp-company-backend' is set to.") irrespective of what `+lsp-company-backend' is set to.")
(defvar +lsp-defer-shutdown 3
"If non-nil, defer shutdown of LSP servers for this many seconds after last
workspace buffer is closed.
This delay prevents premature server shutdown when a user still intends on
working on that project after closing the last buffer.")
;; ;;
;;; Packages ;;; Packages
@ -150,13 +157,16 @@ This gives the user a chance to open other project files before the server is
auto-killed (which is a potentially expensive process)." auto-killed (which is a potentially expensive process)."
:around #'lsp--shutdown-workspace :around #'lsp--shutdown-workspace
(if (or lsp-keep-workspace-alive (if (or lsp-keep-workspace-alive
restart) restart
(null +lsp-defer-shutdown)
(= +lsp-defer-shutdown 0))
(funcall orig-fn) (funcall orig-fn)
(when (timerp +lsp--deferred-shutdown-timer) (when (timerp +lsp--deferred-shutdown-timer)
(cancel-timer +lsp--deferred-shutdown-timer)) (cancel-timer +lsp--deferred-shutdown-timer))
(setq +lsp--deferred-shutdown-timer (setq +lsp--deferred-shutdown-timer
(run-at-time (run-at-time
3 nil (lambda (workspace) (if (numberp +lsp-defer-shutdown) +lsp-defer-shutdown 3)
nil (lambda (workspace)
(let ((lsp--cur-workspace workspace)) (let ((lsp--cur-workspace workspace))
(unless (lsp--workspace-buffers lsp--cur-workspace) (unless (lsp--workspace-buffers lsp--cur-workspace)
(funcall orig-fn)))) (funcall orig-fn))))