MCPcopy Create free account
hub / github.com/TruthHun/BookStack / nameCompletion

Function nameCompletion

static/editor.md/lib/codemirror/addon/hint/sql-hint.js:83–139  ·  view source on GitHub ↗
(cur, token, result, editor)

Source from the content-addressed store, hash-verified

81 }
82
83 function nameCompletion(cur, token, result, editor) {
84 // Try to complete table, colunm names and return start position of completion
85 var useBacktick = false;
86 var nameParts = [];
87 var start = token.start;
88 var cont = true;
89 while (cont) {
90 cont = (token.string.charAt(0) == ".");
91 useBacktick = useBacktick || (token.string.charAt(0) == "`");
92
93 start = token.start;
94 nameParts.unshift(cleanName(token.string));
95
96 token = editor.getTokenAt(Pos(cur.line, token.start));
97 if (token.string == ".") {
98 cont = true;
99 token = editor.getTokenAt(Pos(cur.line, token.start));
100 }
101 }
102
103 // Try to complete table names
104 var string = nameParts.join(".");
105 addMatches(result, string, tables, function(w) {
106 return useBacktick ? insertBackticks(w) : w;
107 });
108
109 // Try to complete columns from defaultTable
110 addMatches(result, string, defaultTable, function(w) {
111 return useBacktick ? insertBackticks(w) : w;
112 });
113
114 // Try to complete columns
115 string = nameParts.pop();
116 var table = nameParts.join(".");
117
118 // Check if table is available. If not, find table by Alias
119 if (!getItem(tables, table))
120 table = findTableByAlias(table, editor);
121
122 var columns = getItem(tables, table);
123 if (columns && Array.isArray(tables) && columns.columns)
124 columns = columns.columns;
125
126 if (columns) {
127 addMatches(result, string, columns, function(w) {
128 if (typeof w == "string") {
129 w = table + "." + w;
130 } else {
131 w = shallowClone(w);
132 w.text = table + "." + w.text;
133 }
134 return useBacktick ? insertBackticks(w) : w;
135 });
136 }
137
138 return start;
139 }
140

Callers 1

sql-hint.jsFile · 0.85

Calls 6

cleanNameFunction · 0.85
addMatchesFunction · 0.85
insertBackticksFunction · 0.85
getItemFunction · 0.85
findTableByAliasFunction · 0.85
shallowCloneFunction · 0.85

Tested by

no test coverage detected