Skip to content

Commit

Permalink
Merge pull request #239 from alison985/m10_rc
Browse files Browse the repository at this point in the history
Tokens to 5000 and cut dups
  • Loading branch information
alison985 authored Aug 31, 2017
2 parents 0962902 + e35321b commit 17ba8e7
Showing 1 changed file with 45 additions and 69 deletions.
114 changes: 45 additions & 69 deletions client/app/pages/queries/query-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,50 @@ function queryEditor(QuerySnippet) {
pre($scope) {
$scope.syntax = $scope.syntax || 'sql';

const schemaCompleter = {
getCompletions(state, session, pos, prefix, callback) {
// make a variable for the auto completion in the query editor
$scope.autoCompleteSchema = $scope.schema; // removeExtraSchemaInfo(

if (prefix.length === 0 || !$scope.autoCompleteSchema) {
callback(null, []);
return;
}

if (!$scope.autoCompleteSchema.keywords) {
const keywords = {};

$scope.autoCompleteSchema.forEach((table) => {
keywords[table.name] = 'Table';

table.columns.forEach((c) => { // autoCompleteColumns
if (c.charAt(c.length - 1) === ')') {
let parensStartAt = c.indexOf('(') - 1;
c = c.substring(0, parensStartAt);
parensStartAt = 1; // linter complains without this line
}
// remove '[P] ' for partition keys
if (c.charAt(0) === '[') {
c = c.substring(4, c.length);
}
// keywords[c] = 'Column'; // dups columns
keywords[`${table.name}.${c}`] = 'Column';
});
});

$scope.autoCompleteSchema.keywords = map(keywords, (v, k) =>
({
name: k,
value: k,
score: 0,
meta: v,
})
);
}
callback(null, $scope.autoCompleteSchema.keywords);
},
};

$scope.editorOptions = {
mode: 'json',
// require: ['ace/ext/language_tools'],
Expand Down Expand Up @@ -76,12 +120,10 @@ function queryEditor(QuerySnippet) {
newSchema.reduce((totalLength, table) => totalLength + table.columns.length, 0);
// If there are too many tokens we disable live autocomplete,
// as it makes typing slower.
if (tokensCount > 3000) {
if (tokensCount > 5000) {
editor.setOption('enableLiveAutocompletion', false);
editor.setOption('enableBasicAutocompletion', false);
} else {
editor.setOption('enableLiveAutocompletion', true);
editor.setOption('enableBasicAutocompletion', true);
}
}
});
Expand All @@ -93,72 +135,6 @@ function queryEditor(QuerySnippet) {
editor.focus();
},
};
/*
function removeExtraSchemaInfo(data) {
let newColumns = [];
data.forEach((table) => {
table.columns.forEach((column) => {
if (column.charAt(column.length - 1) === ')') {
let parensStartAt = column.indexOf('(') - 1;
column = column.substring(0, parensStartAt);
parensStartAt = 1; // linter complains without this line
}
// remove '[P] ' for partition keys
if (column.charAt(0) === '[') {
column = column.substring(4, column.length);
}
newColumns.push(column);
});
table.autoCompleteColumns = newColumns;
});
newColumns = []; // linter complains without this line
return data;
}
*/
const schemaCompleter = {
getCompletions(state, session, pos, prefix, callback) {
// make a variable for the auto completion in the query editor
$scope.autoCompleteSchema = $scope.schema; // removeExtraSchemaInfo(

if (prefix.length === 0 || !$scope.autoCompleteSchema) {
callback(null, []);
return;
}

if (!$scope.autoCompleteSchema.keywords) {
const keywords = {};

$scope.autoCompleteSchema.forEach((table) => {
keywords[table.name] = 'Table';

table.columns.forEach((c) => { // autoCompleteColumns
if (c.charAt(c.length - 1) === ')') {
let parensStartAt = c.indexOf('(') - 1;
c = c.substring(0, parensStartAt);
parensStartAt = 1; // linter complains without this line
}
// remove '[P] ' for partition keys
if (c.charAt(0) === '[') {
c = c.substring(4, c.length);
}
keywords[c] = 'Column';
keywords[`${table.name}.${c}`] = 'Column';
});
});

$scope.autoCompleteSchema.keywords = map(keywords, (v, k) =>
({
name: k,
value: k,
score: 0,
meta: v,
})
);
}
callback(null, $scope.autoCompleteSchema.keywords);
},
};


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

0 comments on commit 17ba8e7

Please sign in to comment.