remove completionModifer, one off for SQL Server Mode

This commit is contained in:
sevin7676 2015-04-20 04:50:25 -04:00
commit e58fa3e6d7
5 changed files with 40 additions and 68 deletions

View file

@ -64,30 +64,6 @@ var JavaScriptHighlightRules = function(options) {
"alert",
"constant.language.boolean": "true|false"
}, "identifier");
// modify keyword completions meta display and remove things that are irrelevant
var modCache = {};
this.completionModifier = function(obj) {
var n = obj.name;
if (n.search('__parent__|__count__|proto__') !== -1) return; //can't cache reserved keys
if (modCache[n] === undefined) {
if (n.search('enum|await|implements|package|protected|static|interface|private|public') !== -1) modCache[n] = ''; //future
else if (n.search('Namespace|QName|XML|XMLList') !== -1) modCache[n] = ''; //E4X is obsolete
else if (n.search('Iterator|ParallelArray|StopIeration') !== -1) modCache[n] = ''; //non standard
else if (n.search('Array|Boolean|Date|Function|Number|Object|RegExp|String|Proxy') !== -1) modCache[n] = 'object';
else if (n.search('Error|EvalError|InternalError|RangeError|ReferenceError|StopIteration|SyntaxError|TypeError|URIError') !== -1) modCache[n] = 'object';
else if (n.search('alert|eval|isFinite|isNan|parseFloat|parseInt|decodeURI|decodeURIComponent|encodeURI|encodeURIComponent|escape|unescape') !== -1) modCache[n] = 'function';
else if (n.search('null|Infinity|NaN|undefined') !== -1) modCache[n] = 'constant';
else if (n.search('const|let|var|function|class|get|set') !== -1) modCache[n] = 'declaration';
else if (n.search('true|false') !== -1) modCache[n] = 'boolean';
else modCache[n] = 'keyword';
}
obj.meta = modCache[n];
if (obj.meta === '') return; //don't show obsolete
return obj;
};
// keywords which can be followed by regular expressions
var kwBeforeRe = "case|do|else|finally|in|instanceof|return|throw|try|typeof|yield|void";

View file

@ -46,6 +46,36 @@ oop.inherits(Mode, TextMode);
(function() {
this.lineCommentStart = "--";
this.blockComment = {start: "/*", end: "*/"};
/**
* Override keyword completions to ensure proper case for completions
* and use smart meta tags instead of 'keyword' for all completions.
*/
this.getCompletions = function(state, session, pos, prefix) {
if (this.getCompletionsResult) return this.getCompletionsResult;
var keywords = this.$keywordList || this.$createKeywordList();
var types = session.$mode.$highlightRules.keywordTypes;
this.getCompletionsResult = keywords.map(function(word) {
var meta = 'keyword';
if (types.builtInStoredProcedures.indexOf(word) !== -1) meta = "procedure";
else {
word = word.toUpperCase(); //all others are upper case
if (types.builtinFunctions.indexOf(word) !== -1) meta = "function";
else if (types.dataTypes.indexOf(word) !== -1) meta = "type";
else if (types.setStatements.indexOf(word) !== -1) meta = "statement";
else if (types.logicalOperators.indexOf(word) !== -1) meta = "operator";
}
return {
name: word,
value: word,
score: 0,
meta: meta
};
});
return this.getCompletionsResult;
};
this.$id = "ace/mode/sql";
}).call(Mode.prototype);

View file

@ -211,41 +211,19 @@ var SqlServerHighlightRules = function() {
this.normalizeRules();
// prepare key word types for completion modifier
builtInStoredProcedures = builtInStoredProcedures.split('|');
logicalOperators = logicalOperators.split('|');
builtinFunctions = builtinFunctions.split('|');
dataTypes = dataTypes.split('|');
var modCache = {};
this.completionModifier = function(obj) {
var word = obj.name,
meta = 'keyword';
if (modCache[word] === undefined) {
if (builtInStoredProcedures.indexOf(word) !== -1) meta = "procedure";
else {
//all others are upper case
word = word.toUpperCase();
if (builtinFunctions.indexOf(word) !== -1) meta = "function";
else if (dataTypes.indexOf(word) !== -1) meta = "type";
else if (setStatements.indexOf(word) !== -1) meta = "statement";
else if (logicalOperators.indexOf(word) !== -1) meta = "operator";
}
modCache[word] = {
word: word,
value: word,
meta: meta,
score: 0
};
}
return modCache[word];
// export types for overriding get completions
this.keywordTypes = {
builtInStoredProcedures: builtInStoredProcedures.split('|'),
logicalOperators: logicalOperators.split('|'),
builtinFunctions: builtinFunctions.split('|'),
dataTypes: dataTypes.split('|'),
setStatements: setStatements,
};
};
oop.inherits(SqlServerHighlightRules, TextHighlightRules);
exports.SqlHighlightRules = SqlServerHighlightRules;
console.log('exports',exports);
});

View file

@ -368,18 +368,14 @@ var Mode = function() {
};
this.getCompletions = function(state, session, pos, prefix) {
var self = this;
var keywords = this.$keywordList || this.$createKeywordList();
return keywords.map(function(word) {
var r = {
return {
name: word,
value: word,
score: 0,
meta: "keyword"
};
return self.$highlightRules.completionModifier ? self.$highlightRules.completionModifier.call(self, r) : r;
}).filter(function(value) {
return value !== undefined;
});
};

View file

@ -227,14 +227,6 @@ var TextHighlightRules = function() {
this.getKeywords = function() {
return this.$keywords;
};
/**
* Function that can be set by HighlightRules to modify a keyword completion.
* The function receives {name<string>, value<string>, score<number>, meta<string>}
* and should return the same type or undefined to skip adding the result to
* the completion list.
*/
this.completionModifier = null;
}).call(TextHighlightRules.prototype);