better completions, no unneeded string rule
This commit is contained in:
parent
67c7da75b6
commit
82453d884b
2 changed files with 33 additions and 50 deletions
|
|
@ -48,30 +48,10 @@ oop.inherits(Mode, TextMode);
|
||||||
this.blockComment = {start: "/*", end: "*/"};
|
this.blockComment = {start: "/*", end: "*/"};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Override keyword completions to ensure proper case for completions
|
* Override keyword completions using list created in highlight rules
|
||||||
* and use smart meta tags instead of 'keyword' for all completions.
|
|
||||||
*/
|
*/
|
||||||
this.getCompletions = function(state, session, pos, prefix) {
|
this.getCompletions = function(state, session, pos, prefix) {
|
||||||
var keywords = this.$keywordList || this.$createKeywordList();
|
return session.$mode.$highlightRules.completions;
|
||||||
var types = session.$mode.$highlightRules.keywordTypes;
|
|
||||||
|
|
||||||
return keywords.map(function(word) {
|
|
||||||
var meta = 'keyword';
|
|
||||||
if (types.builtInStoredProcedures.indexOf(word) !== -1) meta = "procedure";
|
|
||||||
else {
|
|
||||||
word = word.toUpperCase(); //all others are upper case
|
|
||||||
if (types.builtinFunctions.indexOf(word) !== -1) meta = "function";
|
|
||||||
else if (types.dataTypes.indexOf(word) !== -1) meta = "type";
|
|
||||||
else if (types.setStatements.indexOf(word) !== -1) meta = "statement";
|
|
||||||
else if (types.logicalOperators.indexOf(word) !== -1) meta = "operator";
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
name: word,
|
|
||||||
value: word,
|
|
||||||
score: 0,
|
|
||||||
meta: meta
|
|
||||||
};
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.$id = "ace/mode/sql";
|
this.$id = "ace/mode/sql";
|
||||||
|
|
|
||||||
|
|
@ -129,10 +129,6 @@ var SqlServerHighlightRules = function() {
|
||||||
for (var i = 0; i < isolationLevels.length; i++) {
|
for (var i = 0; i < isolationLevels.length; i++) {
|
||||||
setStatements.push('SET TRANSACTION ISOLATION LEVEL ' + isolationLevels[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 = {
|
this.$rules = {
|
||||||
|
|
@ -157,9 +153,6 @@ var SqlServerHighlightRules = function() {
|
||||||
token: "comment",
|
token: "comment",
|
||||||
start: "/\\*",
|
start: "/\\*",
|
||||||
end: "\\*/"
|
end: "\\*/"
|
||||||
}, {
|
|
||||||
token: "string", // ' string
|
|
||||||
regex: "'.*?'"
|
|
||||||
}, {
|
}, {
|
||||||
token: "constant.numeric", // float
|
token: "constant.numeric", // float
|
||||||
regex: "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
|
regex: "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
|
||||||
|
|
@ -198,28 +191,38 @@ var SqlServerHighlightRules = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
//add each set statment as regex at top of rules so that they are processed first because they require multiple words
|
//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
|
//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++) {
|
for (var i = 0; i < setStatements.length; i++) {
|
||||||
var statement = setStatements[i];
|
|
||||||
this.$rules.start.unshift({
|
this.$rules.start.unshift({
|
||||||
token: "set.statement",
|
token: "set.statement",
|
||||||
regex: statement
|
regex: setStatements[i]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
this.embedRules(DocCommentHighlightRules, "doc-", [DocCommentHighlightRules.getEndRule("start")]);
|
this.embedRules(DocCommentHighlightRules, "doc-", [DocCommentHighlightRules.getEndRule("start")]);
|
||||||
|
|
||||||
this.normalizeRules();
|
this.normalizeRules();
|
||||||
|
|
||||||
// export types for overriding get completions
|
|
||||||
this.keywordTypes = {
|
|
||||||
builtInStoredProcedures: builtInStoredProcedures.split('|'),
|
|
||||||
logicalOperators: logicalOperators.split('|'),
|
|
||||||
builtinFunctions: builtinFunctions.split('|'),
|
|
||||||
dataTypes: dataTypes.split('|'),
|
|
||||||
setStatements: setStatements,
|
|
||||||
};
|
|
||||||
|
|
||||||
|
//prepare custom keyword completions used by mode to override default completor
|
||||||
|
//this allows for custom 'meta' and proper case of completions
|
||||||
|
var completions = [];
|
||||||
|
var addCompletions = function(arr, meta) {
|
||||||
|
arr.forEach(function(v) {
|
||||||
|
completions.push({
|
||||||
|
name: v,
|
||||||
|
value: v,
|
||||||
|
score: 0,
|
||||||
|
meta: meta,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
addCompletions(builtInStoredProcedures.split('|'), 'procedure');
|
||||||
|
addCompletions(logicalOperators.split('|'), 'operator');
|
||||||
|
addCompletions(builtinFunctions.split('|'), 'function');
|
||||||
|
addCompletions(dataTypes.split('|'), 'type');
|
||||||
|
addCompletions(setStatements, 'statement');
|
||||||
|
|
||||||
|
this.completions = completions;
|
||||||
};
|
};
|
||||||
|
|
||||||
oop.inherits(SqlServerHighlightRules, TextHighlightRules);
|
oop.inherits(SqlServerHighlightRules, TextHighlightRules);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue