MCPcopy Create free account
hub / github.com/nwutils/nw-sample-apps / scriptHint

Function scriptHint

mini-code-edit/cm/lib/util/javascript-hint.js:19–53  ·  view source on GitHub ↗
(editor, keywords, getToken)

Source from the content-addressed store, hash-verified

17 }
18
19 function scriptHint(editor, keywords, getToken) {
20 // Find the token at the cursor
21 var cur = editor.getCursor(), token = getToken(editor, cur), tprop = token;
22 // If it's not a 'word-style' token, ignore the token.
23 if (!/^[\w$_]*$/.test(token.string)) {
24 token = tprop = {start: cur.ch, end: cur.ch, string: "", state: token.state,
25 className: token.string == "." ? "property" : null};
26 }
27 // If it is a property, find out what it is a property of.
28 while (tprop.className == "property") {
29 tprop = getToken(editor, {line: cur.line, ch: tprop.start});
30 if (tprop.string != ".") return;
31 tprop = getToken(editor, {line: cur.line, ch: tprop.start});
32 if (tprop.string == ')') {
33 var level = 1;
34 do {
35 tprop = getToken(editor, {line: cur.line, ch: tprop.start});
36 switch (tprop.string) {
37 case ')': level++; break;
38 case '(': level--; break;
39 default: break;
40 }
41 } while (level > 0)
42 tprop = getToken(editor, {line: cur.line, ch: tprop.start});
43 if (tprop.className == 'variable')
44 tprop.className = 'function';
45 else return; // no clue
46 }
47 if (!context) var context = [];
48 context.push(tprop);
49 }
50 return {list: getCompletions(token, context, keywords),
51 from: {line: cur.line, ch: token.start},
52 to: {line: cur.line, ch: token.end}};
53 }
54
55 CodeMirror.javascriptHint = function(editor) {
56 return scriptHint(editor, javascriptKeywords,

Callers 1

javascript-hint.jsFile · 0.85

Calls 1

getCompletionsFunction · 0.85

Tested by

no test coverage detected