Merge pull request #1715 from ajaxorg/velocity_snippets

Support loading snippets for mixed modes
This commit is contained in:
Lennart Kats 2013-12-25 02:04:31 -08:00
commit eda5eaba39
103 changed files with 190 additions and 39 deletions

View file

@ -41,6 +41,9 @@ var ACE_HOME = __dirname;
var BUILD_DIR = ACE_HOME + "/build";
function main(args) {
if (args.indexOf("updateModes") !== -1) {
return updateModes();
}
var type = "minimal";
args = args.map(function(x) {
if (x[0] == "-" && x[1] != "-")
@ -258,10 +261,13 @@ function jsFileList(path, filter) {
}
function workers(path) {
return jsFileList(path).map(function(x) {
if (x.slice(-7) == "_worker")
return x.slice(0, -7);
}).filter(function(x) { return !!x; });
return jsFileList(path).map(function(x) {
if (x.slice(-7) == "_worker")
return x.slice(0, -7);
}).filter(function(x) { return !!x; });
}
function modeList() {
return jsFileList("lib/ace/mode", /_highlight_rules|_test|_worker|xml_util|_outdent|behaviour|completions/)
}
function addSuffix(options) {
@ -317,7 +323,7 @@ var buildAce = function(options) {
noconflict: false,
suffix: null,
name: "ace",
modes: jsFileList("lib/ace/mode", /_highlight_rules|_test|_worker|xml_util|_outdent|behaviour|completions/),
modes: modeList(),
themes: jsFileList("lib/ace/theme"),
extensions: jsFileList("lib/ace/ext"),
workers: workers("lib/ace/mode"),
@ -545,22 +551,25 @@ function generateThemesModule(themes) {
}
function inlineTextModules(text) {
var lastDep = "";
return text.replace(/, *['"]ace\/requirejs\/text!(.*?)['"]|= *require\(['"](?:ace|[.\/]+)\/requirejs\/text!(.*?)['"]\)/g, function(_, dep, call) {
var deps = [];
return text.replace(/, *['"]ace\/requirejs\/text!(.*?)['"]| require\(['"](?:ace|[.\/]+)\/requirejs\/text!(.*?)['"]\)/g, function(_, dep, call) {
if (dep) {
if (!lastDep) {
lastDep = dep;
return "";
}
deps.push(dep);
return "";
} else if (call) {
call = textModules[lastDep];
delete textModules[lastDep];
lastDep = "";
deps.some(function(d) {
if (d.split("/").pop() == call.split("/").pop()) {
dep = d;
return true;
}
});
call = textModules[dep];
// if (deps.length > 1)
// console.log(call.length)
if (call)
return "= " + call;
return " " + call;
}
console.log(dep, lastDep, call);
throw "inlining of multiple text modules is not supported";
});
}
@ -657,6 +666,18 @@ function exportAce(ns, module, requireBase) {
};
}
function updateModes() {
modeList().forEach(function(m) {
var filepath = __dirname + "/lib/ace/mode/" + m + ".js"
var source = fs.readFileSync(filepath, "utf8");
if (!/this.\$id\s*=\s*"/.test(source))
source = source.replace(/\n([ \t]*)(\}\).call\(\w*Mode.prototype\))/, '\n$1 this.$id = "";\n$1$2');
source = source.replace(/(this.\$id\s*=\s*)"[^"]*"/, '$1"ace/mode/' + m + '"');
fs.writeFileSync(filepath, source, "utf8")
})
}
if (!module.parent)
main(process.argv);
else

View file

@ -46,10 +46,9 @@ var keyWordCompleter = {
var snippetCompleter = {
getCompletions: function(editor, session, pos, prefix, callback) {
var scope = snippetManager.$getScope(editor);
var snippetMap = snippetManager.snippetMap;
var completions = [];
[scope, "_"].forEach(function(scope) {
snippetManager.getActiveScopes(editor).forEach(function(scope) {
var snippets = snippetMap[scope] || [];
for (var i = snippets.length; i--;) {
var s = snippets[i];
@ -80,22 +79,39 @@ var expandSnippet = {
editor.execCommand("indent");
},
bindKey: "tab"
}
};
var onChangeMode = function(e, editor) {
var mode = editor.session.$mode;
var id = mode.$id
if (!snippetManager.files) snippetManager.files = {};
if (id && !snippetManager.files[id]) {
var snippetFilePath = id.replace("mode", "snippets");
config.loadModule(snippetFilePath, function(m) {
if (m) {
snippetManager.files[id] = m;
m.snippets = snippetManager.parseSnippetFile(m.snippetText);
snippetManager.register(m.snippets, m.scope);
loadSnippetsForMode(editor.session.$mode);
};
var loadSnippetsForMode = function(mode) {
var id = mode.$id;
if (!snippetManager.files)
snippetManager.files = {};
loadSnippetFile(id);
if (mode.modes)
mode.modes.forEach(loadSnippetsForMode);
};
var loadSnippetFile = function(id) {
if (!id || snippetManager.files[id])
return;
var snippetFilePath = id.replace("mode", "snippets");
snippetManager.files[id] = {};
config.loadModule(snippetFilePath, function(m) {
if (m) {
snippetManager.files[id] = m;
m.snippets = snippetManager.parseSnippetFile(m.snippetText);
snippetManager.register(m.snippets, m.scope);
if (m.includeScopes) {
snippetManager.snippetMap[m.scope].includeScopes = m.includeScopes;
m.includeScopes.forEach(function(x) {
loadSnippetFile("ace/mode/" + x);
});
}
});
}
}
});
};
var Editor = require("../editor").Editor;
@ -103,7 +119,7 @@ require("../config").defineOptions(Editor.prototype, "editor", {
enableBasicAutocompletion: {
set: function(val) {
if (val) {
this.completers = completers
this.completers = completers;
this.commands.addCommand(Autocomplete.startCommand);
} else {
this.commands.removeCommand(Autocomplete.startCommand);
@ -116,7 +132,7 @@ require("../config").defineOptions(Editor.prototype, "editor", {
if (val) {
this.commands.addCommand(expandSnippet);
this.on("changeMode", onChangeMode);
onChangeMode(null, this)
onChangeMode(null, this);
} else {
this.commands.removeCommand(expandSnippet);
this.off("changeMode", onChangeMode);

View file

@ -70,6 +70,7 @@ oop.inherits(Mode, TextMode);
}
};
this.$id = "ace/mode/abap";
}).call(Mode.prototype);
exports.Mode = Mode;

View file

@ -56,6 +56,7 @@ oop.inherits(Mode, TextMode);
(function() {
this.lineCommentStart = "//";
this.blockComment = {start: "/*", end: "*/"};
this.$id = "ace/mode/actionscript";
}).call(Mode.prototype);
exports.Mode = Mode;

View file

@ -46,6 +46,7 @@ oop.inherits(Mode, TextMode);
this.lineCommentStart = "--";
this.$id = "ace/mode/ada";
}).call(Mode.prototype);
exports.Mode = Mode;

View file

@ -58,6 +58,7 @@ oop.inherits(Mode, TextMode);
return this.$getIndent(line);
}
};
this.$id = "ace/mode/asciidoc";
}).call(Mode.prototype);
exports.Mode = Mode;

View file

@ -50,6 +50,7 @@ oop.inherits(Mode, TextMode);
(function() {
this.lineCommentStart = ";";
this.$id = "ace/mode/assembly_x86";
}).call(Mode.prototype);
exports.Mode = Mode;

View file

@ -56,6 +56,7 @@ oop.inherits(Mode, TextMode);
(function() {
this.lineCommentStart = "/\\*";
this.blockComment = {start: "/*", end: "*/"};
this.$id = "ace/mode/autohotkey";
}).call(Mode.prototype);
exports.Mode = Mode;

View file

@ -55,6 +55,7 @@ oop.inherits(Mode, TextMode);
(function() {
this.lineCommentStart = "::";
this.blockComment = "";
this.$id = "ace/mode/batchfile";
}).call(Mode.prototype);
exports.Mode = Mode;

View file

@ -60,6 +60,7 @@ oop.inherits(Mode, TextMode);
this.$outdent.autoOutdent(doc, row);
};
this.$id = "ace/mode/c9search";
}).call(Mode.prototype);
exports.Mode = Mode;

View file

@ -95,6 +95,7 @@ oop.inherits(Mode, TextMode);
this.$outdent.autoOutdent(doc, row);
};
this.$id = "ace/mode/c_cpp";
}).call(Mode.prototype);
exports.Mode = Mode;

View file

@ -80,6 +80,7 @@ oop.inherits(Mode, TextMode);
this.$outdent.autoOutdent(doc, row);
};
this.$id = "ace/mode/clojure";
}).call(Mode.prototype);
exports.Mode = Mode;

View file

@ -46,6 +46,7 @@ oop.inherits(Mode, TextMode);
this.lineCommentStart = "*";
this.$id = "ace/mode/cobol";
}).call(Mode.prototype);
exports.Mode = Mode;

View file

@ -107,6 +107,7 @@ oop.inherits(Mode, TextMode);
return worker;
};
this.$id = "ace/mode/coffee";
}).call(Mode.prototype);
exports.Mode = Mode;

View file

@ -56,6 +56,7 @@ oop.inherits(Mode, XmlMode);
return this.$getIndent(line);
};
this.$id = "ace/mode/coldfusion";
}).call(Mode.prototype);
exports.Mode = Mode;

View file

@ -55,6 +55,7 @@ oop.inherits(Mode, TextMode);
return null;
};
this.$id = "ace/mode/csharp";
}).call(Mode.prototype);
exports.Mode = Mode;

View file

@ -93,6 +93,7 @@ oop.inherits(Mode, TextMode);
return worker;
};
this.$id = "ace/mode/css";
}).call(Mode.prototype);
exports.Mode = Mode;

View file

@ -57,6 +57,7 @@ var Mode = function() {
oop.inherits(Mode, HtmlMode);
(function() {
this.$id = "ace/mode/curly";
}).call(Mode.prototype);
exports.Mode = Mode;

View file

@ -50,6 +50,7 @@ oop.inherits(Mode, TextMode);
(function() {
this.lineCommentStart = "/\\+";
this.blockComment = {start: "/*", end: "*/"};
this.$id = "ace/mode/d";
}).call(Mode.prototype);
exports.Mode = Mode;

View file

@ -56,6 +56,7 @@ oop.inherits(Mode, CMode);
(function() {
this.lineCommentStart = "//";
this.blockComment = {start: "/*", end: "*/"};
this.$id = "ace/mode/dart";
}).call(Mode.prototype);
exports.Mode = Mode;

Some files were not shown because too many files have changed in this diff Show more