diff --git a/demo/kitchen-sink/docs/sqlserver.sqlserver b/demo/kitchen-sink/docs/sqlserver.sqlserver new file mode 100644 index 00000000..329930af --- /dev/null +++ b/demo/kitchen-sink/docs/sqlserver.sqlserver @@ -0,0 +1,63 @@ +-- ============================================= +-- Author: Morgan Yarbrough +-- Create date: 4/27/2015 +-- Description: Test Procedure that shows off language features. +-- Includes non-standard folding using region comments using either +-- line comments or block comments (both are demonstrated below) +-- This mode imitates SSMS and it designed to be used with SQL Server theme. +-- ============================================= +CREATE PROCEDURE dbo.TestProcedure + +--#region parameters + @vint INT = 1 + ,@vdate DATE = NULL + ,@vdatetime DATETIME = DATEADD (dd, 1, GETDATE()) + ,@vvarchar VARCHAR(MAX) = '' +--#endregion + +AS +BEGIN + + /*#region set statements */ + SET NOCOUNT ON; + SET XACT_ABORT ON; + SET QUOTED_IDENTIFIER ON; + /*#endregion*/ + + /** + * These comments will produce a fold widget + */ + + -- folding demonstration + SET @vint = CASE + WHEN @vdate IS NULL + THEN 1 + ELSE 2 + END + + -- another folding demonstration + IF @vint = 1 + BEGIN + SET @vvarchar='one' + SET @vint = DATEDIFFT(dd, @vdate, @vdatetime) + END + + -- this mode handles strings properly + DECLARE @sql NVARCHAR(4000) = N'SELECT TOP(1) OrderID + FROM Orders + WHERE @OrderDate > GETDATE()' + + -- this mode is aware of build in stored procedures + EXECUTE sp_executesql @sql + + -- demonstrating some syntax highlighting + SELECT Orders.OrderID + ,Customers.CompanyName + ,DATEFROMPARTS(YEAR(GETDATE()), 1, 1) AS FirstDayOfYear + FROM Orders + INNER JOIN Customers + ON Orders.CustomerID = Customers.CustomerID + WHERE CompanyName NOT LIKE '%something' + OR CompanyName IS NULL + OR CompanyName IN ('bla', 'nothing') +END diff --git a/lib/ace/ext/modelist.js b/lib/ace/ext/modelist.js index 0351567b..7a5a1e9c 100644 --- a/lib/ace/ext/modelist.js +++ b/lib/ace/ext/modelist.js @@ -146,6 +146,7 @@ var supportedModes = { Soy_Template:["soy"], Space: ["space"], SQL: ["sql"], + SQLServer: ["sqlserver"], Stylus: ["styl|stylus"], SVG: ["svg"], Tcl: ["tcl"], diff --git a/lib/ace/ext/themelist.js b/lib/ace/ext/themelist.js index 8914c776..4e3f0ad7 100644 --- a/lib/ace/ext/themelist.js +++ b/lib/ace/ext/themelist.js @@ -57,6 +57,7 @@ var themeData = [ ["XCode" ], ["Kuroir"], ["KatzenMilch"], + ["SQL Server" ,"sqlserver" , "light"], ["Ambiance" ,"ambiance" , "dark"], ["Chaos" ,"chaos" , "dark"], ["Clouds Midnight" ,"clouds_midnight" , "dark"], diff --git a/lib/ace/mode/folding/cstyle.js b/lib/ace/mode/folding/cstyle.js index a98807ab..6a6abca7 100644 --- a/lib/ace/mode/folding/cstyle.js +++ b/lib/ace/mode/folding/cstyle.js @@ -53,7 +53,7 @@ oop.inherits(FoldMode, BaseFoldMode); this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/; this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/; this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/; - this.startRegionRe = /^\s*(\/\*|\/\/)#region\b/; + this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/; //prevent naming conflict with any modes that inherit from cstyle and override this (like csharp) this._getFoldWidgetBase = this.getFoldWidget; @@ -69,6 +69,8 @@ oop.inherits(FoldMode, BaseFoldMode); * * @example tripleStarFoldingSection * /*** this folds even though 1 line because it has 3 stars ***[/] + * + * @note the pound symbol for region tags is optional */ this.getFoldWidget = function(session, foldStyle, row) { var line = session.getLine(row); @@ -158,12 +160,16 @@ oop.inherits(FoldMode, BaseFoldMode); return new Range(startRow, startColumn, endRow, session.getLine(endRow).length); }; + /** + * gets comment region block with end region assumed to be start of comment in any cstyle mode or SQL mode (--) which inherits from this. + * There may optionally be a pound symbol before the region/endregion statement + */ this.getCommentRegionBlock = function(session, line, row) { var startColumn = line.search(/\s*$/); var maxRow = session.getLength(); var startRow = row; - var re = /^\s*(?:\/\*|\/\/)#(end)?region\b/; + var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/; var depth = 1; while (++row < maxRow) { line = session.getLine(row); diff --git a/lib/ace/mode/folding/sqlserver.js b/lib/ace/mode/folding/sqlserver.js new file mode 100644 index 00000000..b3fd4e93 --- /dev/null +++ b/lib/ace/mode/folding/sqlserver.js @@ -0,0 +1,111 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Distributed under the BSD license: + * + * Copyright (c) 2010, Ajax.org B.V. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Ajax.org B.V. nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * ***** END LICENSE BLOCK ***** */ + +define(function(require, exports, module) { +"use strict"; + +var oop = require("../../lib/oop"); +var Range = require("../../range").Range; +var BaseFoldMode = require("./cstyle").FoldMode; + +var FoldMode = exports.FoldMode = function() {}; + +oop.inherits(FoldMode, BaseFoldMode); + +(function() { + /** + * Inheriting cstyle folding because it handles the region comment folding + * and special block comment folding appropriately. + * + * Cstyle's getCommentRegionBlock() contains the sql comment characters '--' for end region block. + */ + + this.foldingStartMarker = /(\bCASE\b|\bBEGIN\b)|^\s*(\/\*)/i; + // this.foldingStopMarker = /(\bEND\b)|^[\s\*]*(\*\/)/i; + this.startRegionRe = /^\s*(\/\*|--)#?region\b/; + + this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) { + var line = session.getLine(row); + + if (this.startRegionRe.test(line)) return this.getCommentRegionBlock(session, line, row); + + var match = line.match(this.foldingStartMarker); + if (match) { + var i = match.index; + if (match[1]) return this.getBeginEndBlock(session, row, i, match[1]); + + var range = session.getCommentFoldRange(row, i + match[0].length, 1); + if (range && !range.isMultiLine()) { + if (forceMultiline) { + range = this.getSectionRange(session, row); + } + else if (foldStyle != "all") range = null; + } + + return range; + } + + if (foldStyle === "markbegin") return; + //TODO: add support for end folding markers + return; + }; + + /** + * @returns {range} folding block for sequence that starts with 'CASE' or 'BEGIN' and ends with 'END' + * @param {string} matchSequence - the sequence of charaters that started the fold widget, which should remain visible when the fold widget is folded + */ + this.getBeginEndBlock = function(session, row, column, matchSequence) { + var start = { + row: row, + column: column + matchSequence.length + }; + var maxRow = session.getLength(); + var line; + + var depth = 1; + var re = /(\bCASE\b|\bBEGIN\b)|(\bEND\b)/i; + while (++row < maxRow) { + line = session.getLine(row); + var m = re.exec(line); + if (!m) continue; + if (m[1]) depth++; + else depth--; + + if (!depth) break; + } + var endRow = row; + if (endRow > start.row) { + return new Range(start.row, start.column, endRow, line.length); + } + }; + +}).call(FoldMode.prototype); + +}); diff --git a/lib/ace/mode/sqlserver.js b/lib/ace/mode/sqlserver.js new file mode 100644 index 00000000..0f66c1e5 --- /dev/null +++ b/lib/ace/mode/sqlserver.js @@ -0,0 +1,55 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Distributed under the BSD license: + * + * Copyright (c) 2010, Ajax.org B.V. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Ajax.org B.V. nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * ***** END LICENSE BLOCK ***** */ + +define(function(require, exports, module) { +"use strict"; + +var oop = require("../lib/oop"); +var TextMode = require("./text").Mode; +var SqlServerHighlightRules = require("./sqlserver_highlight_rules").SqlHighlightRules; +var Range = require("../range").Range; +var SqlServerFoldMode = require("./folding/sqlserver").FoldMode; + +var Mode = function() { + this.HighlightRules = SqlServerHighlightRules; + this.foldingRules = new SqlServerFoldMode(); +}; +oop.inherits(Mode, TextMode); + +(function() { + this.lineCommentStart = "--"; + this.blockComment = {start: "/*", end: "*/"}; + + this.$id = "ace/mode/sql"; +}).call(Mode.prototype); + +exports.Mode = Mode; + +}); diff --git a/lib/ace/mode/sqlserver_highlight_rules.js b/lib/ace/mode/sqlserver_highlight_rules.js new file mode 100644 index 00000000..42e193d7 --- /dev/null +++ b/lib/ace/mode/sqlserver_highlight_rules.js @@ -0,0 +1,224 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Distributed under the BSD license: + * + * Copyright (c) 2010, Ajax.org B.V. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Ajax.org B.V. nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * ***** END LICENSE BLOCK ***** */ + +define(function(require, exports, module) { +"use strict"; + +var oop = require("../lib/oop"); +var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules; +var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; + +var SqlServerHighlightRules = function() { + /** + * Transact-SQL Syntax Conventions: https://msdn.microsoft.com/en-us/library/ms177563.aspx + * Goal: make this imitate SSMS (SQL Server Managment Studio) + */ + + // https://msdn.microsoft.com/en-us/library/ms189773.aspx + var logicalOperators = "ALL|AND|ANY|BETWEEN|EXISTS|IN|LIKE|NOT|OR|SOME"; + 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 + + + var builtinFunctions = ( + /* https://msdn.microsoft.com/en-us/library/ms187957.aspx */ + "OPENDATASOURCE|OPENQUERY|OPENROWSET|OPENXML|" + + /* https://msdn.microsoft.com/en-us/library/ms173454.aspx */ + "AVG|CHECKSUM_AGG|COUNT|COUNT_BIG|GROUPING|GROUPING_ID|MAX|MIN|STDEV|STDEVP|SUM|VAR|VARP|" + + /* https://msdn.microsoft.com/en-us/library/ms189798.aspx */ + "DENSE_RANK|NTILE|RANK|ROW_NUMBER" + + /* https://msdn.microsoft.com/en-us/library/ms173823.aspx */ + "@@DATEFIRST|@@DBTS|@@LANGID|@@LANGUAGE|@@LOCK_TIMEOUT|@@MAX_CONNECTIONS|@@MAX_PRECISION|@@NESTLEVEL|@@OPTIONS|@@REMSERVER|@@SERVERNAME|@@SERVICENAME|@@SPID|@@TEXTSIZE|@@VERSION|" + + /* https://msdn.microsoft.com/en-us/library/hh231076.aspx */ + "CAST|CONVERT|PARSE|TRY_CAST|TRY_CONVERT|TRY_PARSE" + + /* https://msdn.microsoft.com/en-us/library/ms186285.aspx */ + "@@CURSOR_ROWS|@@FETCH_STATUS|CURSOR_STATUS|" + + /* https://msdn.microsoft.com/en-us/library/ms186724.aspx */ + "@@DATEFIRST|@@LANGUAGE|CURRENT_TIMESTAMP|DATEADD|DATEDIFF|DATEFROMPARTS|DATENAME|DATEPART|DATETIME2FROMPARTS|DATETIMEFROMPARTS|DATETIMEOFFSETFROMPARTS|DAY|EOMONTH|GETDATE|GETUTCDATE|ISDATE|MONTH|SET DATEFIRST|SET DATEFORMAT|SET LANGUAGE|SMALLDATETIMEFROMPARTS|SP_HELPLANGUAGE|SWITCHOFFSET|SYSDATETIME|SYSDATETIMEOFFSET|SYSUTCDATETIME|TIMEFROMPARTS|TODATETIMEOFFSET|YEAR|" + + /* https://msdn.microsoft.com/en-us/library/hh213226.aspx */ + "CHOOSE|IIF|" + + /* https://msdn.microsoft.com/en-us/library/ms177516.aspx */ + "ABS|ACOS|ASIN|ATAN|ATN2|CEILING|COS|COT|DEGREES|EXP|FLOOR|LOG|LOG10|PI|POWER|RADIANS|RAND|ROUND|SIGN|SIN|SQRT|SQUARE|TAN|" + + /* https://msdn.microsoft.com/en-us/library/ms187812.aspx */ + "@@PROCID|APPLOCK_MODE|APPLOCK_TEST|APP_NAME|ASSEMBLYPROPERTY|COLUMNPROPERTY|COL_LENGTH|COL_NAME|DATABASEPROPERTYEX|DATABASE_PRINCIPAL_ID|DB_ID|DB_NAME|FILEGROUPPROPERTY|FILEGROUP_ID|FILEGROUP_NAME|FILEPROPERTY|FILE_ID|FILE_IDEX|FILE_NAME|FULLTEXTCATALOGPROPERTY|FULLTEXTSERVICEPROPERTY|INDEXKEY_PROPERTY|INDEXPROPERTY|INDEX_COL|OBJECTPROPERTY|OBJECTPROPERTYEX|OBJECT_DEFINITION|OBJECT_ID|OBJECT_NAME|OBJECT_SCHEMA_NAME|ORIGINAL_DB_NAME|PARSENAME|SCHEMA_ID|SCHEMA_NAME|SCOPE_IDENTITY|SERVERPROPERTY|STATS_DATE|TYPEPROPERTY|TYPE_ID|TYPE_NAME|" + + /* https://msdn.microsoft.com/en-us/library/ms186236.aspx */ + "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|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 */ + "@@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" + ); + + + // https://msdn.microsoft.com/en-us/library/ms187752.aspx + var dataTypes = ("BIGINT|BINARY|BIT|CHAR|CURSOR|DATE|DATETIME|DATETIME2|DATETIMEOFFSET|DECIMAL|FLOAT|HIERARCHYID|IMAGE|INTEGER|INT|MONEY|NCHAR|NTEXT|NUMERIC|NVARCHAR|REAL|SMALLDATETIME|SMALLINT|SMALLMONEY|SQL_VARIANT|TABLE|TEXT|TIME|TIMESTAMP|TINYINT|UNIQUEIDENTIFIER|VARBINARY|VARCHAR|XML"); + + + //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 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"; + + + // Microsoft's keyword list is missing a lot of things that are located on various other pages + // 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"; + // https://msdn.microsoft.com/en-us/library/ms173815.aspx + keywords += "|LOOP|HASH|MERGE|REMOTE"; + // https://msdn.microsoft.com/en-us/library/ms175976.aspx + 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 + 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, + "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++) { + 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('|'); + var isolationLevels = "READ UNCOMMITTED|READ COMMITTED|REPEATABLE READ|SNAPSHOP|SERIALIZABLE".split('|'); + for (var i = 0; i < isolationLevels.length; i++) { + setStatements.push('SET TRANSACTION ISOLATION LEVEL ' + isolationLevels[i]); + } + //add set statements to keywordList for completions + for (var i = 0; i < setStatements.length; i++) { + this.$keywordList.push(setStatements[i]); + } + + + this.$rules = { + start: [{ + token: "string.start", + regex: "'", + next: [{ + token: "constant.language.escape", + regex: /\\'/ + }, { + token: "string.end", + next: "start", + regex: "'" + }, { + defaultToken: "string" + }] + }, + DocCommentHighlightRules.getStartRule("doc-start"), { + token: "comment", + regex: "--.*$" + }, { + token: "comment", + start: "/\\*", + end: "\\*/" + }, { + token: "string", // ' string + regex: "'.*?'" + }, { + token: "constant.numeric", // float + regex: "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b" + }, { + token: keywordMapper, + regex: "@{0,2}[a-zA-Z_$][a-zA-Z0-9_$]*\\b" //up to 2 @symbols for some build in functions + }, { + token: "constant.class", + regex: "@@?[a-zA-Z_$][a-zA-Z0-9_$]*\\b" + }, { + //https://msdn.microsoft.com/en-us/library/ms174986.aspx + token: "keyword.operator", + regex: "\\+|\\-|\\/|\\/\\/|%|<@>|@>|<@|&|\\^|~|<|>|<=|=>|==|!=|<>|=|\\*" + }, { + token: "paren.lparen", + regex: "[\\(]" + }, { + token: "paren.rparen", + regex: "[\\)]" + }, { + token: "punctuation", + regex: ",|;" + }, { + token: "text", + regex: "\\s+" + }], + comment: [ + DocCommentHighlightRules.getTagRule(), { + token: "comment", + regex: "\\*\\/", + next: "no_regex" + }, { + defaultToken: "comment", + caseInsensitive: true + }], + }; + + //add each set statment as regex at top of rules so that they are processed first because they require multiple words + //note, this makes the statements not match if they are not upper case.. which is not ideal but I don't know of an easy way to fix this + for (var i = 0; i < setStatements.length; i++) { + var statement = setStatements[i]; + this.$rules.start.unshift({ + token: "set.statement", + regex: statement + }); + } + + this.embedRules(DocCommentHighlightRules, "doc-", [DocCommentHighlightRules.getEndRule("start")]); + + this.normalizeRules(); +}; + +oop.inherits(SqlServerHighlightRules, TextHighlightRules); + +exports.SqlHighlightRules = SqlServerHighlightRules; +}); diff --git a/lib/ace/snippets/sqlserver.js b/lib/ace/snippets/sqlserver.js new file mode 100644 index 00000000..f84694dc --- /dev/null +++ b/lib/ace/snippets/sqlserver.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./sqlserver.snippets"); +exports.scope = "sqlserver"; + +}); diff --git a/lib/ace/snippets/sqlserver.snippets b/lib/ace/snippets/sqlserver.snippets new file mode 100644 index 00000000..51c00ae4 --- /dev/null +++ b/lib/ace/snippets/sqlserver.snippets @@ -0,0 +1,56 @@ +# ISNULL +snippet isnull + ISNULL(${1:check_expression}, ${2:replacement_value}) +# FORMAT +snippet format + FORMAT(${1:value}, ${2:format}) +# CAST +snippet cast + CAST(${1:expression} AS ${2:data_type}) +# CONVERT +snippet convert + CONVERT(${1:data_type}, ${2:expression}) +# DATEPART +snippet datepart + DATEPART(${1:datepart}, ${2:date}) +# DATEDIFF +snippet datediff + DATEDIFF(${1:datepart}, ${2:startdate}, ${3:enddate}) +# DATEADD +snippet dateadd + DATEADD(${1:datepart}, ${2:number}, ${3:date}) +# DATEFROMPARTS +snippet datefromparts + DATEFROMPARTS(${1:year}, ${2:month}, ${3:day}) +# Create Procedure +snippet createproc + -- ============================================= + -- Author: ${1:Author} + -- Create date: ${2:Date} + -- Description: ${3:Description} + -- ============================================= + CREATE PROCEDURE ${4:Procedure_Name} + -- Add the parameters for the stored procedure here + AS + BEGIN + -- SET NOCOUNT ON added to prevent extra result sets from interfering with SELECT statements. + SET NOCOUNT ON; + + END + GO +# Create Scalar Function +snippet createfn + -- ============================================= + -- Author: ${1:Author} + -- Create date: ${2:Date} + -- Description: ${3:Description} + -- ============================================= + CREATE FUNCTION ${4:Scalar_Function_Name} + -- Add the parameters for the function here + RETURNS ${5:Function_Data_Type} + AS + BEGIN + DECLARE @Result ${5:Function_Data_Type} + + END + GO \ No newline at end of file diff --git a/lib/ace/theme/sqlserver.css b/lib/ace/theme/sqlserver.css new file mode 100644 index 00000000..ff6d1e1c --- /dev/null +++ b/lib/ace/theme/sqlserver.css @@ -0,0 +1,171 @@ +.ace_line { + font-family: Consolas; +} + +.ace-sqlserver .ace_gutter { + background: #ebebeb; + color: #333; + overflow: hidden; +} + +.ace-sqlserver .ace_print-margin { + width: 1px; + background: #e8e8e8; +} + +.ace-sqlserver { + background-color: #FFFFFF; + color: black; +} + +.ace-sqlserver .ace_identifier { + color: black; +} + +.ace-sqlserver .ace_keyword { + color: #0000FF; +} + +.ace-sqlserver .ace_numeric { + color: black; +} + +.ace-sqlserver .ace_storage { + color: #11B7BE; +} + +.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: #0000FF; + text-decoration: underline; +} + +.ace-sqlserver .ace_cursor { + color: black; +} + +.ace-sqlserver .ace_invisible { + color: rgb(191, 191, 191); +} + +.ace-sqlserver .ace_constant.ace_buildin { + color: rgb(88, 72, 246); +} + +.ace-sqlserver .ace_constant.ace_language { + color: #979797; +} + +.ace-sqlserver .ace_constant.ace_library { + color: rgb(6, 150, 14); +} + +.ace-sqlserver .ace_invalid { + background-color: rgb(153, 0, 0); + color: white; +} + +.ace-sqlserver .ace_support.ace_function { + color: #FF00FF; +} + +.ace-sqlserver .ace_support.ace_constant { + color: rgb(6, 150, 14); +} + +.ace-sqlserver .ace_class { + color: #008080; +} + +.ace-sqlserver .ace_support.ace_other { + color: #6D79DE; +} + +.ace-sqlserver .ace_variable.ace_parameter { + font-style: italic; + color: #FD971F; +} + +.ace-sqlserver .ace_comment { + color: #008000; +} + +.ace-sqlserver .ace_constant.ace_numeric { + color: black; +} + +.ace-sqlserver .ace_variable { + color: rgb(49, 132, 149); +} + +.ace-sqlserver .ace_xml-pe { + color: rgb(104, 104, 91); +} + +.ace-sqlserver .ace_support.ace_storedprocedure { + color: #800000; +} + +.ace-sqlserver .ace_heading { + color: rgb(12, 7, 255); +} + +.ace-sqlserver .ace_list { + color: rgb(185, 6, 144); +} + +.ace-sqlserver .ace_marker-layer .ace_selection { + background: rgb(181, 213, 255); +} + +.ace-sqlserver .ace_marker-layer .ace_step { + background: rgb(252, 255, 0); +} + +.ace-sqlserver .ace_marker-layer .ace_stack { + background: rgb(164, 229, 101); +} + +.ace-sqlserver .ace_marker-layer .ace_bracket { + margin: -1px 0 0 -1px; + border: 1px solid rgb(192, 192, 192); +} + +.ace-sqlserver .ace_marker-layer .ace_active-line { + background: rgba(0, 0, 0, 0.07); +} + +.ace-sqlserver .ace_gutter-active-line { + background-color: #dcdcdc; +} + +.ace-sqlserver .ace_marker-layer .ace_selected-word { + background: rgb(250, 250, 255); + border: 1px solid rgb(200, 200, 250); +} + +.ace-sqlserver .ace_meta.ace_tag { + color: #0000FF; +} + +.ace-sqlserver .ace_string.ace_regex { + color: #FF0000; +} + +.ace-sqlserver .ace_string { + color: #FF0000; +} + +.ace-sqlserver .ace_entity.ace_other.ace_attribute-name { + color: #994409; +} + +.ace-sqlserver .ace_indent-guide { + background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAACCAYAAACZgbYnAAAAE0lEQVQImWP4////f4bLly//BwAmVgd1/w11/gAAAABJRU5ErkJggg==") right repeat-y; +} diff --git a/lib/ace/theme/sqlserver.js b/lib/ace/theme/sqlserver.js new file mode 100644 index 00000000..ab657483 --- /dev/null +++ b/lib/ace/theme/sqlserver.js @@ -0,0 +1,39 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Distributed under the BSD license: + * + * Copyright (c) 2010, Ajax.org B.V. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Ajax.org B.V. nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * ***** END LICENSE BLOCK ***** */ + +define(function(require, exports, module) { + +exports.isDark = false; +exports.cssClass = "ace-sqlserver"; +exports.cssText = require("../requirejs/text!./sqlserver.css"); + +var dom = require("../lib/dom"); +dom.importCssString(exports.cssText, exports.cssClass); +});