ScottyB / ac-js2

Javascript auto-completion in Emacs using Js2-mode's parser and Skewer-mode.
123 stars 8 forks source link

Completion fails sporadically #3

Closed dgutov closed 11 years ago

dgutov commented 11 years ago

With the example code from the screenshot:

var moreMaths = {};

moreMaths.product = function(num1, num2) {
  return num1 * num2;
};

moreMaths.divide = function(numerator, denominator) {
  return numerator / denominator;
};

var someMath = math();

moreMaths.|
  1. Place point at |, press C-M-i => completion buffer pops up with expected contents, including product and divide.
  2. Type d, press C-M-i again => it completes to "document".
  3. backward-kill-word, type d again, press C-M-i => there's like 30% chance it will complete to divide, otherwise it will be document.
  4. Similarly with modeMaths.di, it will either say no match, or complete to divide, with the same buffer contents.

completion-at-point calls the completion function several times during one completion command, so maybe we're sometimes getting the response for the previous request, or something. EDIT: Nope, I can reproduce the same problem with calling (ac-js2-candidates) directly, or with my company back-end.

I tracked it down to ac-js2-get-object-properties, and yes, it returns different completion lists for the same value of name.

ScottyB commented 11 years ago

This problem is caused by completing before the new result from skewer has loaded. I am unsure of how to hold up auto-completion until the result from skewer has loaded without blocking the user. The only plugin that I know that does this well is jedi.

dgutov commented 11 years ago

I don't understand how this currently works at all, then. Do you just hope that ac-js2-get-object-properties receives the reply before ac-js2-skewer-completion-candidates is called?

AFAIK, the common method of turning asynchronous action into synchronous involves a buffer with an external process, because we can use accept-process-output on it. See url-retrieve-synchronously for an example.

ScottyB commented 11 years ago

It was based on hope. I have changed it to use skewer-eval-synchronously now and doesn't block as much as I feared. I couldn't use external processes because it depends on a request made by the browser. Could you test to see if this fixes the problem you described above? It seems to be fixed my end.

dgutov commented 11 years ago

Yes, it's much better now. Thanks!