Skip to content

Commit 17ba8e7

Browse files
authored
Merge pull request #239 from alison985/m10_rc
Tokens to 5000 and cut dups
2 parents 0962902 + e35321b commit 17ba8e7

File tree

1 file changed

+45
-69
lines changed

1 file changed

+45
-69
lines changed

client/app/pages/queries/query-editor.js

Lines changed: 45 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,50 @@ function queryEditor(QuerySnippet) {
3131
pre($scope) {
3232
$scope.syntax = $scope.syntax || 'sql';
3333

34+
const schemaCompleter = {
35+
getCompletions(state, session, pos, prefix, callback) {
36+
// make a variable for the auto completion in the query editor
37+
$scope.autoCompleteSchema = $scope.schema; // removeExtraSchemaInfo(
38+
39+
if (prefix.length === 0 || !$scope.autoCompleteSchema) {
40+
callback(null, []);
41+
return;
42+
}
43+
44+
if (!$scope.autoCompleteSchema.keywords) {
45+
const keywords = {};
46+
47+
$scope.autoCompleteSchema.forEach((table) => {
48+
keywords[table.name] = 'Table';
49+
50+
table.columns.forEach((c) => { // autoCompleteColumns
51+
if (c.charAt(c.length - 1) === ')') {
52+
let parensStartAt = c.indexOf('(') - 1;
53+
c = c.substring(0, parensStartAt);
54+
parensStartAt = 1; // linter complains without this line
55+
}
56+
// remove '[P] ' for partition keys
57+
if (c.charAt(0) === '[') {
58+
c = c.substring(4, c.length);
59+
}
60+
// keywords[c] = 'Column'; // dups columns
61+
keywords[`${table.name}.${c}`] = 'Column';
62+
});
63+
});
64+
65+
$scope.autoCompleteSchema.keywords = map(keywords, (v, k) =>
66+
({
67+
name: k,
68+
value: k,
69+
score: 0,
70+
meta: v,
71+
})
72+
);
73+
}
74+
callback(null, $scope.autoCompleteSchema.keywords);
75+
},
76+
};
77+
3478
$scope.editorOptions = {
3579
mode: 'json',
3680
// require: ['ace/ext/language_tools'],
@@ -76,12 +120,10 @@ function queryEditor(QuerySnippet) {
76120
newSchema.reduce((totalLength, table) => totalLength + table.columns.length, 0);
77121
// If there are too many tokens we disable live autocomplete,
78122
// as it makes typing slower.
79-
if (tokensCount > 3000) {
123+
if (tokensCount > 5000) {
80124
editor.setOption('enableLiveAutocompletion', false);
81-
editor.setOption('enableBasicAutocompletion', false);
82125
} else {
83126
editor.setOption('enableLiveAutocompletion', true);
84-
editor.setOption('enableBasicAutocompletion', true);
85127
}
86128
}
87129
});
@@ -93,72 +135,6 @@ function queryEditor(QuerySnippet) {
93135
editor.focus();
94136
},
95137
};
96-
/*
97-
function removeExtraSchemaInfo(data) {
98-
let newColumns = [];
99-
data.forEach((table) => {
100-
table.columns.forEach((column) => {
101-
if (column.charAt(column.length - 1) === ')') {
102-
let parensStartAt = column.indexOf('(') - 1;
103-
column = column.substring(0, parensStartAt);
104-
parensStartAt = 1; // linter complains without this line
105-
}
106-
// remove '[P] ' for partition keys
107-
if (column.charAt(0) === '[') {
108-
column = column.substring(4, column.length);
109-
}
110-
newColumns.push(column);
111-
});
112-
table.autoCompleteColumns = newColumns;
113-
});
114-
newColumns = []; // linter complains without this line
115-
return data;
116-
}
117-
*/
118-
const schemaCompleter = {
119-
getCompletions(state, session, pos, prefix, callback) {
120-
// make a variable for the auto completion in the query editor
121-
$scope.autoCompleteSchema = $scope.schema; // removeExtraSchemaInfo(
122-
123-
if (prefix.length === 0 || !$scope.autoCompleteSchema) {
124-
callback(null, []);
125-
return;
126-
}
127-
128-
if (!$scope.autoCompleteSchema.keywords) {
129-
const keywords = {};
130-
131-
$scope.autoCompleteSchema.forEach((table) => {
132-
keywords[table.name] = 'Table';
133-
134-
table.columns.forEach((c) => { // autoCompleteColumns
135-
if (c.charAt(c.length - 1) === ')') {
136-
let parensStartAt = c.indexOf('(') - 1;
137-
c = c.substring(0, parensStartAt);
138-
parensStartAt = 1; // linter complains without this line
139-
}
140-
// remove '[P] ' for partition keys
141-
if (c.charAt(0) === '[') {
142-
c = c.substring(4, c.length);
143-
}
144-
keywords[c] = 'Column';
145-
keywords[`${table.name}.${c}`] = 'Column';
146-
});
147-
});
148-
149-
$scope.autoCompleteSchema.keywords = map(keywords, (v, k) =>
150-
({
151-
name: k,
152-
value: k,
153-
score: 0,
154-
meta: v,
155-
})
156-
);
157-
}
158-
callback(null, $scope.autoCompleteSchema.keywords);
159-
},
160-
};
161-
162138

163139
window.ace.acequire(['ace/ext/language_tools'], (langTools) => {
164140
langTools.addCompleter(schemaCompleter);

0 commit comments

Comments
 (0)