10gen-labs/mongo-web-shell — pull request #337 by ecbtln (2014-03-05 20:31:51+00:00)
Title: Added tab completion functionality for collections

- Adds in functionality for basic functionality for tab completion for collections on the main db
- Makes use of code-mirror's `show-hint.js` add-on.
- When hitting tab, the code will invoke the function to decide whether or not any autocompletions can be suggested. If none are found, nothing happens, if 1 is found, the UI automatically fills in that one suggestion, and if more than 1 is found a suggestion box appears showing all of them.
- The code also attempts to parse the current cursor position, so, for example, the following autocompletions will work:

Assume that the collections `foo`, `bar`, and `foobar` exist.

After hitting tab,
`db.` will autocomplete to show all of the above options
`db.f` will autocomplete to show `foo` and `foobar`
`db.foob` will autocomplete automatically to `foobar`

Furthermore,

if `x=db` has been executed previously,
`x.` will also autocomplete to show all of the available options

But if `y = {}` has been executed,

`y.` will not autocomplete because it does not evaluate to an object equal to the global `db` object.

Finally, if we set:

`a = {}`
`a.b = db`

Then the autocompletion logic will recognize that `a.b` evaluates to `db` and therefore will autocomplete `a.b.` to all of the available options.

For now, this context-awareness only works for properties in dot-notation, but I plan on implementing it for bracket notation as well (which is really just a special type of property access). Evaluating functions is more problematic, however, because there is no way to safely know which function evaluations will modify state and which ones won't.

- Also, added Ctrl-U to clear contents of line in shell, just like command line