better completions, no unneeded string rule

This commit is contained in:
sevin7676 2015-04-22 05:28:31 -04:00
commit 82453d884b
2 changed files with 33 additions and 50 deletions

View file

@ -48,30 +48,10 @@ oop.inherits(Mode, TextMode);
this.blockComment = {start: "/*", end: "*/"};
/**
* Override keyword completions to ensure proper case for completions
* and use smart meta tags instead of 'keyword' for all completions.
* Override keyword completions using list created in highlight rules
*/
this.getCompletions = function(state, session, pos, prefix) {
var keywords = this.$keywordList || this.$createKeywordList();
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
};
});
return session.$mode.$highlightRules.completions;
};
this.$id = "ace/mode/sql";

View file

@ -129,10 +129,6 @@ var SqlServerHighlightRules = function() {
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 = {
@ -157,9 +153,6 @@ var SqlServerHighlightRules = function() {
token: "comment",
start: "/\\*",
end: "\\*/"
}, {
token: "string", // ' string
regex: "'.*?'"
}, {
token: "constant.numeric", // float
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
//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++) {
var statement = setStatements[i];
this.$rules.start.unshift({
token: "set.statement",
regex: statement
regex: setStatements[i]
});
}
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,
};
//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);