progress, and about to work on folding

This commit is contained in:
Morgan Yarbrough 2015-04-17 14:09:38 -04:00
commit e42bc9a265
3 changed files with 65 additions and 39 deletions

View file

@ -42,19 +42,21 @@ oop.inherits(FoldMode, BaseFoldMode);
(function() {
// Currently the only supported folding is #region comments
// TODO: add more folding (will require in depth testing because this has never existed before) for things like:
// TODO: add more folding (will require in depth testing because this has never existed before) for things like:
// CASE ... END https://msdn.microsoft.com/en-us/library/ms181765.aspx
// BEGIN ... END https://msdn.microsoft.com/en-us/library/ms182717.aspx
// this.foldingStartMarker =
// this.foldingStopMarker =
this.foldingStartMarker = /CASE|BEGIN/;
this.foldingStopMarker = /END/;
this.startRegionRe = /^\s*(\/\*|--)#region\b/;
this.getFoldWidget = function(session, foldStyle, row) {
var line = session.getLine(row);
if (this.startRegionRe.test(line))
// var fw = this.getFoldWidget(session, foldStyle, row);
if (this.startRegionRe.test(line))
return "start";
return "";

View file

@ -46,7 +46,8 @@ var SqlServerHighlightRules = function() {
// https://msdn.microsoft.com/en-us/library/ms189773.aspx
var logicalOperators = "ALL|AND|ANY|BETWEEN|EXISTS|IN|LIKE|NOT|OR|SOME";
logicalOperators+= "|NULL|IS";//SSMS colors these gray too
logicalOperators+= "|NULL|IS|APPLY|INNER|OUTER|LEFT|RIGHT|JOIN|CROSS";//SSMS colors these gray too
//note: manually removed LEFT and RIGHT from built in functions below to color it same way SSMS does
@ -76,7 +77,7 @@ var SqlServerHighlightRules = function() {
/* https://msdn.microsoft.com/en-us/library/ms186236.aspx (MANUAL) */
"CERTENCODED|CERTPRIVATEKEY|CURRENT_USER|DATABASE_PRINCIPAL_ID|HAS_PERMS_BY_NAME|IS_MEMBER|IS_ROLEMEMBER|IS_SRVROLEMEMBER|ORIGINAL_LOGIN|PERMISSIONS|PWDCOMPARE|PWDENCRYPT|SCHEMA_ID|SCHEMA_NAME|SESSION_USER|SUSER_ID|SUSER_NAME|SUSER_SID|SUSER_SNAME|SYS.FN_BUILTIN_PERMISSIONS|SYS.FN_GET_AUDIT_FILE|SYS.FN_MY_PERMISSIONS|SYSTEM_USER|USER_ID|USER_NAME|" +
/* https://msdn.microsoft.com/en-us/library/ms181984.aspx */
"ASCII|CHAR|CHARINDEX|CONCAT|DIFFERENCE|FORMAT|LEFT|LEN|LOWER|LTRIM|NCHAR|PATINDEX|QUOTENAME|REPLACE|REPLICATE|REVERSE|RIGHT|RTRIM|SOUNDEX|SPACE|STR|STUFF|SUBSTRING|UNICODE|UPPER|" +
"ASCII|CHAR|CHARINDEX|CONCAT|DIFFERENCE|FORMAT|LEN|LOWER|LTRIM|NCHAR|PATINDEX|QUOTENAME|REPLACE|REPLICATE|REVERSE|RTRIM|SOUNDEX|SPACE|STR|STUFF|SUBSTRING|UNICODE|UPPER|" +
/* https://msdn.microsoft.com/en-us/library/ms187786.aspx */
"$PARTITION|@@ERROR|@@IDENTITY|@@PACK_RECEIVED|@@ROWCOUNT|@@TRANCOUNT|BINARY_CHECKSUM|CHECKSUM|CONNECTIONPROPERTY|CONTEXT_INFO|CURRENT_REQUEST_ID|ERROR_LINE|ERROR_MESSAGE|ERROR_NUMBER|ERROR_PROCEDURE|ERROR_SEVERITY|ERROR_STATE|FORMATMESSAGE|GETANSINULL|GET_FILESTREAM_TRANSACTION_CONTEXT|HOST_ID|HOST_NAME|ISNULL|ISNUMERIC|MIN_ACTIVE_ROWVERSION|NEWID|NEWSEQUENTIALID|ROWCOUNT_BIG|XACT_STATE|" +
/* https://msdn.microsoft.com/en-us/library/ms177520.aspx */
@ -93,15 +94,24 @@ var SqlServerHighlightRules = function() {
);
//https://msdn.microsoft.com/en-us/library/ms176007.aspx
//these are lower case!
var builtInStoredProcedures = "sp_addextendedproc|sp_addextendedproperty|sp_addmessage|sp_addtype|sp_addumpdevice|sp_add_data_file_recover_suspect_db|sp_add_log_file_recover_suspect_db|sp_altermessage|sp_attach_db|sp_attach_single_file_db|sp_autostats|sp_bindefault|sp_bindrule|sp_bindsession|sp_certify_removable|sp_clean_db_file_free_space|sp_clean_db_free_space|sp_configure|sp_control_plan_guide|sp_createstats|sp_create_plan_guide|sp_create_plan_guide_from_handle|sp_create_removable|sp_cycle_errorlog|sp_datatype_info|sp_dbcmptlevel|sp_dbmmonitoraddmonitoring|sp_dbmmonitorchangealert|sp_dbmmonitorchangemonitoring|sp_dbmmonitordropalert|sp_dbmmonitordropmonitoring|sp_dbmmonitorhelpalert|sp_dbmmonitorhelpmonitoring|sp_dbmmonitorresults|sp_db_increased_partitions|sp_delete_backuphistory|sp_depends|sp_describe_first_result_set|sp_describe_undeclared_parameters|sp_detach_db|sp_dropdevice|sp_dropextendedproc|sp_dropextendedproperty|sp_dropmessage|sp_droptype|sp_execute|sp_executesql|sp_getapplock|sp_getbindtoken|sp_help|sp_helpconstraint|sp_helpdb|sp_helpdevice|sp_helpextendedproc|sp_helpfile|sp_helpfilegroup|sp_helpindex|sp_helplanguage|sp_helpserver|sp_helpsort|sp_helpstats|sp_helptext|sp_helptrigger|sp_indexoption|sp_invalidate_textptr|sp_lock|sp_monitor|sp_prepare|sp_prepexec|sp_prepexecrpc|sp_procoption|sp_recompile|sp_refreshview|sp_releaseapplock|sp_rename|sp_renamedb|sp_resetstatus|sp_sequence_get_range|sp_serveroption|sp_setnetname|sp_settriggerorder|sp_spaceused|sp_tableoption|sp_unbindefault|sp_unbindrule|sp_unprepare|sp_updateextendedproperty|sp_updatestats|sp_validname|sp_who|sys.sp_merge_xtp_checkpoint_files|sys.sp_xtp_bind_db_resource_pool|sys.sp_xtp_checkpoint_force_garbage_collection|sys.sp_xtp_control_proc_exec_stats|sys.sp_xtp_control_query_exec_stats|sys.sp_xtp_unbind_db_resource_pool";
// https://msdn.microsoft.com/en-us/library/ms189822.aspx
// var r = []; $('.tableSection').find('td').each(function() { r.push($(this).text().trim()); }); r = r.filter(function(value, index, self) { return self.indexOf(value) === index; }); r.sort(); console.log(r.join('|'));
var keywords = "ABSOLUTE|ACTION|ADA|ADD|ADMIN|AFTER|AGGREGATE|ALIAS|ALL|ALLOCATE|ALTER|AND|ANY|ARE|ARRAY|AS|ASC|ASENSITIVE|ASSERTION|ASYMMETRIC|AT|ATOMIC|AUTHORIZATION|BACKUP|BEFORE|BEGIN|BETWEEN|BIT_LENGTH|BLOB|BOOLEAN|BOTH|BREADTH|BREAK|BROWSE|BULK|BY|CALL|CALLED|CARDINALITY|CASCADE|CASCADED|CASE|CATALOG|CHARACTER|CHARACTER_LENGTH|CHAR_LENGTH|CHECK|CHECKPOINT|CLASS|CLOB|CLOSE|CLUSTERED|COALESCE|COLLATE|COLLATION|COLLECT|COLUMN|COMMIT|COMPLETION|COMPUTE|CONDITION|CONNECT|CONNECTION|CONSTRAINT|CONSTRAINTS|CONSTRUCTOR|CONTAINS|CONTAINSTABLE|CONTINUE|CORR|CORRESPONDING|COVAR_POP|COVAR_SAMP|CREATE|CROSS|CUBE|CUME_DIST|CURRENT|CURRENT_CATALOG|CURRENT_DATE|CURRENT_DEFAULT_TRANSFORM_GROUP|CURRENT_PATH|CURRENT_ROLE|CURRENT_SCHEMA|CURRENT_TIME|CURRENT_TRANSFORM_GROUP_FOR_TYPE|CYCLE|DATA|DATABASE|DBCC|DEALLOCATE|DEC|DECLARE|DEFAULT|DEFERRABLE|DEFERRED|DELETE|DENY|DEPTH|DEREF|DESC|DESCRIBE|DESCRIPTOR|DESTROY|DESTRUCTOR|DETERMINISTIC|DIAGNOSTICS|DICTIONARY|DISCONNECT|DISK|DISTINCT|DISTRIBUTED|DOMAIN|DOUBLE|DROP|DUMP|DYNAMIC|EACH|ELEMENT|ELSE|END|END-EXEC|EQUALS|ERRLVL|ESCAPE|EVERY|EXCEPT|EXCEPTION|EXEC|EXECUTE|EXISTS|EXIT|EXTERNAL|EXTRACT|FETCH|FILE|FILLFACTOR|FILTER|FIRST|FOR|FOREIGN|FORTRAN|FOUND|FREE|FREETEXT|FREETEXTTABLE|FROM|FULL|FULLTEXTTABLE|FUNCTION|FUSION|GENERAL|GET|GLOBAL|GO|GOTO|GRANT|GROUP|HAVING|HOLD|HOLDLOCK|HOST|HOUR|IDENTITY|IDENTITYCOL|IDENTITY_INSERT|IF|IGNORE|IMMEDIATE|IN|INCLUDE|INDEX|INDICATOR|INITIALIZE|INITIALLY|INNER|INOUT|INPUT|INSENSITIVE|INSERT|INTEGER|INTERSECT|INTERSECTION|INTERVAL|INTO|IS|ISOLATION|ITERATE|JOIN|KEY|KILL|LANGUAGE|LARGE|LAST|LATERAL|LEADING|LESS|LEVEL|LIKE|LIKE_REGEX|LIMIT|LINENO|LN|LOAD|LOCAL|LOCALTIME|LOCALTIMESTAMP|LOCATOR|MAP|MATCH|MEMBER|MERGE|METHOD|MINUTE|MOD|MODIFIES|MODIFY|MODULE|MULTISET|NAMES|NATIONAL|NATURAL|NCLOB|NEW|NEXT|NO|NOCHECK|NONCLUSTERED|NONE|NORMALIZE|NOT|NULL|NULLIF|OBJECT|OCCURRENCES_REGEX|OCTET_LENGTH|OF|OFF|OFFSETS|OLD|ON|ONLY|OPEN|OPERATION|OPTION|OR|ORDER|ORDINALITY|OUT|OUTER|OUTPUT|OVER|OVERLAPS|OVERLAY|PAD|PARAMETER|PARAMETERS|PARTIAL|PARTITION|PASCAL|PATH|PERCENT|PERCENTILE_CONT|PERCENTILE_DISC|PERCENT_RANK|PIVOT|PLAN|POSITION|POSITION_REGEX|POSTFIX|PRECISION|PREFIX|PREORDER|PREPARE|PRESERVE|PRIMARY|PRINT|PRIOR|PRIVILEGES|PROC|PROCEDURE|PUBLIC|RAISERROR|RANGE|READ|READS|READTEXT|RECONFIGURE|RECURSIVE|REF|REFERENCES|REFERENCING|REGR_AVGX|REGR_AVGY|REGR_COUNT|REGR_INTERCEPT|REGR_R2|REGR_SLOPE|REGR_SXX|REGR_SXY|REGR_SYY|RELATIVE|RELEASE|REPLICATION|RESTORE|RESTRICT|RESULT|RETURN|RETURNS|REVERT|REVOKE|ROLE|ROLLBACK|ROLLUP|ROUTINE|ROW|ROWCOUNT|ROWGUIDCOL|ROWS|RULE|SAVE|SAVEPOINT|SCHEMA|SCOPE|SCROLL|SEARCH|SECOND|SECTION|SECURITYAUDIT|SELECT|SEMANTICKEYPHRASETABLE|SEMANTICSIMILARITYDETAILSTABLE|SEMANTICSIMILARITYTABLE|SENSITIVE|SEQUENCE|SESSION|SET|SETS|SETUSER|SHUTDOWN|SIMILAR|SIZE|SOME|SPECIFIC|SPECIFICTYPE|SQL|SQLCA|SQLCODE|SQLERROR|SQLEXCEPTION|SQLSTATE|SQLWARNING|START|STATE|STATEMENT|STATIC|STATISTICS|STDDEV_POP|STDDEV_SAMP|STRUCTURE|SUBMULTISET|SUBSTRING_REGEX|SYMMETRIC|SYSTEM|TABLESAMPLE|TEMPORARY|TERMINATE|TEXTSIZE|THAN|THEN|TIMEZONE_HOUR|TIMEZONE_MINUTE|TO|TOP|TRAILING|TRAN|TRANSACTION|TRANSLATE|TRANSLATE_REGEX|TRANSLATION|TREAT|TRIGGER|TRIM|TRUNCATE|TSEQUAL|UESCAPE|UNDER|UNION|UNIQUE|UNKNOWN|UNNEST|UNPIVOT|UPDATE|UPDATETEXT|USAGE|USE|USER|USING|VALUE|VALUES|VARIABLE|VARYING|VAR_POP|VAR_SAMP|VIEW|WAITFOR|WHEN|WHENEVER|WHERE|WHILE|WIDTH_BUCKET|WINDOW|WITH|WITHIN|WITHIN GROUP|WITHOUT|WORK|WRITE|WRITETEXT|XMLAGG|XMLATTRIBUTES|XMLBINARY|XMLCAST|XMLCOMMENT|XMLCONCAT|XMLDOCUMENT|XMLELEMENT|XMLEXISTS|XMLFOREST|XMLITERATE|XMLNAMESPACES|XMLPARSE|XMLPI|XMLQUERY|XMLSERIALIZE|XMLTABLE|XMLTEXT|XMLVALIDATE|ZONE";
//add table hints and query hints (many overlap): https://msdn.microsoft.com/en-us/library/ms187373.aspx
// https://msdn.microsoft.com/en-us/library/ms181714.aspx
keywords+= "|KEEPIDENTITY|KEEPDEFAULTS|IGNORE_CONSTRAINTS|IGNORE_TRIGGERS|XLOCK|FORCESCAN|FORCESEEK|HOLDLOCK|NOLOCK|NOWAIT|PAGLOCK|READCOMMITTED|READCOMMITTEDLOCK|READPAST|READUNCOMMITTED|REPEATABLEREAD|ROWLOCK|SERIALIZABLE|SNAPSHOT|SPATIAL_WINDOW_MAX_CELLS|TABLOCK|TABLOCKX|UPDLOCK|XLOCK|IGNORE_NONCLUSTERED_COLUMNSTORE_INDEX|EXPAND|VIEWS|FAST|FORCE|KEEP|KEEPFIXED|MAXDOP|MAXRECURSION|OPTIMIZE|PARAMETERIZATION|SIMPLE|FORCED|RECOMPILE|ROBUST|PLAN|SPATIAL_WINDOW_MAX_CELLS|NOEXPAND|HINT";
keywords += "|KEEPIDENTITY|KEEPDEFAULTS|IGNORE_CONSTRAINTS|IGNORE_TRIGGERS|XLOCK|FORCESCAN|FORCESEEK|HOLDLOCK|NOLOCK|NOWAIT|PAGLOCK|READCOMMITTED|READCOMMITTEDLOCK|READPAST|READUNCOMMITTED|REPEATABLEREAD|ROWLOCK|SERIALIZABLE|SNAPSHOT|SPATIAL_WINDOW_MAX_CELLS|TABLOCK|TABLOCKX|UPDLOCK|XLOCK|IGNORE_NONCLUSTERED_COLUMNSTORE_INDEX|EXPAND|VIEWS|FAST|FORCE|KEEP|KEEPFIXED|MAXDOP|MAXRECURSION|OPTIMIZE|PARAMETERIZATION|SIMPLE|FORCED|RECOMPILE|ROBUST|PLAN|SPATIAL_WINDOW_MAX_CELLS|NOEXPAND|HINT";
//add join hints: https://msdn.microsoft.com/en-us/library/ms173815.aspx
keywords+= "|LOOP|HASH|MERGE|REMOTE";
keywords += "|LOOP|HASH|MERGE|REMOTE";
//https://msdn.microsoft.com/en-us/library/ms175976.aspx -seems messed up that microsofts offical reserved words does not contain these...
keywords += "|TRY|CATCH|THROW";
//highlighted words in SSMS that I'm not even sure where they come from
keywords += "|TYPE";
//remove any other built in things from key word list
@ -112,17 +122,21 @@ var SqlServerHighlightRules = function() {
keywords = keywords.sort().join('|');
var keywordMapper = this.createKeywordMapper({
"support.function": builtinFunctions,
"keyword": keywords,
"constant.language": logicalOperators,
"storage.type": dataTypes
"storage.type": dataTypes,
"support.function": builtinFunctions,
"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: build in stored procedures are lower case
for (var i = 0; i < this.$keywordList.length; i++) {
this.$keywordList[i] = this.$keywordList[i].toUpperCase();
var keyword = this.$keywordList[i];
if (builtInStoredProcedures.indexOf(keyword) !== -1) continue;
this.$keywordList[i] = keyword.toUpperCase();
}
@ -140,7 +154,20 @@ var SqlServerHighlightRules = function() {
}
this.$rules = {
"start": [{
start: [{
token: "string.start",
regex: "'",
next: [{
token: "constant.language.escape",
regex: /\\'/
}, {
token: "string.end",
next: "start",
regex: "'"
}, {
defaultToken: "string"
}]
}, {
token: "comment",
regex: "--.*$"
}, {
@ -162,13 +189,16 @@ var SqlServerHighlightRules = function() {
}, {
//https://msdn.microsoft.com/en-us/library/ms174986.aspx
token: "keyword.operator",
regex: "\\+|\\-|\\/|\\/\\/|%|<@>|@>|<@|&|\\^|~|<|>|<=|=>|==|!=|<>|="
regex: "\\+|\\-|\\/|\\/\\/|%|<@>|@>|<@|&|\\^|~|<|>|<=|=>|==|!=|<>|=|\\*"
}, {
token: "paren.lparen",
regex: "[\\(]"
}, {
token: "paren.rparen",
regex: "[\\)]"
}, {
token: "punctuation",
regex: ",|;"
}, {
token: "text",
regex: "\\s+"

View file

@ -1,3 +1,7 @@
.ace_line{
font-family:Consolas
}
.ace-sqlserver .ace_gutter {
background: #ebebeb;
color: #333;
@ -15,7 +19,8 @@
}
.ace-sqlserver .ace_identifier{
color: #008080;
/*color: #008080;*/
color:black;
}
@ -24,24 +29,27 @@
/*text-transform: uppercase;*/
}
.ace-sqlserver .ace_comment{
color: #FD971F;
}
.ace-sqlserver .ace_numeric{
color: black;
}
.ace-sqlserver .ace_storage{
color: #979797;
font-style: italic;
/*color: #979797;*/
color: #11B7BE;
/*color: #00A2FF;*/
/*font-style: italic;*/
/*text-transform: uppercase;*/
}
.ace-sqlserver .ace_bracket {
border: 1px solid magenta;
.ace-sqlserver .ace_keyword.ace_operator,
.ace-sqlserver .ace_lparen,
.ace-sqlserver .ace_rparen,
.ace-sqlserver .ace_punctuation{
color: #808080;
}
.ace-sqlserver .ace_set.ace_statement{
/*color: #11B7BE;*/
color: #0000FF;
@ -76,9 +84,6 @@
color: white;
}
.ace-sqlserver .ace_fold {
}
.ace-sqlserver .ace_support.ace_function {
color: #FF00FF;
/*text-transform: uppercase;*/
@ -103,20 +108,9 @@
font-style:italic;
color:#FD971F;
}
.ace-sqlserver .ace_keyword.ace_operator {
color: rgb(104, 118, 135);
}
.ace-sqlserver .ace_comment {
color: #FD971F;
}
.ace-sqlserver .ace_comment.ace_doc {
color: #FD971F;
}
.ace-sqlserver .ace_comment.ace_doc.ace_tag {
color: #FD971F;
color:#008000;
}
.ace-sqlserver .ace_constant.ace_numeric {
@ -131,8 +125,8 @@
color: rgb(104, 104, 91);
}
.ace-sqlserver .ace_entity.ace_name.ace_function {
color: #0000A2;
.ace-sqlserver .ace_support.ace_storedprocedure {
color: #800000;
}