zedapp/zed — pull request #147 by robru (2014-03-19 07:52:19+00:00)
Title: Pre-emptively pass more info to the sandbox modules.

I think I'm losing my mind, because I wrote out a long issue explaining some thoughts I had about simplifying the sandbox API, but now I can't find it. I must have accidentally closed the tab without submitting it. Bah.

Basically, today I was working on fixing that stripper issue, and I was just really annoyed by the sheer number of callbacks that were necessary in order to achieve it. In the worst case (ie, when autosave is enabled, and when there are empty lines to be deleted at the end), the number of callbacks is 6, that means 6 roundtrips between the sandbox and the core in order to do a simple job like whitespace stripping.

So I was thinking, there just has to be a better way to do this. And it occurred to me that actually we could save quite a few callbacks by simply pre-emptively providing all the necessary information before the extension is even invoked.

Please tell me what you think of the following idea. If you like it, I'd like to expand on it.

* it needs `cursorIndex` in addition to `cursor`, but as that's only implemented in the sandbox API, I'll have to move that into core in order to access it from here.
* I'd also like to just dump the complete preferences list right in there too, so they can be accessed from extensions without a callback.

If you're concerned about sending the full document text unconditionally into extensions that might not even use it, it would be easy to make this only send the information that the extensions request. For example, in `commands.json` we could specify `"text": true` and then if we detect that `text` is true, we can replace it with the full body text. If `text` isn't true, then don't insert the text.

I'm pretty excited about this idea; by giving all possible info to the extension right up front, it cuts out all the getter callbacks. At that point, many extensions would only need to call a single setter method, and wouldn't even need to provide a callback at all. So you could almost pretend that you're programming synchronously ;-)