ajaxorg/ace — pull request #1189 by gjtorikian (2013-01-04 23:49:26+00:00)
Title: [WIP] Implement basic code completion

For #110.

Features include:

* Multiple key bindings: `Ctrl-Space|Shift-Space|Alt-Space`
* Keyboard navigation of autocompletion list
* Everything is done in a worker
* Clicking a different line detaches autocompletion
* Fuzzy matching support
* Inclusion of all Mode keywords from a higlighter's `createKeywordMapper`
* Rematch on character deletion and insertion
* Scoring based on distance of keyword (idea taken from Cloud9; pending permission from Ruben if we can include this)

I can think of a few improvements: enable autocompletion by default (without keybinding, based on a preference), and better integration of Mode highlighting rules into the autocompletion list, emmet support--but this is good enough for now.

Seems to work well on a file of 100k LOC (Ace unminified + jQuery unminified + APF unminified).

I made a few required changes to _lib/ace/worker/mirror.js_. The first is the ability to attach arbitrary additional data to the worker (beyond just the document value). The second is that currently, wokers fire on every doc change. I wanted the worker to only fire once, and then end itself. so I added the option to turn off `deferredUpdate`.

### Current Issues

Given these please let me know if a WIP PR is not appropriate and I'll close this and move the discussion back to the issues.

* This PR introduces a failing test, but I can't figure out why it's not functioning:

```
Test run aborted. Not all tests could be run!
ReferenceError: Worker is not defined
at new WorkerClient (/Users/gjtorikian/Developer/ace/lib/ace/worker/worker_client.js:65:24)
at Object. (/Users/gjtorikian/Developer/ace/lib/ace/autocomplete.js:43:14)
at global.define (/Users/gjtorikian/Developer/ace/node_modules/amd-loader/lib/amd-loader.js:79:28)
at Object. (/Users/gjtorikian/Developer/ace/lib/ace/autocomplete.js:31:1)
at Module._compile (module.js:449:26)
at Module.module.constructor._compile (/Users/gjtorikian/Developer/ace/node_modules/amd-loader/lib/amd-loader.js:11:31)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:362:17)
```

* For large results (I've seen it at ~300), the popup has issues populating. This is not dependent on document size, but size of matches.