completion modifier for SQL and JavaScript
This commit is contained in:
parent
27284cd29f
commit
961f8c4893
2 changed files with 59 additions and 14 deletions
|
|
@ -64,6 +64,30 @@ 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";
|
||||
|
|
|
|||
|
|
@ -77,7 +77,9 @@ var SqlServerHighlightRules = function() {
|
|||
/* https://msdn.microsoft.com/en-us/library/ms177520.aspx */
|
||||
"@@CONNECTIONS|@@CPU_BUSY|@@IDLE|@@IO_BUSY|@@PACKET_ERRORS|@@PACK_RECEIVED|@@PACK_SENT|@@TIMETICKS|@@TOTAL_ERRORS|@@TOTAL_READ|@@TOTAL_WRITE|FN_VIRTUALFILESTATS|" +
|
||||
/* https://msdn.microsoft.com/en-us/library/ms188353.aspx */
|
||||
"PATINDEX|TEXTPTR|TEXTVALID"
|
||||
"PATINDEX|TEXTPTR|TEXTVALID|" +
|
||||
/* other */
|
||||
"COALESCE|NULLIF"
|
||||
);
|
||||
|
||||
|
||||
|
|
@ -104,12 +106,14 @@ var SqlServerHighlightRules = function() {
|
|||
keywords += "|TYPE";
|
||||
|
||||
|
||||
//remove any other built in things from key word list
|
||||
//remove specific built in types from keyword list
|
||||
keywords = keywords.split('|');
|
||||
keywords = keywords.filter(function(value, index, self) {
|
||||
return logicalOperators.split('|').indexOf(value) === -1 && builtinFunctions.split('|').indexOf(value) === -1 && dataTypes.split('|').indexOf(value) === -1;
|
||||
});
|
||||
keywords = keywords.sort().join('|');
|
||||
|
||||
|
||||
var keywordMapper = this.createKeywordMapper({
|
||||
"constant.language": logicalOperators,
|
||||
"storage.type": dataTypes,
|
||||
|
|
@ -117,19 +121,7 @@ var SqlServerHighlightRules = function() {
|
|||
"support.storedprocedure": builtInStoredProcedures,
|
||||
"keyword": keywords,
|
||||
}, "identifier", true);
|
||||
|
||||
|
||||
// createKeywordMapper ignores case which we want because SqlServer keywords are not case sensitive which causes our keywords to get changed to lowercase.
|
||||
// However, the preferred standard for keywords is uppercase, so this transforms them back to uppercase for code completion
|
||||
// EXCEPTION: built in stored procedures are lower case
|
||||
builtInStoredProcedures = builtInStoredProcedures.split('|');
|
||||
for (var i = 0; i < this.$keywordList.length; i++) {
|
||||
var keyword = this.$keywordList[i];
|
||||
if (builtInStoredProcedures.indexOf(keyword) !== -1) continue;
|
||||
|
||||
this.$keywordList[i] = keyword.toUpperCase();
|
||||
}
|
||||
|
||||
|
||||
//https://msdn.microsoft.com/en-us/library/ms190356.aspx
|
||||
var setStatements = "SET ANSI_DEFAULTS|SET ANSI_NULLS|SET ANSI_NULL_DFLT_OFF|SET ANSI_NULL_DFLT_ON|SET ANSI_PADDING|SET ANSI_WARNINGS|SET ARITHABORT|SET ARITHIGNORE|SET CONCAT_NULL_YIELDS_NULL|SET CURSOR_CLOSE_ON_COMMIT|SET DATEFIRST|SET DATEFORMAT|SET DEADLOCK_PRIORITY|SET FIPS_FLAGGER|SET FMTONLY|SET FORCEPLAN|SET IDENTITY_INSERT|SET IMPLICIT_TRANSACTIONS|SET LANGUAGE|SET LOCK_TIMEOUT|SET NOCOUNT|SET NOEXEC|SET NUMERIC_ROUNDABORT|SET OFFSETS|SET PARSEONLY|SET QUERY_GOVERNOR_COST_LIMIT|SET QUOTED_IDENTIFIER|SET REMOTE_PROC_TRANSACTIONS|SET ROWCOUNT|SET SHOWPLAN_ALL|SET SHOWPLAN_TEXT|SET SHOWPLAN_XML|SET STATISTICS IO|SET STATISTICS PROFILE|SET STATISTICS TIME|SET STATISTICS XML|SET TEXTSIZE|SET XACT_ABORT".split('|');
|
||||
|
|
@ -218,6 +210,35 @@ var SqlServerHighlightRules = function() {
|
|||
this.embedRules(DocCommentHighlightRules, "doc-", [DocCommentHighlightRules.getEndRule("start")]);
|
||||
|
||||
this.normalizeRules();
|
||||
|
||||
|
||||
// prepare key word types for completion modifier
|
||||
builtInStoredProcedures = builtInStoredProcedures.split('|');
|
||||
logicalOperators = logicalOperators.split('|');
|
||||
builtinFunctions = builtinFunctions.split('|');
|
||||
dataTypes = dataTypes.split('|');
|
||||
|
||||
this.completionModifier = function(obj) {
|
||||
var word = obj.name,
|
||||
meta = 'keyword';
|
||||
|
||||
if (builtInStoredProcedures.indexOf(word) !== -1) meta = "storedProcedure";
|
||||
else {
|
||||
//all others are upper case
|
||||
word = word.toUpperCase();
|
||||
if (builtinFunctions.indexOf(word) !== -1) meta = "function";
|
||||
else if (dataTypes.indexOf(word) !== -1) meta = "dataType";
|
||||
else if (setStatements.indexOf(word) !== -1) meta = "setStatement";
|
||||
else if (logicalOperators.indexOf(word) !== -1) meta = "logicalOperator";
|
||||
}
|
||||
|
||||
return {
|
||||
name: word,
|
||||
value: word,
|
||||
score: 0,
|
||||
meta: meta
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
oop.inherits(SqlServerHighlightRules, TextHighlightRules);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue