Skip to content

Commit

Permalink
Project cleanup when buffers are killed
Browse files Browse the repository at this point in the history
There is a general tendency to accumulate many servers since they're
never removed (actually, more than just the servers -- the whole project
resources are kept, but the server is the main problem wrt resources).
This is also mentioned in ananthakumaran#256.

So I implemented a function that scans all buffers and cleanup all
projects that have no live buffers.  It looks to me like a good idea to
do this, since you can just kill old buffers to reduce resource
usage.  (And killing old buffers is more obvious than explicitly
openning the server list to kill old ones, especially since there's no
way to tell if a server is used by some buffer or not.)

(I added this function onto `kill-buffer-hook`, but if that's too
extreme, then a more mild option is to not do that and just let people
add it themselves.)
  • Loading branch information
elibarzilay committed Oct 30, 2019
1 parent e4c76a4 commit 584c5a0
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tide.el
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,18 @@ If TIDE-TSSERVER-EXECUTABLE is set by the user use it. Otherwise check in the n
(remhash project-name tide-tsserver-unsupported-commands)
(remhash project-name tide-project-configs))

(defun tide-cleanup-dead-projects* ()
(tide-cleanup-dead-projects (current-buffer)))
(defun tide-cleanup-dead-projects (ignore)
(let ((live-projects '()))
(dolist (b (-remove-item ignore (buffer-list)))
(-when-let (proj (with-current-buffer b
(and (bound-and-true-p tide-mode)
(tide-project-name))))
(cl-pushnew proj live-projects)))
(dolist (proj (-difference (hash-table-keys tide-servers) live-projects))
(tide-cleanup-project proj))))

(defun tide-start-server-if-required ()
(unless (tide-current-server)
(tide-start-server)))
Expand Down Expand Up @@ -1955,13 +1967,15 @@ code-analysis."
(add-hook 'after-save-hook 'tide-auto-compile-file nil t)
(add-hook 'after-change-functions 'tide-handle-change nil t)
(add-hook 'kill-buffer-hook 'tide-cleanup-buffer nil t)
(add-hook 'kill-buffer-hook 'tide-cleanup-dead-projects* nil t)
(add-hook 'hack-local-variables-hook 'tide-configure-buffer nil t)
(when (commandp 'typescript-insert-and-indent)
(eldoc-add-command 'typescript-insert-and-indent)))
(remove-hook 'after-save-hook 'tide-sync-buffer-contents t)
(remove-hook 'after-save-hook 'tide-auto-compile-file t)
(remove-hook 'after-change-functions 'tide-handle-change t)
(remove-hook 'kill-buffer-hook 'tide-cleanup-buffer t)
(remove-hook 'kill-buffer-hook 'tide-cleanup-dead-projects* t)
(remove-hook 'hack-local-variables-hook 'tide-configure-buffer t)
(tide-cleanup-buffer)))

Expand Down

0 comments on commit 584c5a0

Please sign in to comment.