-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SQL Server typos and keyword completion modifier #2460
Changes from 10 commits
ee90854
cf0c81a
27284cd
961f8c4
1027dce
1ec6eb7
e58fa3e
68d531e
662cd11
67c7da7
82453d8
87044e8
2d7ebc3
5a3bf25
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,30 +106,22 @@ 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, | ||
"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('|'); | ||
|
@@ -147,7 +141,7 @@ var SqlServerHighlightRules = function() { | |
regex: "'", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like the |
||
next: [{ | ||
token: "constant.language.escape", | ||
regex: /\\'/ | ||
regex: /''/ | ||
}, { | ||
token: "string.end", | ||
next: "start", | ||
|
@@ -171,7 +165,7 @@ var SqlServerHighlightRules = function() { | |
regex: "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b" | ||
}, { | ||
token: keywordMapper, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this was the unnecessary rule you were referring to, correct? I think I copied that rule from somewhere else |
||
regex: "@{0,2}[a-zA-Z_$][a-zA-Z0-9_$]*\\b" //up to 2 @symbols for some build in functions | ||
regex: "@{0,2}[a-zA-Z_$][a-zA-Z0-9_$]*\\b" //up to 2 @symbols for some built in functions | ||
}, { | ||
token: "constant.class", | ||
regex: "@@?[a-zA-Z_$][a-zA-Z0-9_$]*\\b" | ||
|
@@ -216,6 +210,16 @@ var SqlServerHighlightRules = function() { | |
this.embedRules(DocCommentHighlightRules, "doc-", [DocCommentHighlightRules.getEndRule("start")]); | ||
|
||
this.normalizeRules(); | ||
|
||
// export types for overriding get completions | ||
this.keywordTypes = { | ||
builtInStoredProcedures: builtInStoredProcedures.split('|'), | ||
logicalOperators: logicalOperators.split('|'), | ||
builtinFunctions: builtinFunctions.split('|'), | ||
dataTypes: dataTypes.split('|'), | ||
setStatements: setStatements, | ||
}; | ||
|
||
}; | ||
|
||
oop.inherits(SqlServerHighlightRules, TextHighlightRules); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we just use types skipping keywordList entirely?
keywordList removes some information that highlighter doesn't need and here we are restoring that using slow indexOf in a large array