reason-mode
reason-mode copied to clipboard
reason-mode-indent-line performance issue
Issue:
Issuing indent command, the editor will hang forever. The only option to continue is canceling the command (Ctrl-g
).
Setup
- Emacs: 25.3.1
- My emacs configuration can be found here
Profile
Here is profiling result on both CPU and Memory:
update: The image includes more expanded tree, which shows maybe the issue is caused by the constant call of syntax-ppss
function.
To reproduce this problem just trigger indentation between ||
in following lines:
[%%bs.raw {|
|}]
It looks like Emacs enters an infinite loop when it hits this lines of code here.
Thanks, I'll have a look soon. Do you wanna PR a failing test case?
About PR on a failing test, I'm a newbie on emacs-lisp and don't know how to express an assertable unit for this scenario (Infinite loop).
@shahinism there are some tests here https://github.com/reasonml-editor/reason-mode/blob/master/test/reason-test.el if you'd like to model yours after them
Well, I've already tried it. The problem is I don't know how to timeout this test. And the current test suite will just hang in the loop and block all the process.
I'm also experiencing this issue but with the jest testing syntax:
describe("functionToTest", () => {...})
As soon as I enter the curly brackets the editor (spacemacs) hangs.
I have the same issues. In the beginning I thought it is a problem with the file-naming and weird __tests__
path...
I found a funny quick fix though: As soon as you start your file with a simple declaration like let a = ""
, suddenly there are no hangups on indent anymore.
EDIT:
Or another way to prevent the freeze:
let _ = foo("hi", () => {
});
I just encountered this bug. For me, I simply change indent-line-function
to indent-relative
and let refmt-before-save
take care of indenting when I save a file.
@shahinism is absolutely right. The infinite loop is right there. The value current-level
and (reason-paren-level)
are both 0 are stay like that forever (the point is moved upward until it couldn't and then get stuck forever).
The reason @ryyppy 's workaround works is because of line https://github.com/reasonml-editor/reason-mode/blob/a9de59cced37b44db72ee248107021a660561d11/reason-indent.el#L175. In fact, any let
, type
, module
, fun
will do.
@sorawee thanks for looking into this in depth. To be honest, the reason-mode-indent-line
function is kind of a mess.
Do you see a path forward?
I don't have time to investigate further. That's why I simply switch reason-mode-indent-line
off.