remove completionModifer, one off for SQL Server Mode
This commit is contained in:
parent
1ec6eb7b5d
commit
e58fa3e6d7
5 changed files with 40 additions and 68 deletions
|
|
@ -65,30 +65,6 @@ var JavaScriptHighlightRules = function(options) {
|
||||||
"constant.language.boolean": "true|false"
|
"constant.language.boolean": "true|false"
|
||||||
}, "identifier");
|
}, "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
|
// keywords which can be followed by regular expressions
|
||||||
var kwBeforeRe = "case|do|else|finally|in|instanceof|return|throw|try|typeof|yield|void";
|
var kwBeforeRe = "case|do|else|finally|in|instanceof|return|throw|try|typeof|yield|void";
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,36 @@ oop.inherits(Mode, TextMode);
|
||||||
this.lineCommentStart = "--";
|
this.lineCommentStart = "--";
|
||||||
this.blockComment = {start: "/*", end: "*/"};
|
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";
|
this.$id = "ace/mode/sql";
|
||||||
}).call(Mode.prototype);
|
}).call(Mode.prototype);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -211,41 +211,19 @@ var SqlServerHighlightRules = function() {
|
||||||
|
|
||||||
this.normalizeRules();
|
this.normalizeRules();
|
||||||
|
|
||||||
|
// export types for overriding get completions
|
||||||
// prepare key word types for completion modifier
|
this.keywordTypes = {
|
||||||
builtInStoredProcedures = builtInStoredProcedures.split('|');
|
builtInStoredProcedures: builtInStoredProcedures.split('|'),
|
||||||
logicalOperators = logicalOperators.split('|');
|
logicalOperators: logicalOperators.split('|'),
|
||||||
builtinFunctions = builtinFunctions.split('|');
|
builtinFunctions: builtinFunctions.split('|'),
|
||||||
dataTypes = dataTypes.split('|');
|
dataTypes: dataTypes.split('|'),
|
||||||
|
setStatements: setStatements,
|
||||||
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];
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
oop.inherits(SqlServerHighlightRules, TextHighlightRules);
|
oop.inherits(SqlServerHighlightRules, TextHighlightRules);
|
||||||
|
|
||||||
exports.SqlHighlightRules = SqlServerHighlightRules;
|
exports.SqlHighlightRules = SqlServerHighlightRules;
|
||||||
|
console.log('exports',exports);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -368,18 +368,14 @@ var Mode = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.getCompletions = function(state, session, pos, prefix) {
|
this.getCompletions = function(state, session, pos, prefix) {
|
||||||
var self = this;
|
|
||||||
var keywords = this.$keywordList || this.$createKeywordList();
|
var keywords = this.$keywordList || this.$createKeywordList();
|
||||||
return keywords.map(function(word) {
|
return keywords.map(function(word) {
|
||||||
var r = {
|
return {
|
||||||
name: word,
|
name: word,
|
||||||
value: word,
|
value: word,
|
||||||
score: 0,
|
score: 0,
|
||||||
meta: "keyword"
|
meta: "keyword"
|
||||||
};
|
};
|
||||||
return self.$highlightRules.completionModifier ? self.$highlightRules.completionModifier.call(self, r) : r;
|
|
||||||
}).filter(function(value) {
|
|
||||||
return value !== undefined;
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -228,14 +228,6 @@ var TextHighlightRules = function() {
|
||||||
return this.$keywords;
|
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);
|
}).call(TextHighlightRules.prototype);
|
||||||
|
|
||||||
exports.TextHighlightRules = TextHighlightRules;
|
exports.TextHighlightRules = TextHighlightRules;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue