jscheid / prettier.el

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

Ignore stray stdout and stderr output #78

Closed jscheid closed 3 years ago

jscheid commented 3 years ago

Print a beacon string at the beginning of the response and skip to it when reading the response.

This avoids communication with the remote process getting stuck in cases where calling prettier.format emits anything to stdout/stderr, as is the case with @prettier/plugin-ruby at least up to version 1.5.2.

Also, handle remote process timeouts better.

asbish commented 3 years ago

I couldn't reproduce the case (the remote process getting stuck) so I've tested this PR inserting for (;;) {} before prettier.format. And it works.

jscheid commented 3 years ago

Thanks for taking a look. To reproduce:

  1. Checkout this branch and (cd test-cases/ruby-mode-error && npm install) (don't use yarn, as it won't pick up package-lock.json and instead install a newer version of @prettier/plugin-ruby which doesn't print to stderr anymore.)
  2. Open test-cases/ruby-mode-error/a.original.rb and M-x prettier-restart (for good measure), M-x prettier-prettify -- it should hang indefinitely using latest released prettier.el
  3. With the version from this branch it should output an error immediately.
jscheid commented 3 years ago

I'll leave this open for another couple of days in case you get a chance to take another look, but don't feel obliged. I've been dogfooding this over the course of the week and seems to work as expected.