Skip to content

Commit ffa4589

Browse files
committed
[sql-hint addon] Make tests pass again
1 parent 9e31c01 commit ffa4589

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

addon/hint/sql-hint.js

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
};
2121
var Pos = CodeMirror.Pos;
2222

23+
function isArray(val) { return Object.prototype.toString.call(val) == "[object Array]" }
24+
2325
function getKeywords(editor) {
2426
var mode = editor.doc.modeOption;
2527
if (mode === "sql") mode = "text/x-sql";
@@ -30,16 +32,22 @@
3032
return typeof item == "string" ? item : item.text;
3133
}
3234

35+
function wrapTable(name, value) {
36+
if (isArray(value)) value = {columns: value}
37+
if (!value.text) value.text = name
38+
return value
39+
}
40+
3341
function parseTables(input) {
3442
var result = {}
35-
if (Object.prototype.toString.call(input) == "[object Array]") {
43+
if (isArray(input)) {
3644
for (var i = input.length - 1; i >= 0; i--) {
3745
var item = input[i]
38-
result[getText(item).toUpperCase()] = item
46+
result[getText(item).toUpperCase()] = wrapTable(getText(item), item)
3947
}
4048
} else if (input) {
4149
for (var name in input)
42-
result[name.toUpperCase()] = input[name]
50+
result[name.toUpperCase()] = wrapTable(name, input[name])
4351
}
4452
return result
4553
}
@@ -62,11 +70,18 @@
6270
}
6371

6472
function addMatches(result, search, wordlist, formatter) {
65-
for (var word in wordlist) {
66-
if (!wordlist.hasOwnProperty(word)) continue;
67-
if (wordlist.slice) word = wordlist[word];
68-
69-
if (match(search, word)) result.push(formatter(word));
73+
if (isArray(wordlist)) {
74+
for (var i = 0; i < wordlist.length; i++)
75+
if (match(search, wordlist[i])) result.push(formatter(wordlist[i]))
76+
} else {
77+
for (var word in wordlist) if (wordlist.hasOwnProperty(word)) {
78+
var val = wordlist[word]
79+
if (!val || val === true)
80+
val = word
81+
else
82+
val = val.displayText ? {text: val.text, displayText: val.displayText} : val.text
83+
if (match(search, val)) result.push(formatter(val))
84+
}
7085
}
7186
}
7287

0 commit comments

Comments
 (0)