jscheid / prettier.el

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

Emacs hangs when opening remote markdown file #84

Closed swarnendubiswas closed 2 years ago

swarnendubiswas commented 3 years ago

Describe the bug Emacs hangs when trying to open and edit a remote markdown file.

Link to M-x prettier-info output

M-x prettier-info hangs.

To Reproduce

Here is my MWE.

(package-initialize)
(unless (package-installed-p 'use-package)
  (package-refresh-contents)
  (package-install 'use-package))

(eval-when-compile
  (require 'use-package))

(use-package tramp
  :custom
  (tramp-completion-reread-directory-timeout nil)
  (tramp-default-method "ssh" "SSH is faster than the default SCP")
  (tramp-default-remote-shell "/bin/bash")
  (tramp-default-user "swarnendu")
  (remote-file-name-inhibit-cache nil "Remote files are not updated outside of Tramp")
  (tramp-verbose 1)
  ;; Disable version control
  (vc-ignore-dir-regexp (format "\\(%s\\)\\|\\(%s\\)" vc-ignore-dir-regexp
                                tramp-file-name-regexp))
  :config
  (defalias 'exit-tramp 'tramp-cleanup-all-buffers)
  (setenv "SHELL" "/bin/bash") ; Recommended to connect with bash
  ;; Disable backup
  (add-to-list 'backup-directory-alist (cons tramp-file-name-regexp nil))
  ;; Include this directory in $PATH on remote
  (add-to-list 'tramp-remote-path (expand-file-name ".local/bin" (getenv "HOME")))
  (add-to-list 'tramp-remote-path 'tramp-own-remote-path))

(use-package markdown-mode
  :mode
  ;; The order is important to associate "README.md" with `gfm-mode'
  (("\\.md\\'" . markdown-mode)
   ("\\.markdown\\'" . markdown-mode)
   ("README\\.md\\'" . gfm-mode))
  ;; :init
  ;; Looks good, but hiding markup makes it difficult to be consistent while editing
  ;; (setq-default markdown-hide-markup t)
  :custom
  (markdown-command
   "pandoc -f markdown -s --mathjax --standalone --quiet --highlight-style=pygments")
  (markdown-enable-math t "Syntax highlight for LaTeX fragments")
  (markdown-enable-wiki-links t)
  ;; https://emacs.stackexchange.com/questions/13189/github-flavored-markdown-mode-syntax-highlight-code-blocks/33497
  (markdown-fontify-code-blocks-natively t)
  (markdown-indent-on-enter 'indent-and-new-item)
  ;; (markdown-make-gfm-checkboxes-buttons nil)
  (markdown-list-indent-width 2)
  (markdown-split-window-direction 'horizontal))

(use-package prettier
  :if (executable-find "prettier")
  :hook ((markdown-mode ; gfm-mode
          web-mode ; should include `css-mode' and `html-mode'
          json-mode
          jsonc-mode
          js2-mode) . prettier-mode)
  :custom (prettier-lighter nil))

Expected behavior

I expect the editing flow to be normal and prettier to return.

Additional context

Remote machine

swarnendu@cseproj227:~$ node --version
v15.5.1
swarnendu@cseproj227:~$ prettier --version
2.1.2
swarnendu@cseproj227:~$ which prettier
/usr/bin/prettier
swarnendu@cseproj227:~$ 

Local machine

~ $ node --version
v14.16.0
~ $ prettier --version
2.2.1
~ $ which prettier
/home/swarnendu/tmp/node_modules/.bin/prettier
~ $ 
jscheid commented 3 years ago

I've tested here to make sure remote formatting of markdown files works in principle, and it does. So we'll need to debug this at your end.

After it hangs and you abort with C-g there should be a buffer called *prettier cseproj227* (assuming cseproj227 is the host you're connecting to.) Can you send the contents over or let me know in case it's empty?

Does it hang with all remote files (that you use Prettier with), all remote Markdown files, or just a specific Markdown file? If it's just a specific file, could you share it with me?

If you log into the remote host and run prettier from the command line on the file in question, is there any interesting output?

Which Emacs version are you using and which version of this package?

swarnendubiswas commented 3 years ago

Here is the output after aborting with C-g.

swarnendu@cseproj227:~$ tramp_exit_status 0
swarnendu@cseproj227:~$ 

I tried with .json on the same machine, Emacs hangs with the same output in the prettier buffer. Prettier from the CLI on the remote machine works fine, it returns instantly.

My Emacs version is 27.1, Ubuntu 20.04, and prettier package is the latest from melpa 20210313.1047.

It may have something to do with my setup. Any pointers to resolve the issue would be useful.

jscheid commented 3 years ago

For a start you could set tramp-verbose to something high, maybe 6, and put the resulting trace in a Gist. It might tell us what's going on.

You could also double-check that the remote path configuration is correct, see here. It's possible that it's not picking up the right node executable?

jscheid commented 3 years ago

It does look like something with your setup but I'm flagging this as a bug because we should handle this case better. At the very least it shouldn't hang, instead it should surface the remote output.

Could you check if the remote process is still active when it hangs? (Is it still listed in M-x list-process output?)

swarnendubiswas commented 3 years ago

Gist

I had to use a different remote machine but the behavior is the same.

jscheid commented 3 years ago

The logs contain mention of a timeout. There's a variable prettier-timeout-seconds that defaults to 20s. It wouldn't take that long to connect and start Prettier remotely, would it?

swarnendubiswas commented 3 years ago

No, I do not think so unless there is something wrong in my node setup. The following log from the second remote machine seems reasonable.

swarnendu:~$ prettier --version
2.2.1
swarnendu:~$ node --version
v14.16.0
swarnendu:~$ which node
/usr/bin/node
swarnendu:~$ echo $PATH
/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:/home/swarnendu/.local/bin:/home/swarnendu/anaconda3/condabin:/home/swarnendu/tmp/node_modules/.bin:/home/swarnendu/tmp/textlint-workspace/node_modules/.bin:/opt/bin:/home/swarnendu/prospar-workspace/data-race-framework:/home/swarnendu/prospar-workspace/spmv-framework:::/home/swarnendu/.luarocks/bin:/home/swarnendu/.cargo/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
swarnendu:~$ 
swarnendubiswas commented 3 years ago

I use the Prettier VSCode extension for editing the same files on the same remote machines, and they work fine.

jscheid commented 2 years ago

Hi @swarnendubiswas , I made a Docker environment to test running Prettier via TRAMP: https://github.com/jscheid/prettier.el/tree/master/docker-envs/issue-84

You could try changing this test case to match your environment. Hopefully this lets you recreate the issue.

Without being able to recreate it, there's not much I can do at this point so I'm going to close this. Feel free to reopen if you succeed.