brotzeit / rustic

Rust development environment for Emacs
Apache License 2.0
729 stars 102 forks source link

hang on save #233

Closed tanj closed 2 years ago

tanj commented 3 years ago

Running emacs GNU Emacs 27.1 (build 1, x86_64-w64-mingw32) with the following

Steps to reproduce

  1. Run emacs as follows

    $ git clone https://github.com/rksm/emacs-rust-config
    $ # edit ./emacs-rust-config/init.el to remove loading of exec-path-from-shell because that doesn't work on Windows
    $ emacs -q --load ./emacs-rust-config/standalone.el
  2. Edit a rust file and make a change

  3. Save file

What happens

Emacs hangs until I press C-g then after a slight pause the file reloads with the reformatted file.

What I expect to happen

File saves and reloads with formatted file without hanging

Installed packages

  company            20210224.2244 installed             Modular text completion framework
  exec-path-from-shell 20201215.33   installed             Get environment variables such as $PATH from the shell
  flycheck           20210314.2015 installed             On-the-fly syntax checking
  lsp-ui             20210317.1358 installed             UI modules for lsp-mode
  rustic             20210315.1728 installed             Rust development environment
  selectrum          20210316.835  installed             Easily select item from list
  toml-mode          20161107.1800 installed             Major mode for editing TOML files
  use-package        20210207.1926 installed             A configuration macro for simplifying your .emacs
  which-key          20210131.1837 installed             Display available keybindings in popup
  yasnippet          20200604.246  installed             Yet another snippet extension for Emacs
  bind-key           20210210.1609 dependency            A simple way to manage personal keybindings
  dash               20210308.2109 dependency            A modern list library for Emacs
  epl                20180205.2049 dependency            Emacs Package Library
  f                  20191110.1357 dependency            Modern API for working with files and directories
  ht                 20210119.741  dependency            The missing hash table library for Emacs
  lsp-mode           20210317.1031 dependency            LSP mode
  lv                 20200507.1518 dependency            Other echo area
  markdown-mode      20210220.1301 dependency            Major mode for Markdown-formatted text
  pkg-info           20150517.1143 dependency            Information about packages
  s                  20180406.808  dependency            The long lost Emacs string manipulation library.
  spinner            1.7.3         dependency            Add spinners and progress-bars to the mode-line for ongoing operations
  xterm-color        20200605.2017 dependency            ANSI, XTERM 256 and Truecolor support
brotzeit commented 3 years ago

Thanks for the bug report. Can you please test it without lsp-mode activated, so we can exclude lsp as source for the issue.

tanj commented 3 years ago

Setting rustic-lsp-client to nil clears the issue. What is the next step? report to lsp?

brotzeit commented 3 years ago

Does this also happen when you trigger rustic-format-file manually ?

tanj commented 3 years ago

with lsp-mode active it also happens when triggering rustic-format-file manually

if I turn off lsp-mode in the buffer (not removed from config) it also happens with manual rustic-format-file

brotzeit commented 3 years ago

Ok now it gets odd. @yyoncho I'm not up-to-date with recent lsp-mode changes, any idea which changes could be the reason for this ?

yyoncho commented 3 years ago

What happens after M-x toggle-debug-on-quit + C-g when hangs?

tanj commented 3 years ago

Steps

  1. M-x lsp-mode (to disable)
  2. M-x toggle-debug-on-quit
  3. M-x rustic-format-file
  4. C-g
Debugger entered--Lisp error: (quit)
  sit-for(0.05)
  rustic-format-file(nil)
  funcall-interactively(rustic-format-file nil)
  call-interactively(rustic-format-file record nil)
  command-execute(rustic-format-file record)
  execute-extended-command(nil "rustic-format-file" "rustic-for")
  funcall-interactively(execute-extended-command nil "rustic-format-file" "rustic-for")
  call-interactively(execute-extended-command nil nil)
  command-execute(execute-extended-command)
yyoncho commented 3 years ago

I don't see anything related to lsp-mode in this call-stack.... Also in order to disable lsp-mode use lsp-disconnect.

brotzeit commented 3 years ago

Maybe an on change hook or something similar ?

tanj commented 3 years ago

Using lsp-disconnect and running rustic-format-file

Debugger entered--Lisp error: (quit)
  rustic-format-file(nil)
  funcall-interactively(rustic-format-file nil)
  call-interactively(rustic-format-file record nil)
  command-execute(rustic-format-file record)
  execute-extended-command(nil "rustic-format-file" "rustic-for")
  funcall-interactively(execute-extended-command nil "rustic-format-file" "rustic-for")
  call-interactively(execute-extended-command nil nil)
  command-execute(execute-extended-command)
brotzeit commented 3 years ago

Does rustic-format-buffer work ?

brotzeit commented 3 years ago

Please remember to only require rustic.

tanj commented 3 years ago
  1. M-x lsp-disconnect
  2. Make changes to rust file format
  3. M-x rustic-format-buffer
  4. buffer reformatted no hang
brotzeit commented 2 years ago

I really doubt this is realated to rustic or lsp-mode. It's worth trying if something detached the buffer from the file

(defun my-print-buffer-file ()
  (interactive)
  (print (buffer-file-name)))

However I (hopefully) fixed the buffer position issue when using rustic-format-buffer finally, so there's still an alternative that can be used.

If anybody is still experiencing this problem, please open a new issue.

brotzeit commented 2 years ago

On the other hand, maybe some function writes to the file so rustic-format-file can't do...