AdamNiederer / ng2-mode

Angular Support for Emacs
GNU General Public License v3.0
73 stars 11 forks source link

Angle bracket (>) seems to cause 100% cpu. #21

Closed jmb1026 closed 3 years ago

jmb1026 commented 4 years ago

Problem

While following along with this tutorial ng2-ts mode seems to cause emacs to block and use 100% of the CPU. The code in question is from the "Error handling" section, specifically:

private handleError<T> (operation = 'operation', result?: T) {
  return (error: any): Observable<T> => {  // Typing the second > on this line causes the issue.
     // ...
  };
}

Environment

Emacs configuration

 ;; Angular/Typescript
 (use-package typescript-mode
    :ensure t)

 (use-package ng2-mode
    :ensure t
    :after typescript-mode)

Steps to reproduce

  1. ng new repro Accept defaults.
  2. cd repro
  3. Launch emacs and open repro/src/app/app.module.ts
  4. In the AppModule class, add the following block
getRepro() {
  return (): <T> => {
  }
}
  1. Typing the second gt bracket (>) will reproduce the issue.

Misc.

LlinksRechts commented 3 years ago

Any updates on this? What I have found out:

LlinksRechts commented 3 years ago

For anyone else running into this issue: I fixed it using

--- a/ng2-ts.el
+++ b/ng2-ts.el
@@ -198,6 +198,7 @@
                            (min bound (ng2-ts--end-of-lambda-args (point))) 1))
       (and (ignore-errors
              ;; Skip forward if we wind up in the space between the args and the =>
+             (save-match-data (while (looking-at ">") (forward-char)))
              (ng2-ts--skip-whitespace)
              (forward-char 2)
              (prog1 (save-match-data (search-forward "=>" bound 1))

However that is relatively hacky and I really don't know elisp, so I'm not submitting a PR :p

AdamNiederer commented 3 years ago

Oh, hey!

Honestly syntax highlighting in emacs is a massive hack anyway. If this fixes it, shoot me an PR and I'll put it in. Rather some edge case not get highlighted than have your editor hang.