Skip to content

Commit e9c52f3

Browse files
tugrulelmasmarijnh
authored andcommitted
[sql mode] Add text/x-mssql dialect and ssms theme
1 parent e8fa972 commit e9c52f3

2 files changed

Lines changed: 34 additions & 9 deletions

File tree

mode/sql/sql.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ CodeMirror.defineMode("sql", function(config, parserConfig) {
2222
support = parserConfig.support || {},
2323
hooks = parserConfig.hooks || {},
2424
dateSQL = parserConfig.dateSQL || {"date" : true, "time" : true, "timestamp" : true},
25-
backslashStringEscapes = parserConfig.backslashStringEscapes !== false
25+
backslashStringEscapes = parserConfig.backslashStringEscapes !== false,
26+
brackets = parserConfig.brackets || /^[\{}\(\)\[\]]/,
27+
punctuation = parserConfig.punctuation || /^[;.,:]/
2628

2729
function tokenBase(stream, state) {
2830
var ch = stream.next();
@@ -65,9 +67,6 @@ CodeMirror.defineMode("sql", function(config, parserConfig) {
6567
// charset casting: _utf8'str', N'str', n'str'
6668
// ref: http://dev.mysql.com/doc/refman/5.5/en/string-literals.html
6769
return "keyword";
68-
} else if (/^[\(\),\;\[\]]/.test(ch)) {
69-
// no highlighting
70-
return null;
7170
} else if (support.commentSlashSlash && ch == "/" && stream.eat("/")) {
7271
// 1-line comment
7372
stream.skipToEnd();
@@ -96,7 +95,15 @@ CodeMirror.defineMode("sql", function(config, parserConfig) {
9695
} else if (operatorChars.test(ch)) {
9796
// operators
9897
stream.eatWhile(operatorChars);
99-
return null;
98+
return "operator";
99+
} else if (brackets.test(ch)) {
100+
// brackets
101+
stream.eatWhile(brackets);
102+
return "bracket";
103+
} else if (punctuation.test(ch)) {
104+
// punctuation
105+
stream.eatWhile(punctuation);
106+
return "punctuation";
100107
} else if (ch == '{' &&
101108
(stream.match(/^( )*(d|D|t|T|ts|TS)( )*'[^']*'( )*}/) || stream.match(/^( )*(d|D|t|T|ts|TS)( )*"[^"]*"( )*}/))) {
102109
// dates (weird ODBC syntax)
@@ -289,11 +296,13 @@ CodeMirror.defineMode("sql", function(config, parserConfig) {
289296

290297
CodeMirror.defineMIME("text/x-mssql", {
291298
name: "sql",
292-
client: set("charset clear connect edit ego exit go help nopager notee nowarning pager print prompt quit rehash source status system tee"),
293-
keywords: set(sqlKeywords + "begin trigger proc view index for add constraint key primary foreign collate clustered nonclustered declare exec"),
299+
client: set("$partition binary_checksum checksum connectionproperty context_info current_request_id error_line error_message error_number error_procedure error_severity error_state formatmessage get_filestream_transaction_context getansinull host_id host_name isnull isnumeric min_active_rowversion newid newsequentialid rowcount_big xact_state object_id"),
300+
keywords: set(sqlKeywords + "begin trigger proc view index for add constraint key primary foreign collate clustered nonclustered declare exec go if use index holdlock nolock nowait paglock readcommitted readcommittedlock readpast readuncommitted repeatableread rowlock serializable snapshot tablock tablockx updlock with"),
294301
builtin: set("bigint numeric bit smallint decimal smallmoney int tinyint money float real char varchar text nchar nvarchar ntext binary varbinary image cursor timestamp hierarchyid uniqueidentifier sql_variant xml table "),
295-
atoms: set("false true null unknown"),
296-
operatorChars: /^[*+\-%<>!=]/,
302+
atoms: set("is not null like and or in left right between inner outer join all any some cross unpivot pivot exists"),
303+
operatorChars: /^[*+\-%<>!=^\&|\/]/,
304+
brackets: /^[\{}\(\)]/,
305+
punctuation: /^[;.,:/]/,
297306
backslashStringEscapes: false,
298307
dateSQL: set("date datetimeoffset datetime2 smalldatetime datetime time"),
299308
hooks: {

theme/ssms.css

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.cm-s-ssms span.cm-keyword { color: blue; }
2+
.cm-s-ssms span.cm-comment { color: darkgreen; }
3+
.cm-s-ssms span.cm-string { color: red; }
4+
.cm-s-ssms span.cm-def { color: black; }
5+
.cm-s-ssms span.cm-variable { color: black; }
6+
.cm-s-ssms span.cm-variable-2 { color: black; }
7+
.cm-s-ssms span.cm-atom { color: darkgray; }
8+
.cm-s-ssms .CodeMirror-linenumber { color: teal; }
9+
.cm-s-ssms .CodeMirror-activeline-background { background: #ffffff; }
10+
.cm-s-ssms span.cm-string-2 { color: #FF00FF; }
11+
.cm-s-ssms span.cm-operator,
12+
.cm-s-ssms span.cm-bracket,
13+
.cm-s-ssms span.cm-punctuation { color: darkgray; }
14+
.cm-s-ssms .CodeMirror-gutters { border-right: 3px solid #ffee62; background-color: #ffffff; }
15+
.cm-s-ssms div.CodeMirror-selected { background: #ADD6FF; }
16+

0 commit comments

Comments
 (0)