skeeto / skewer-mode

Live web development in Emacs
The Unlicense
1.09k stars 57 forks source link

Skewer for Javascript autocompletion #2

Closed ScottyB closed 11 years ago

ScottyB commented 11 years ago

Hello,

Thanks a lot for building this little tool.

I have started building an auto-completion module using skewer for completing properties of an object. What do you think would be the best way to extend skewer.js to handle formatting the results of eval differently? For instance I would like to return an object where the keys are an object's properties and the values are the initial value or function interface for that key.

I am not sure if this code should be part of skewer-mode but I am happy to add it if need be.

skeeto commented 11 years ago

Interesting! This is something I've wanted to have in skewer, but I hadn't yet figured out how to properly implement JS completion. I was looking for libraries to do it but never found one.

Right now Emacs always sends an evaluation request to the browser. The browser's response always has a "type" field (filled with "eval", "error", or "log"), which Emacs uses to decide how to handle the response (only very recently). This allows for messages from the browser that aren't tied to a specific evaluation requests (logs, error logs).

To implement completion, Emacs should also have a type field in the object it sends to the browser, and skewer.js should dispatch on this type field. That way it can send an evaluation request ("eval") or something else, like a "completion" request: complete this expression and return the results as a "completion" type response.


Ok, in the middle of typing this message I just added this request type field (a0b7951). In skewer.js all you need to do is add a new request handler, like the request.type === "eval" handler, which gathers completions to send back to Emacs.