abicky / nodejs-repl.el

Run Node.js REPL and communicate with the process
190 stars 38 forks source link

Token completion appears to be broken in emacs 26.2 #24

Closed shofetim closed 5 years ago

shofetim commented 5 years ago

After updating to the latest nodejs-repl and emacs 26.2 tab completion in repl buffers hangs emacs.

Steps to reproduce are pretty straight forward. Install emacs 26.2 Install latest nodejs-repl M-x nodejs-repl Type process. and hit tab, emacs freezes. ctr-g to unfreeze

Thanks!

shofetim commented 5 years ago

I tried to track it down, but I don't know elisp well. It isn't the version of emacs, or nodejs-repl.el that causes the problem, but some change in how the latest Node works. (ie the problem is not present with latest Emacs and nodejs-repl and Node v10.x

Emacs get's stuck in the while loop in nodejs-repl--wait-for-process, here is a debug output:

Debugger entered--Lisp error: (quit)
  accept-process-output(#<process nodejs> 0.01)
  nodejs-repl--wait-for-process(#<process nodejs> "process\011" 0.01)
  nodejs-repl--send-string("process\011")
  nodejs-repl--get-completions-from-process("process")
  nodejs-repl--get-completions("process")
  #f(compiled-function (string pred action) #<bytecode 0x43b96531>)("process" nil t)
  all-completions("process" #f(compiled-function (string pred action) #<bytecode 0x43b96531>) nil)
  completion-pcm--all-completions("" ("process" point) #f(compiled-function (string pred action) #<bytecode 0x43b96531>) nil)
  completion-basic-all-completions("process" #f(compiled-function (string pred action) #<bytecode 0x43b96531>) nil 7)
  #f(compiled-function (style) #<bytecode 0x43b96559>)(basic)
  completion--some(#f(compiled-function (style) #<bytecode 0x43b96559>) (basic partial-completion emacs22))
  completion--nth-completion(2 "process" #f(compiled-function (string pred action) #<bytecode 0x43b96531>) nil 7 nil)
  completion-all-completions("process" #f(compiled-function (string pred action) #<bytecode 0x43b96531>) nil 7)
  company-capf(candidates "process")
  apply(company-capf (candidates "process"))
  company-call-backend-raw(candidates "process")
  company--fetch-candidates("process")
  company-calculate-candidates("process" nil)
  company--begin-new()
  company--perform()
  company-auto-begin()
  company-idle-begin(#<buffer *nodejs*> #<window 523 on *nodejs*> 11 10)
  apply(company-idle-begin (#<buffer *nodejs*> #<window 523 on *nodejs*> 11 10))
  timer-event-handler([t 23782 55234 584354 nil company-idle-begin (#<buffer *nodejs*> #<window 523 on *nodejs*> 11 10) nil 999999])

Adding some print statements to:

(defun nodejs-repl--wait-for-process (proc string interval)
  "Wait for Node.js process to output all results."
  (process-put proc 'last-line "")
  (process-put proc 'running-p t)
  ;; trim trailing whitespaces
  (setq string (replace-regexp-in-string "[ \t\r\n]*\\'" "" string))
  ;; TODO: write unit test for the case that the process returns 'foo' when string is 'foo\t'
  (while (or (process-get proc 'running-p)
             (not
              (let ((last-line (process-get proc 'last-line)))
                (message "but _never_ here")
                (or (string-match-p nodejs-repl-prompt-re last-line)
                    (string= last-line string)))))
     (message "here")
    (process-put proc 'running-p nil)
    (accept-process-output proc interval)))

"here" is printed an infinite number of times, however "but never here" isn't, so process-get proc 'running-p is always true, which I don't understand.

abicky commented 5 years ago

Thank you for your report. I've confirmed this issue is reproducible using Node.js 12.4.0. I try to fix it.

abicky commented 5 years ago

I've fixed the issue in https://github.com/abicky/nodejs-repl.el/pull/25 and released nodejs-repl.el 0.2.2.