jscheid / prettier.el

Prettier code formatting for Emacs.
GNU General Public License v3.0
164 stars 11 forks source link

Restart Prettier on load #73

Closed jscheid closed 3 years ago

jscheid commented 3 years ago

This is intended to ensure that the version of the JavaScript code running in the child process matches that of the Elisp code.

Also, introduce a new interactive function called prettier-restart that can be used to explicitly restart the system so that configuration changes get picked up.

asbish commented 3 years ago

Sounds good! However, I think that a new prettier process invoked by prettier-restart exits immediately.

prettier-process (local) quit unexpectedly: hangup

It seems that a new process was killed by kill-buffer in sentinels of processes that received SIGQUIT signal. I propose to remove current process sentinels before calling quit-process like this below.

(defun prettier--quit-all-processes (&optional restart)
  "Quit all Prettier sub-processes."
  (maphash (lambda (_key process)
             (when restart (set-process-sentinel process nil))
             (quit-process process))
           prettier-processes)
  (clrhash prettier-processes)
  (setq prettier-nvm-node-command-cache nil))

(defun prettier-restart ()
  (interactive)
  (prettier--quit-all-processes t)
  ;; ...
)

But I also think the change seems to be a little messy, so I was wondering about changing the sentinel code. What do you think?

jscheid commented 3 years ago

Hi @asbish, thanks for testing! I can't seem to reproduce this in a simple case:

I've also tried a few other things (ensure prettier-prettify runs before/after restarting) but no luck.

Which Emacs version are you using and do you have a way to reproduce this reliably?

asbish commented 3 years ago

Thank you for your response.

I've tried your procedure on freshly installed Fedora 33 (not VM) and Emacs 27.1 (rpm). Even in this case, I got the same message, prettier-process (local) quit unexpectedly: hangup and besides list-processes shows nothing after running prettier-restart.

init.el and prettier-info.el(before prettier-restart) are here.

jscheid commented 3 years ago

Thanks @asbish , it was working fine on MacOS but I can reproduce on Linux. Good catch! Can you try again now?

(CI is red but that will hopefuly be fixed soon by rejeep/nvm.el#20)

jscheid commented 3 years ago

Thanks for re-testing.