Skip to content
This repository was archived by the owner on Dec 10, 2018. It is now read-only.

Added tab completion functionality for collections #337

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

ecbtln
Copy link
Contributor

@ecbtln ecbtln commented Mar 5, 2014

  • 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

var cur = editor.getCursor();
var token = editor.getTokenAt(cur);
var tprop = token;
if (/\b(?:string|comment)\b/.test(token.type)) return;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment explaining what this regex is matching? if it is matches "string" or "comment" why do we return?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes its matching either string or comment. I will modify this to be more clear by removing the regex altogether.

You're right it shouldn't be returning, it should be calling the callback with no autocompletions in it and then returning. Good catch. The intent of the returning is that there are no autocompletion results to present if we are in a comment or string

@idbentley
Copy link

This looks pretty exciting, but I don't fully understand it. I'd like to get on a call to walk through it when you have time.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants