jdtsmith / indent-bars

Fast, configurable indentation guide-bars for Emacs
GNU General Public License v3.0
298 stars 9 forks source link

Full hang in tsx files when editorconfig is active #48

Closed colonelpanic8 closed 1 month ago

jdtsmith commented 1 month ago

This is not nearly enough to go on. pkill -SIGUSR1 emacs and see what it's hung on. And then get a simple reproduction starting from emacs -Q.

colonelpanic8 commented 1 month ago

It seems to have to do with editorconfig--advice-find-file-noselect. if that advice is removed the issue goes away. If you edebug that function you get through almost the entire thing and the issue only occurs at the end of the function.

But like I said its a full UNRECOVERABLE hang. emacs is unresponsive to any signals except for kill

colonelpanic8 commented 1 month ago

Minimal repro: https://gist.github.com/colonelpanic8/04b228cf3a8b1ae81160e56da2c073f4

Requires setting e.g.

[*.tsx]
indent_style = tab
indent_size = 2

in .editorconfig

also must manually enable indent-bars in buffer.

Hang seems to happen in the call to font-lock-flush

jdtsmith commented 1 month ago

Minimal repro

Thanks, but it seems like this is quite specific to your system, and requires an external executable? Let's see if we can zero in on the issue in other ways.

It seems to have to do with editorconfig--advice-find-file-noselect

I see. I don't understand why find-file is involved: Is this hanging directly upon opening a file?

Hang seems to happen in the call to font-lock-flush

Do you have a traceback of some kind? Font-lock is pretty aggressive in catching errors. If it's caught in an endless loop somehow, sending SIGUSR2 (and maybe a few C-g's) should produce a traceback (if that's what debug-on-event is set to, not SIGUSR1).

Also if it's a font-lock problem, jit-lock (which drives font-lock) logs errors to *Messages*; keep that open when you reproduce and see if anything is reported there prior to the hang.

Since your config mentions indent_size, what is the value of indent-bars-spacing right before the hang? WAG but maybe editorconfig is setting the indent to something crazy leading to endless font-locking. You could find this out by M-x trace-function indent-bars--guess-spacing, and open the trace output buffer before the hang to see if it gets reported.

Or just insert a (message "spacing=%d" indent-bars-spacing) after the ;;Spacing section in indent-bars-setup and eval that. And/or remove the indent setup from the config file (replace with something innocuous) and see if that fixes it.

Also, what are js-indent-level and indent-tabs-mode before the hang? The former is what indent-bars looks for in JS files (though maybe it needs something more specific, modes are always changing their indent level names).

Let me know what you uncover.

colonelpanic8 commented 1 month ago

Thanks, but it seems like this is quite specific to your system, and requires an external executable?

no external executable required. Where did i give that impression?

I see. I don't understand why find-file is involved: Is this hanging directly upon opening a file?

I think that this is how editorconfig sets certain properties for the file.

The issue actually happens in the indent-bars code, but only when editorconfig runs its setup.

Do you have a traceback of some kind? Font-lock is pretty aggressive in catching errors. If it's caught in an endless loop somehow, sending SIGUSR2 (and maybe a few C-g's) should produce a traceback (if that's what debug-on-event is set to, not SIGUSR1).

Tried this, like I said, unrecoverable hang. Emacs seems dead. I tried doing an strace but it wasn't useful.

jdtsmith commented 1 month ago

Thanks, but it seems like this is quite specific to your system, and requires an external executable?

no external executable required. Where did i give that impression?

I got that impression from e.g. editorconfig-exec-path.

I see. I don't understand why find-file is involved: Is this hanging directly upon opening a file?

I think that this is how editorconfig sets certain properties for the file.

The issue actually happens in the indent-bars code, but only when editorconfig runs its setup.

I see, so all that matters is that editorconfig has done something to the local variables. The job is to figure out what that something is.

Do you have a traceback of some kind? Font-lock is pretty aggressive in catching errors. If it's caught in an endless loop somehow, sending SIGUSR2 (and maybe a few C-g's) should produce a traceback (if that's what debug-on-event is set to, not SIGUSR1).

Tried this, like I said, unrecoverable hang. Emacs seems dead. I tried doing an strace but it wasn't useful.

Try all the other various tests and gather the information I requested.

jdtsmith commented 1 month ago

Unfortunately, I can't make your reproducer work. Please trim it down to the minimum setup, removing straight, etc. (assume I can load editorconfig and indent-bars). E.g. along the lines of:

(package-initialize)
(use-package editorconfig
  :config
  (progn
    (add-to-list 'editorconfig-exclude-modes '(org-mode))
    (editorconfig-mode 1)))

(use-package indent-bars
  :hook (some-js-mode . indent-bars))

And then after loading this, what steps are needed? E.g. is there a particular file to open? What mode will it be in? Presumably some JS-flavored mode, which isn't mentioned in the current config.

BTW, I also notice you do:

  :config
  (indent-bars-mode +1)

which isn't right as it will start indent-bars in some random buffer.

jdtsmith commented 1 month ago

Closing due to lack of response. Can re-open if needed.