Sarcasm / irony-mode

A C/C++ minor mode for Emacs powered by libclang
GNU General Public License v3.0
904 stars 99 forks source link

irony-diagnostics some times fails to fire call-backs #159

Closed pdixon closed 9 years ago

pdixon commented 9 years ago

I've been using flycheck-irony. Fairly regularly the checker seems to get stuck (i.e FlyC* showing in the mode-line, indicating a check is in progress). It seems to happen most often while I'm typing quickly, but I'm pretty sure I can also trigger it by saving the buffer while a check is in progress.

I think the problem is in irony-diagnostics--request-handler.

(defun irony-diagnostics--request-handler (diagnostics context)
  (when (equal (list irony-diagnostics--request-context
                     (irony-diagnostics--context))
               (make-list 2 context))
    (setq irony-diagnostics--diagnostics diagnostics
          irony-diagnostics--available-context context)
    (mapc 'funcall irony-diagnostics--callbacks)))

The when effectively checks that the current state of the buffer matches what it was when the request was started, if it isn't the nothing happens. Since flycheck requires the callback to be called at least once it just gets stuck.

I've modified irony-diagnostics--request-handler to start another request if the buffer has changed since the last request has triggered. i.e

(defun irony-diagnostics--request-handler (diagnostics context)
  (if (equal (list irony-diagnostics--request-context
                   (irony-diagnostics--context))
             (make-list 2 context))
      (progn
        (setq irony-diagnostics--diagnostics diagnostics
              irony-diagnostics--available-context context)
        (mapc 'funcall irony-diagnostics--callbacks))
    (irony-diagnostics--send-request)))

with this change in place I haven't managed to get flycheck stuck. Clearly this is a fairly brute force solution, but I'm not yet familiar enough with irony-mode or flycheck to come up with a more efficient approach.

Sarcasm commented 9 years ago

Thank you for your report, I knew I would have to think about supporting some kind of status in irony-mode requests. It would be better to do this properly by supporting error on irony-server side (#157) and then allow an interrupted status for callbacks that are out-of-date.

Then this could be mapped to flycheck statuses: http://flycheck.readthedocs.org/en/latest/dev/api.html#status-callback-protocol

Sarcasm commented 9 years ago

This should be fixed now, hopefully flycheck-irony is reliable now.