fixes #1976: minor REPL tab completion bug fixes

This commit is contained in:
Michael Ficarra
2011-12-27 00:44:29 -05:00
parent 62a331a3dc
commit c8059a752f
2 changed files with 9 additions and 7 deletions

View File

@@ -62,7 +62,7 @@
ACCESSOR = /\s*([\w\.]+)(?:\.(\w*))$/;
SIMPLEVAR = /\s*(\w*)$/i;
SIMPLEVAR = /(\w+)$/i;
autocomplete = function(text) {
return completeAttribute(text) || completeVariable(text) || [[], text];
@@ -77,7 +77,7 @@
} catch (error) {
return;
}
completions = getCompletions(prefix, Object.getOwnPropertyNames(val));
completions = getCompletions(prefix, Object.getOwnPropertyNames(Object(val)));
return [completions, prefix];
}
};
@@ -85,8 +85,9 @@
completeVariable = function(text) {
var completions, free, keywords, possibilities, r, vars, _ref;
free = (_ref = text.match(SIMPLEVAR)) != null ? _ref[1] : void 0;
if (text === "") free = "";
if (free != null) {
vars = Script.runInThisContext('Object.getOwnPropertyNames(this)');
vars = Script.runInThisContext('Object.getOwnPropertyNames(Object(this))');
keywords = (function() {
var _i, _len, _ref2, _results;
_ref2 = CoffeeScript.RESERVED;

View File

@@ -63,7 +63,7 @@ run = (buffer) ->
# Regexes to match complete-able bits of text.
ACCESSOR = /\s*([\w\.]+)(?:\.(\w*))$/
SIMPLEVAR = /\s*(\w*)$/i
SIMPLEVAR = /(\w+)$/i
# Returns a list of completions, and the completed text.
autocomplete = (text) ->
@@ -77,14 +77,15 @@ completeAttribute = (text) ->
val = Script.runInThisContext obj
catch error
return
completions = getCompletions prefix, Object.getOwnPropertyNames val
completions = getCompletions prefix, Object.getOwnPropertyNames Object val
[completions, prefix]
# Attempt to autocomplete an in-scope free variable: `one`.
completeVariable = (text) ->
free = (text.match SIMPLEVAR)?[1]
free = text.match(SIMPLEVAR)?[1]
free = "" if text is ""
if free?
vars = Script.runInThisContext 'Object.getOwnPropertyNames(this)'
vars = Script.runInThisContext 'Object.getOwnPropertyNames(Object(this))'
keywords = (r for r in CoffeeScript.RESERVED when r[..1] isnt '__')
possibilities = vars.concat keywords
completions = getCompletions free, possibilities