Skip to content

Commit

Permalink
Merge pull request #1189 from ajaxorg/feature/codecomplete
Browse files Browse the repository at this point in the history
Implement basic code completion
  • Loading branch information
lennartcl committed Jun 11, 2013
2 parents 89c4226 + db1118c commit fa13f37
Show file tree
Hide file tree
Showing 215 changed files with 1,725 additions and 78 deletions.
37 changes: 31 additions & 6 deletions Makefile.dryice.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ function ace() {
source: ACE_HOME + "/ChangeLog.txt",
dest: BUILD_DIR + "/ChangeLog.txt"
});

return project;
}

Expand Down Expand Up @@ -211,7 +211,7 @@ function demo(project) {
});

var demo = copy.createDataObject();

project.assumeAllFilesLoaded();
copy({
source: [{
Expand Down Expand Up @@ -309,7 +309,7 @@ var buildAce = function(options) {
for(var key in defaults)
if (!options.hasOwnProperty(key))
options[key] = defaults[key];

generateThemesModule(options.themes);

addSuffix(options);
Expand All @@ -334,7 +334,7 @@ var buildAce = function(options) {
filter: [ copy.filter.moduleDefines ],
dest: ace
});

if (options.coreOnly)
return project;

Expand All @@ -349,6 +349,7 @@ var buildAce = function(options) {
project.assumeAllFilesLoaded();
options.modes.forEach(function(mode) {
console.log("mode " + mode);
addSnippetFile(mode, project, targetDir, options);
copy({
source: [{
project: cloneProject(project),
Expand Down Expand Up @@ -441,7 +442,7 @@ var buildAce = function(options) {
dest: BUILD_DIR + '/ace-min.js'
});
}

return project;
};

Expand All @@ -460,6 +461,30 @@ var buildAce = function(fn) {
}
}(buildAce);

var addSnippetFile = function(modeName, project, targetDir, options) {
var snippetFilePath = ACE_HOME + "/lib/ace/snippets/" + modeName;
if (!fs.existsSync(snippetFilePath + ".js")) {
copy({
source: ACE_HOME + "/tool/snippets.tmpl.js",
dest: snippetFilePath + ".js",
filter: [
function(t) {return t.replace(/%modeName%/g, modeName);}
]
});
}
if (!fs.existsSync(snippetFilePath + ".snippets")) {
fs.writeFileSync(snippetFilePath + ".snippets", "")
}
copy({
source: [{
project: cloneProject(project),
require: [ 'ace/snippets/' + modeName ]
}],
filter: getWriteFilters(options, "mode"),
dest: targetDir + "/snippets/" + modeName + ".js"
});
}

var textModules = {}
var detectTextModules = function(input, source) {
if (!source)
Expand All @@ -469,7 +494,7 @@ var detectTextModules = function(input, source) {
input = input.toString();

var module = source.isLocation ? source.path : source;

input = input.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
if (/\.css$/.test(module)) {
// remove unnecessary whitespace from css
Expand Down
51 changes: 25 additions & 26 deletions demo/kitchen-sink/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ env.editor.commands.addCommands([{
bindKey: "ctrl+enter",
exec: function(editor) {
try {
var r = eval(editor.getCopyText()||editor.getValue());
var r = window.eval(editor.getCopyText()||editor.getValue());
} catch(e) {
r = e;
}
Expand Down Expand Up @@ -196,7 +196,7 @@ commands.addCommand({
exec: function() {alert("Fake Save File");}
});

var keybindings = {
var keybindings = {
ace: null, // Null = use "default" keymapping
vim: require("ace/keyboard/vim").handler,
emacs: "ace/keyboard/emacs",
Expand Down Expand Up @@ -431,7 +431,7 @@ bindDropdown("split", function(value) {
sp.setSplits(1);
} else {
var newEditor = (sp.getSplits() == 1);
sp.setOrientation(value == "below" ? sp.BELOW : sp.BESIDE);
sp.setOrientation(value == "below" ? sp.BELOW : sp.BESIDE);
sp.setSplits(2);

if (newEditor) {
Expand Down Expand Up @@ -517,17 +517,9 @@ net.loadScript("https://rawgithub.com/nightwing/emmet-core/master/emmet.js", fun
})


require("ace/placeholder").PlaceHolder;
// require("ace/placeholder").PlaceHolder;

var snippetManager = require("ace/snippets").snippetManager
var jsSnippets = require("ace/snippets/javascript");
window.snippetManager = snippetManager
saveSnippets()

function saveSnippets() {
jsSnippets.snippets = snippetManager.parseSnippetFile(jsSnippets.snippetText);
snippetManager.register(jsSnippets.snippets, "javascript")
}
var snippetManager = require("ace/snippets").snippetManager;

env.editSnippets = function() {
var sp = env.split;
Expand All @@ -538,25 +530,32 @@ env.editSnippets = function() {
sp.setSplits(1);
sp.setSplits(2);
sp.setOrientation(sp.BESIDE);
var editor = sp.$editors[1]
if (!env.snippetSession) {
var file = jsSnippets.snippetText;
env.snippetSession = doclist.initDoc(file, "", {});
env.snippetSession.setMode("ace/mode/tmsnippet");
env.snippetSession.setUseSoftTabs(false);
var editor = sp.$editors[1];
var id = sp.$editors[0].session.$mode.$id || "";
var m = snippetManager.files[id];
if (!doclist["snippets/" + id]) {
var text = m.snippetText;
var s = doclist.initDoc(text, "", {});
s.setMode("ace/mode/snippets");
doclist["snippets/" + id] = s
}
editor.on("blur", function() {
jsSnippets.snippetText = editor.getValue();
saveSnippets();
m.snippetText = editor.getValue();
snippetManager.unregister(m.snippets);
m.snippets = snippetManager.parseSnippetFile(m.snippetText);
snippetManager.register(m.snippets);
})
sp.$editors[0].once("changeMode", function() {
sp.setSplits(1);
})
editor.setSession(env.snippetSession, 1);
editor.setSession(doclist["snippets/" + id], 1);
editor.focus();
}

ace.commands.bindKey("Tab", function(editor) {
var success = snippetManager.expandWithTab(editor);
if (!success)
editor.execCommand("indent");
require("ace/ext/language_tools");
env.editor.setOptions({
enableBasicAutocompletion: true,
enableSnippets: true
})

});

0 comments on commit fa13f37

Please sign in to comment.