Permalink
Browse files

Merge pull request #78 from iwehrman/iwehrman/global-hinting

Iwehrman/global hinting
  • Loading branch information...
2 parents 1881b80 + 58d9179 commit d102a4c079c74e0652edfc8a0978faa900c1c45a @njx njx committed Dec 19, 2012
Showing with 12 additions and 3 deletions.
  1. +2 −1 lib/util/javascript-hint.js
  2. +10 −2 mode/javascript/javascript.js
@@ -124,8 +124,9 @@
}
else {
// If not, just look in the window object and any local scope
- // (reading into JS mode internals to get at the local variables)
+ // (reading into JS mode internals to get at the local and global variables)
for (var v = token.state.localVars; v; v = v.next) maybeAdd(v.name);
+ for (var v = token.state.globalVars; v; v = v.next) maybeAdd(v.name);
gatherCompletions(window);
forEach(keywords, maybeAdd);
}
@@ -162,12 +162,19 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
return true;
}
function register(varname) {
+ function inList(list) {
+ for (var v = list; v; v = v.next)
+ if (v.name == varname) return true;
+ return false;
+ }
var state = cx.state;
if (state.context) {
cx.marked = "def";
- for (var v = state.localVars; v; v = v.next)
- if (v.name == varname) return;
+ if (inList(state.localVars)) return;
state.localVars = {name: varname, next: state.localVars};
+ } else {
+ if (inList(state.globalVars)) return;
+ state.globalVars = {name: varname, next: state.globalVars};
}
}
@@ -320,6 +327,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
cc: [],
lexical: new JSLexical((basecolumn || 0) - indentUnit, 0, "block", false),
localVars: parserConfig.localVars,
+ globalVars: parserConfig.globalVars,
context: parserConfig.localVars && {vars: parserConfig.localVars},
indented: 0
};

0 comments on commit d102a4c

Please sign in to comment.