diff --git a/examples/org.codingpark.piraterobot.play.web/src-js/org/codingpark/piraterobot/play/web/Play.js b/examples/org.codingpark.piraterobot.play.web/src-js/org/codingpark/piraterobot/play/web/Play.js index 5d9a3d8..6722076 100644 --- a/examples/org.codingpark.piraterobot.play.web/src-js/org/codingpark/piraterobot/play/web/Play.js +++ b/examples/org.codingpark.piraterobot.play.web/src-js/org/codingpark/piraterobot/play/web/Play.js @@ -1,5 +1,5 @@ /** - * @Generated by DSLFORGE + * @Generated by DSL Forge */ //minify using as YUI Compressor, Google Closure Compiler, or JSMin. (function() { @@ -95,7 +95,7 @@ } else { //Compute worker's http URL var filePath = 'rwt-resources/src-js/org/dslforge/styledtext/global-index.js'; - var httpURL = computeWorkerPath(filePath); + var httpURL = this.computeWorkerPath(filePath); var worker = this.worker = new SharedWorker(httpURL); if (this.ready) { editor.on("change", function(event) { @@ -179,23 +179,7 @@ }, onCompletionRequest : function(pos, prefix, callback) { - if (this.isFocused) { - var remoteObject = rap.getRemoteObject(this); - if (remoteObject) { - remoteObject.call("getProposals", { value : this.editor.getValue(), pos : pos, prefix : prefix}); - } - var proposals = this.proposals==null?[":"]:this.proposals; - var wordList = Object.keys(proposals); - callback(null, wordList.map(function(word) { - return { - iconClass: " " + typeToIcon(proposals[word].split(":")[1]), - name: word, - value: proposals[word].split(":")[0], - score: 1, - meta: "[" + proposals[word].split(":")[1] + "]" - }; - })); - } + this.base(arguments, pos, prefix, callback); }, setProposals : function(proposals) { @@ -228,26 +212,4 @@ } }); - var computeWorkerPath = function (path) { - path = path.replace(/^[a-z]+:\/\/[^\/]+/, ""); - path = location.protocol + "//" + location.host - + (path.charAt(0) == "/" ? "" : location.pathname.replace(/\/[^\/]*$/, "")) - + "/" + path.replace(/^[\/]+/, ""); - return path; - }; - - var typeToIcon = function(type) { - var cls = "ace-"; - var suffix; - if (type == "?") suffix = "unknown"; - else if (type == "keyword") suffix = type; - else if (type == "identifier") suffix = type; - else if (type == "snippet") suffix = "snippet"; - else if (type == "number" || type == "string" || type == "bool") suffix = type; - else if (/^fn\(/.test(type)) suffix = "fn"; - else if (/^\[/.test(type)) suffix = "array"; - else suffix = "object"; - return cls + "completion " + cls + "completion-" + suffix; - }; - }()); diff --git a/examples/org.eclipse.sphinx.examples.xtext.hummingbird.web/src-js/org/eclipse/sphinx/examples/xtext/hummingbird/web/Hummingbird.js b/examples/org.eclipse.sphinx.examples.xtext.hummingbird.web/src-js/org/eclipse/sphinx/examples/xtext/hummingbird/web/Hummingbird.js index 4888a4a..9eb4c37 100644 --- a/examples/org.eclipse.sphinx.examples.xtext.hummingbird.web/src-js/org/eclipse/sphinx/examples/xtext/hummingbird/web/Hummingbird.js +++ b/examples/org.eclipse.sphinx.examples.xtext.hummingbird.web/src-js/org/eclipse/sphinx/examples/xtext/hummingbird/web/Hummingbird.js @@ -1,5 +1,5 @@ /** - * @Generated by DSLFORGE + * @Generated by DSL Forge */ //minify using as YUI Compressor, Google Closure Compiler, or JSMin. (function() { @@ -95,7 +95,7 @@ } else { //Compute worker's http URL var filePath = 'rwt-resources/src-js/org/dslforge/styledtext/global-index.js'; - var httpURL = computeWorkerPath(filePath); + var httpURL = this.computeWorkerPath(filePath); var worker = this.worker = new SharedWorker(httpURL); if (this.ready) { editor.on("change", function(event) { @@ -179,23 +179,7 @@ }, onCompletionRequest : function(pos, prefix, callback) { - if (this.isFocused) { - var remoteObject = rap.getRemoteObject(this); - if (remoteObject) { - remoteObject.call("getProposals", { value : this.editor.getValue(), pos : pos, prefix : prefix}); - } - var proposals = this.proposals==null?[":"]:this.proposals; - var wordList = Object.keys(proposals); - callback(null, wordList.map(function(word) { - return { - iconClass: " " + typeToIcon(proposals[word].split(":")[1]), - name: word, - value: proposals[word].split(":")[0], - score: 1, - meta: "[" + proposals[word].split(":")[1] + "]" - }; - })); - } + this.base(arguments, pos, prefix, callback); }, setProposals : function(proposals) { @@ -228,26 +212,4 @@ } }); - var computeWorkerPath = function (path) { - path = path.replace(/^[a-z]+:\/\/[^\/]+/, ""); - path = location.protocol + "//" + location.host - + (path.charAt(0) == "/" ? "" : location.pathname.replace(/\/[^\/]*$/, "")) - + "/" + path.replace(/^[\/]+/, ""); - return path; - }; - - var typeToIcon = function(type) { - var cls = "ace-"; - var suffix; - if (type == "?") suffix = "unknown"; - else if (type == "keyword") suffix = type; - else if (type == "identifier") suffix = type; - else if (type == "snippet") suffix = "snippet"; - else if (type == "number" || type == "string" || type == "bool") suffix = type; - else if (/^fn\(/.test(type)) suffix = "fn"; - else if (/^\[/.test(type)) suffix = "array"; - else suffix = "object"; - return cls + "completion " + cls + "completion-" + suffix; - }; - }()); diff --git a/examples/org.eclipse.xtext.example.arithmetics.web/src-js/org/eclipse/xtext/example/arithmetics/web/Arithmetics.js b/examples/org.eclipse.xtext.example.arithmetics.web/src-js/org/eclipse/xtext/example/arithmetics/web/Arithmetics.js index aa69b4a..893853b 100644 --- a/examples/org.eclipse.xtext.example.arithmetics.web/src-js/org/eclipse/xtext/example/arithmetics/web/Arithmetics.js +++ b/examples/org.eclipse.xtext.example.arithmetics.web/src-js/org/eclipse/xtext/example/arithmetics/web/Arithmetics.js @@ -1,5 +1,5 @@ /** - * @Generated by DSLFORGE + * @Generated by DSL Forge */ //minify using as YUI Compressor, Google Closure Compiler, or JSMin. (function() { @@ -95,7 +95,7 @@ } else { //Compute worker's http URL var filePath = 'rwt-resources/src-js/org/dslforge/styledtext/global-index.js'; - var httpURL = computeWorkerPath(filePath); + var httpURL = this.computeWorkerPath(filePath); var worker = this.worker = new SharedWorker(httpURL); if (this.ready) { editor.on("change", function(event) { @@ -179,23 +179,7 @@ }, onCompletionRequest : function(pos, prefix, callback) { - if (this.isFocused) { - var remoteObject = rap.getRemoteObject(this); - if (remoteObject) { - remoteObject.call("getProposals", { value : this.editor.getValue(), pos : pos, prefix : prefix}); - } - var proposals = this.proposals==null?[":"]:this.proposals; - var wordList = Object.keys(proposals); - callback(null, wordList.map(function(word) { - return { - iconClass: " " + typeToIcon(proposals[word].split(":")[1]), - name: word, - value: proposals[word].split(":")[0], - score: 1, - meta: "[" + proposals[word].split(":")[1] + "]" - }; - })); - } + this.base(arguments, pos, prefix, callback); }, setProposals : function(proposals) { @@ -228,26 +212,4 @@ } }); - var computeWorkerPath = function (path) { - path = path.replace(/^[a-z]+:\/\/[^\/]+/, ""); - path = location.protocol + "//" + location.host - + (path.charAt(0) == "/" ? "" : location.pathname.replace(/\/[^\/]*$/, "")) - + "/" + path.replace(/^[\/]+/, ""); - return path; - }; - - var typeToIcon = function(type) { - var cls = "ace-"; - var suffix; - if (type == "?") suffix = "unknown"; - else if (type == "keyword") suffix = type; - else if (type == "identifier") suffix = type; - else if (type == "snippet") suffix = "snippet"; - else if (type == "number" || type == "string" || type == "bool") suffix = type; - else if (/^fn\(/.test(type)) suffix = "fn"; - else if (/^\[/.test(type)) suffix = "array"; - else suffix = "object"; - return cls + "completion " + cls + "completion-" + suffix; - }; - }()); diff --git a/examples/org.eclipse.xtext.example.domainmodel.web/src-js/org/eclipse/xtext/example/domainmodel/web/Domainmodel.js b/examples/org.eclipse.xtext.example.domainmodel.web/src-js/org/eclipse/xtext/example/domainmodel/web/Domainmodel.js index 89d3977..bcddd84 100644 --- a/examples/org.eclipse.xtext.example.domainmodel.web/src-js/org/eclipse/xtext/example/domainmodel/web/Domainmodel.js +++ b/examples/org.eclipse.xtext.example.domainmodel.web/src-js/org/eclipse/xtext/example/domainmodel/web/Domainmodel.js @@ -1,5 +1,5 @@ /** - * @Generated by DSLFORGE + * @Generated by DSL Forge */ //minify using as YUI Compressor, Google Closure Compiler, or JSMin. (function() { @@ -95,7 +95,7 @@ } else { //Compute worker's http URL var filePath = 'rwt-resources/src-js/org/dslforge/styledtext/global-index.js'; - var httpURL = computeWorkerPath(filePath); + var httpURL = this.computeWorkerPath(filePath); var worker = this.worker = new SharedWorker(httpURL); if (this.ready) { editor.on("change", function(event) { @@ -179,23 +179,7 @@ }, onCompletionRequest : function(pos, prefix, callback) { - if (this.isFocused) { - var remoteObject = rap.getRemoteObject(this); - if (remoteObject) { - remoteObject.call("getProposals", { value : this.editor.getValue(), pos : pos, prefix : prefix}); - } - var proposals = this.proposals==null?[":"]:this.proposals; - var wordList = Object.keys(proposals); - callback(null, wordList.map(function(word) { - return { - iconClass: " " + typeToIcon(proposals[word].split(":")[1]), - name: word, - value: proposals[word].split(":")[0], - score: 1, - meta: "[" + proposals[word].split(":")[1] + "]" - }; - })); - } + this.base(arguments, pos, prefix, callback); }, setProposals : function(proposals) { @@ -227,27 +211,5 @@ } } }); - - var computeWorkerPath = function (path) { - path = path.replace(/^[a-z]+:\/\/[^\/]+/, ""); - path = location.protocol + "//" + location.host - + (path.charAt(0) == "/" ? "" : location.pathname.replace(/\/[^\/]*$/, "")) - + "/" + path.replace(/^[\/]+/, ""); - return path; - }; - - var typeToIcon = function(type) { - var cls = "ace-"; - var suffix; - if (type == "?") suffix = "unknown"; - else if (type == "keyword") suffix = type; - else if (type == "identifier") suffix = type; - else if (type == "snippet") suffix = "snippet"; - else if (type == "number" || type == "string" || type == "bool") suffix = type; - else if (/^fn\(/.test(type)) suffix = "fn"; - else if (/^\[/.test(type)) suffix = "array"; - else suffix = "object"; - return cls + "completion " + cls + "completion-" + suffix; - }; - + }()); diff --git a/examples/org.eclipse.xtext.example.fowlerdsl.web/src-js/org/eclipse/xtext/example/fowlerdsl/web/Statemachine.js b/examples/org.eclipse.xtext.example.fowlerdsl.web/src-js/org/eclipse/xtext/example/fowlerdsl/web/Statemachine.js index 92ec75d..d979230 100644 --- a/examples/org.eclipse.xtext.example.fowlerdsl.web/src-js/org/eclipse/xtext/example/fowlerdsl/web/Statemachine.js +++ b/examples/org.eclipse.xtext.example.fowlerdsl.web/src-js/org/eclipse/xtext/example/fowlerdsl/web/Statemachine.js @@ -1,5 +1,5 @@ /** - * @Generated by DSLFORGE + * @Generated by DSL Forge */ //minify using as YUI Compressor, Google Closure Compiler, or JSMin. (function() { @@ -95,7 +95,7 @@ } else { //Compute worker's http URL var filePath = 'rwt-resources/src-js/org/dslforge/styledtext/global-index.js'; - var httpURL = computeWorkerPath(filePath); + var httpURL = this.computeWorkerPath(filePath); var worker = this.worker = new SharedWorker(httpURL); if (this.ready) { editor.on("change", function(event) { @@ -179,25 +179,9 @@ }, onCompletionRequest : function(pos, prefix, callback) { - if (this.isFocused) { - var remoteObject = rap.getRemoteObject(this); - if (remoteObject) { - remoteObject.call("getProposals", { value : this.editor.getValue(), pos : pos, prefix : prefix}); - } - var proposals = this.proposals==null?[":"]:this.proposals; - var wordList = Object.keys(proposals); - callback(null, wordList.map(function(word) { - return { - iconClass: " " + typeToIcon(proposals[word].split(":")[1]), - name: word, - value: proposals[word].split(":")[0], - score: 1, - meta: "[" + proposals[word].split(":")[1] + "]" - }; - })); - } + this.base(arguments, pos, prefix, callback); }, - + setProposals : function(proposals) { this.proposals = proposals; }, @@ -227,27 +211,5 @@ } } }); - - var computeWorkerPath = function (path) { - path = path.replace(/^[a-z]+:\/\/[^\/]+/, ""); - path = location.protocol + "//" + location.host - + (path.charAt(0) == "/" ? "" : location.pathname.replace(/\/[^\/]*$/, "")) - + "/" + path.replace(/^[\/]+/, ""); - return path; - }; - - var typeToIcon = function(type) { - var cls = "ace-"; - var suffix; - if (type == "?") suffix = "unknown"; - else if (type == "keyword") suffix = type; - else if (type == "identifier") suffix = type; - else if (type == "snippet") suffix = "snippet"; - else if (type == "number" || type == "string" || type == "bool") suffix = type; - else if (/^fn\(/.test(type)) suffix = "fn"; - else if (/^\[/.test(type)) suffix = "array"; - else suffix = "object"; - return cls + "completion " + cls + "completion-" + suffix; - }; - + }()); diff --git a/examples/org.xtext.example.mydsl.web/src-js/org/xtext/example/mydsl/web/MyDsl.js b/examples/org.xtext.example.mydsl.web/src-js/org/xtext/example/mydsl/web/MyDsl.js index ab723b1..ca06a2f 100644 --- a/examples/org.xtext.example.mydsl.web/src-js/org/xtext/example/mydsl/web/MyDsl.js +++ b/examples/org.xtext.example.mydsl.web/src-js/org/xtext/example/mydsl/web/MyDsl.js @@ -1,5 +1,5 @@ /** - * @Generated by DSLFORGE + * @Generated by DSL Forge */ //minify using as YUI Compressor, Google Closure Compiler, or JSMin. (function() { @@ -95,7 +95,7 @@ } else { //Compute worker's http URL var filePath = 'rwt-resources/src-js/org/dslforge/styledtext/global-index.js'; - var httpURL = computeWorkerPath(filePath); + var httpURL = this.computeWorkerPath(filePath); var worker = this.worker = new SharedWorker(httpURL); if (this.ready) { editor.on("change", function(event) { @@ -179,23 +179,7 @@ }, onCompletionRequest : function(pos, prefix, callback) { - if (this.isFocused) { - var remoteObject = rap.getRemoteObject(this); - if (remoteObject) { - remoteObject.call("getProposals", { value : this.editor.getValue(), pos : pos, prefix : prefix}); - } - var proposals = this.proposals==null?[":"]:this.proposals; - var wordList = Object.keys(proposals); - callback(null, wordList.map(function(word) { - return { - iconClass: " " + typeToIcon(proposals[word].split(":")[1]), - name: word, - value: proposals[word].split(":")[0], - score: 1, - meta: "[" + proposals[word].split(":")[1] + "]" - }; - })); - } + this.base(arguments, pos, prefix, callback); }, setProposals : function(proposals) { @@ -227,27 +211,5 @@ } } }); - - var computeWorkerPath = function (path) { - path = path.replace(/^[a-z]+:\/\/[^\/]+/, ""); - path = location.protocol + "//" + location.host - + (path.charAt(0) == "/" ? "" : location.pathname.replace(/\/[^\/]*$/, "")) - + "/" + path.replace(/^[\/]+/, ""); - return path; - }; - - var typeToIcon = function(type) { - var cls = "ace-"; - var suffix; - if (type == "?") suffix = "unknown"; - else if (type == "keyword") suffix = type; - else if (type == "identifier") suffix = type; - else if (type == "snippet") suffix = "snippet"; - else if (type == "number" || type == "string" || type == "bool") suffix = type; - else if (/^fn\(/.test(type)) suffix = "fn"; - else if (/^\[/.test(type)) suffix = "array"; - else suffix = "object"; - return cls + "completion " + cls + "completion-" + suffix; - }; - + }()); diff --git a/plugins/org.dslforge.styledtext/src-js/org/dslforge/styledtext/BasicText.js b/plugins/org.dslforge.styledtext/src-js/org/dslforge/styledtext/BasicText.js index 414b0dc..ce384ec 100644 --- a/plugins/org.dslforge.styledtext/src-js/org/dslforge/styledtext/BasicText.js +++ b/plugins/org.dslforge.styledtext/src-js/org/dslforge/styledtext/BasicText.js @@ -59,9 +59,9 @@ langTools: null, annotations: [], scope: [], + proposals: [], completers: null, backendCompleter: null, - proposals: [":"], selectionStart:0, selectionEnd:0, useSharedWorker: true, @@ -148,7 +148,7 @@ } } //clear proposals - this.proposals= [":"]; + this.proposals= []; }, onRender : function() { @@ -168,22 +168,23 @@ remoteObject.notify("CaretEvent", { value : this.editor.getCursorPosition()}); } }, - + onCompletionRequest : function(pos, prefix, callback) { if (this.isFocused) { var remoteObject = rap.getRemoteObject(this); if (remoteObject) { remoteObject.call("getProposals", { value : this.editor.getValue(), pos : pos, prefix : prefix}); } - var proposals = this.proposals==null?[":"]:this.proposals; + var proposals = this.proposals; var wordList = Object.keys(proposals); + var self = this; callback(null, wordList.map(function(word) { return { - iconClass: " " + typeToIcon(proposals[word].split(":")[1]), + iconClass: " " + self.typeToIcon(proposals[word].type), name: word, - value: proposals[word].split(":")[0], + value: proposals[word].replacement, score: 1, - meta: "[" + proposals[word].split(":")[1] + "]" + meta: "[" + proposals[word].type + "]" }; })); } @@ -267,8 +268,6 @@ setAnnotations : function(newAnnotations) { if (this.ready) { //remove old server annotations - //var annotations = this.annotations != null ? this.annotations : this.editor.session.getAnnotations(); - var annotations = this.editor.session.getAnnotations(); for (var i = annotations.length; i--;) { annotations.pop(annotations[i]); @@ -436,7 +435,7 @@ //Initialize the completion proposals if (this.proposals==null) - this.proposals=[":"]; + this.proposals=[]; var self = this; this.backendCompleter = { @@ -469,7 +468,7 @@ } else { //create the shared worker var filePath = 'rwt-resources/src-js/org/dslforge/styledtext/global-index.js'; - var httpURL = computeWorkerPath(filePath); + var httpURL = this.computeWorkerPath(filePath); var worker = this.worker = new SharedWorker(httpURL); if (this.ready) { editor.on("change", function(event) { @@ -505,7 +504,7 @@ //On mouse down event editor.on("mousedown", function() { - // Store the Row/column values + // Store the Row/column values }) //On cursor move event @@ -516,12 +515,6 @@ // the cursor changed self.onChangeCursor(); }); - editor.getSession().on('changeCursor', function() { - if (editor.$mouseHandler.isMousePressed) { - // remove last stored values - } - // Store the Row/column values - }); //On text change event editor.on("change", function(event) { @@ -565,24 +558,32 @@ this.element.style.height = (area[3]-5) + 'px'; this.editor.resize(); } + }, + + computeWorkerPath : function (path) { + path = path.replace(/^[a-z]+:\/\/[^\/]+/, ""); // Remove domain name and rebuild path + path = location.protocol + "//" + location.host + + (path.charAt(0) == "/" ? "" : location.pathname.replace(/\/[^\/]*$/, "")) + + "/" + path.replace(/^[\/]+/, ""); + return path; + }, + + typeToIcon : function(type) { + var cls = "ace-"; + var suffix; + if (type == "?") suffix = "unknown"; + else if (type == "keyword") suffix = type; + else if (type == "identifier") suffix = type; + else if (type == "snippet") suffix = "snippet"; + else if (type == "number" || type == "string" || type == "bool") suffix = type; + else if (/^fn\(/.test(type)) suffix = "fn"; + else if (/^\[/.test(type)) suffix = "array"; + else suffix = "object"; + return cls + "completion " + cls + "completion-" + suffix; } } }); - var typeToIcon = function(type) { - var cls = "ace-"; - var suffix; - if (type == "?") suffix = "unknown"; - else if (type == "keyword") suffix = type; - else if (type == "identifier") suffix = type; - else if (type == "snippet") suffix = "snippet"; - else if (type == "number" || type == "string" || type == "bool") suffix = type; - else if (/^fn\(/.test(type)) suffix = "fn"; - else if (/^\[/.test(type)) suffix = "array"; - else suffix = "object"; - return cls + "completion " + cls + "completion-" + suffix; - }; - var bind = function(context, method) { return function() { return method.apply(context, arguments); @@ -601,13 +602,5 @@ func.apply(context); }, 0); }; - - var computeWorkerPath = function (path) { - path = path.replace(/^[a-z]+:\/\/[^\/]+/, ""); // Remove domain name and rebuild path - path = location.protocol + "//" + location.host - + (path.charAt(0) == "/" ? "" : location.pathname.replace(/\/[^\/]*$/, "")) - + "/" + path.replace(/^[\/]+/, ""); - return path; - }; }()); \ No newline at end of file diff --git a/plugins/org.dslforge.styledtext/src/org/dslforge/styledtext/BasicText.java b/plugins/org.dslforge.styledtext/src/org/dslforge/styledtext/BasicText.java index db4671a..eea9ed5 100644 --- a/plugins/org.dslforge.styledtext/src/org/dslforge/styledtext/BasicText.java +++ b/plugins/org.dslforge.styledtext/src/org/dslforge/styledtext/BasicText.java @@ -22,6 +22,7 @@ import java.util.List; import org.apache.log4j.Logger; +import org.dslforge.styledtext.jface.ICompletionProposal; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; import org.eclipse.rap.json.JsonArray; @@ -67,7 +68,7 @@ public class BasicText extends Composite { private String status = ""; private List annotations = new ArrayList(); private List scope = new ArrayList(); - private List proposals = new ArrayList(); + private List proposals = new ArrayList(); private List markers = new ArrayList(); private int style; private Listener listener; @@ -869,17 +870,21 @@ public void setScope(List scope) { * * @param proposals */ - public void setProposals(List proposals) { + public void setProposals(List proposals) { checkWidget(); if (proposals == null) { SWT.error(SWT.ERROR_NULL_ARGUMENT); } this.proposals = proposals; - JsonArray array = new JsonArray(); - for (String s : proposals) { - array.add(s); + JsonArray values = new JsonArray(); + for (ICompletionProposal proposal : proposals) { + JsonObject value = new JsonObject(); + value.add("display", proposal.getDisplayString()); + value.add("replacement", proposal.getReplacementString()); + value.add("type", proposal.getAdditionalProposalInfo()); + values.add(value); } - getRemoteObject().set("proposals", array); + getRemoteObject().set("proposals", values); } /** @@ -1013,7 +1018,7 @@ public List getScope() { * * @return the content assist proposals */ - public List getProposals() { + public List getProposals() { checkWidget(); return proposals; } diff --git a/plugins/org.dslforge.styledtext/src/org/dslforge/styledtext/jface/ICompletionProposal.java b/plugins/org.dslforge.styledtext/src/org/dslforge/styledtext/jface/ICompletionProposal.java index 4f3c671..44cdfa3 100644 --- a/plugins/org.dslforge.styledtext/src/org/dslforge/styledtext/jface/ICompletionProposal.java +++ b/plugins/org.dslforge.styledtext/src/org/dslforge/styledtext/jface/ICompletionProposal.java @@ -78,7 +78,7 @@ public interface ICompletionProposal { * * @param document the document into which to insert the proposed completion */ - //void apply(IDocument document); + void apply(IDocument document); /** * Returns the new selection after the proposal has been applied to @@ -116,6 +116,14 @@ public interface ICompletionProposal { */ String getDisplayString(); + /** + * Returns the string to be actually inserted in text. + * + * @return the string to be inserted + * + */ + String getReplacementString(); + /** * Returns the image to be displayed in the list of completion proposals. * The image would typically be shown to the left of the display string. diff --git a/plugins/org.dslforge.texteditor/src/org/dslforge/texteditor/BasicTextEditor.java b/plugins/org.dslforge.texteditor/src/org/dslforge/texteditor/BasicTextEditor.java index 8955a87..6fed1cd 100644 --- a/plugins/org.dslforge.texteditor/src/org/dslforge/texteditor/BasicTextEditor.java +++ b/plugins/org.dslforge.texteditor/src/org/dslforge/texteditor/BasicTextEditor.java @@ -38,6 +38,7 @@ import org.dslforge.styledtext.TextChangedEvent; import org.dslforge.styledtext.TextSavedEvent; import org.dslforge.styledtext.TextSelection; +import org.dslforge.styledtext.jface.ICompletionProposal; import org.dslforge.styledtext.jface.IDocument; import org.dslforge.styledtext.jface.ITextViewer; import org.dslforge.styledtext.jface.TextDocument; @@ -595,7 +596,7 @@ protected void setScope(List scope) { viewer.getTextWidget().setScope(scope); } - protected void setProposals(List proposals) { + protected void setProposals(List proposals) { viewer.getTextWidget().setProposals(proposals); } diff --git a/plugins/org.dslforge.xtext.common/src/org/dslforge/xtext/common/XtextContentAssistEnabledEditor.java b/plugins/org.dslforge.xtext.common/src/org/dslforge/xtext/common/XtextContentAssistEnabledEditor.java index e321672..09750f6 100644 --- a/plugins/org.dslforge.xtext.common/src/org/dslforge/xtext/common/XtextContentAssistEnabledEditor.java +++ b/plugins/org.dslforge.xtext.common/src/org/dslforge/xtext/common/XtextContentAssistEnabledEditor.java @@ -4,7 +4,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; -import java.util.List; import org.dslforge.styledtext.BasicText; import org.dslforge.styledtext.jface.ICompletionProposal; @@ -116,12 +115,7 @@ public void run() { XtextContentAssistProcessor xtextContentAssistProcessor = (XtextContentAssistProcessor)contentAssistProcessor; ICompletionProposal[] computedCompletionProposals = xtextContentAssistProcessor.computeCompletionProposals(getViewer(), xtextResource, offset); if (computedCompletionProposals!=null) { - List proposals = Lists.transform(Arrays.asList(computedCompletionProposals), new Function() { - public String apply(ICompletionProposal completionProposal) { - return completionProposal.getDisplayString() + ":" + completionProposal.getAdditionalProposalInfo(); - } - }); - setProposals(proposals); + setProposals(Arrays.asList(computedCompletionProposals)); } } }); diff --git a/plugins/org.dslforge.xtext.common/src/org/dslforge/xtext/common/scoping/WebScopeProvider.java b/plugins/org.dslforge.xtext.common/src/org/dslforge/xtext/common/scoping/WebScopeProvider.java deleted file mode 100644 index b5ebcbd..0000000 --- a/plugins/org.dslforge.xtext.common/src/org/dslforge/xtext/common/scoping/WebScopeProvider.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * - * - * Copyright (c) 2015 PlugBee. All rights reserved. - * - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Amine Lajmi - Initial API and implementation - * - * - */ -package org.dslforge.xtext.common.scoping; - -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EReference; -import org.eclipse.xtext.resource.IEObjectDescription; -import org.eclipse.xtext.scoping.IScope; -import org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider; -import org.eclipse.xtext.scoping.impl.FilteringScope; - -import com.google.common.base.Predicate; - - -public class WebScopeProvider extends AbstractDeclarativeScopeProvider { - - IScope scope_A_B(EObject context, EReference reference) { - return new FilteringScope(delegateGetScope(context, reference), - new Predicate() { - public boolean apply(IEObjectDescription d) { - return true; - } - }); - } -} \ No newline at end of file diff --git a/plugins/org.dslforge.xtext.common/src/org/dslforge/xtext/common/shared/SharedModule.java b/plugins/org.dslforge.xtext.common/src/org/dslforge/xtext/common/shared/SharedModule.java index 04ae832..9fadfa6 100644 --- a/plugins/org.dslforge.xtext.common/src/org/dslforge/xtext/common/shared/SharedModule.java +++ b/plugins/org.dslforge.xtext.common/src/org/dslforge/xtext/common/shared/SharedModule.java @@ -42,7 +42,7 @@ protected void bindLinkingService(Binder binder) { } protected void bindGlobalScopeProvider(Binder binder) { -// binder.bind(IGlobalScopeProvider.class).to(WebGlobalScopeProvider.class); + //binder.bind(IGlobalScopeProvider.class).to(WebGlobalScopeProvider.class); } protected void bindContainerManager(Binder binder) { diff --git a/plugins/org.dslforge.xtext.common/src/org/eclipse/xtext/ui/editor/contentassist/CompletionProposalComputer.java b/plugins/org.dslforge.xtext.common/src/org/eclipse/xtext/ui/editor/contentassist/CompletionProposalComputer.java index e49a06b..51f2505 100644 --- a/plugins/org.dslforge.xtext.common/src/org/eclipse/xtext/ui/editor/contentassist/CompletionProposalComputer.java +++ b/plugins/org.dslforge.xtext.common/src/org/eclipse/xtext/ui/editor/contentassist/CompletionProposalComputer.java @@ -3,7 +3,6 @@ import java.util.Collection; import java.util.LinkedHashSet; -import org.dslforge.styledtext.BasicText; import org.dslforge.styledtext.jface.ICompletionProposal; import org.dslforge.styledtext.jface.ITextViewer; import org.eclipse.xtext.resource.XtextResource; @@ -17,7 +16,7 @@ public class CompletionProposalComputer implements ICompletionProposalAcceptor { private final State state; private final Collection proposals; - + @Inject private ContentAssistContext.Factory contextFactory; diff --git a/plugins/org.dslforge.xtext.common/src/org/eclipse/xtext/ui/editor/contentassist/ConfigurableCompletionProposal.java b/plugins/org.dslforge.xtext.common/src/org/eclipse/xtext/ui/editor/contentassist/ConfigurableCompletionProposal.java index 2a33470..526f030 100644 --- a/plugins/org.dslforge.xtext.common/src/org/eclipse/xtext/ui/editor/contentassist/ConfigurableCompletionProposal.java +++ b/plugins/org.dslforge.xtext.common/src/org/eclipse/xtext/ui/editor/contentassist/ConfigurableCompletionProposal.java @@ -1,6 +1,8 @@ package org.eclipse.xtext.ui.editor.contentassist; +import org.apache.log4j.Logger; import org.dslforge.styledtext.jface.ICompletionProposal; +import org.dslforge.styledtext.jface.IDocument; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.edit.provider.StyledString; import org.eclipse.swt.graphics.Image; @@ -8,6 +10,8 @@ public class ConfigurableCompletionProposal implements ICompletionProposal { + static final Logger logger = Logger.getLogger(ConfigurableCompletionProposal.class); + private String replacementString; private int replacementOffset; private int replacementLength; @@ -33,6 +37,16 @@ public ConfigurableCompletionProposal(String replacementString, int replacementO this.additionalProposalInfo = additionalProposalInfo; } + @Override + public void apply(IDocument document) { + String original = document.get(); + try { + document.replace(getReplacementOffset(), getReplacementLength(), getReplacementString()); + } catch (Exception ex) { + logger.error("Error applying completion proposal", ex); + document.set(original); + } + } public int getReplacementOffset() { return replacementOffset; } diff --git a/plugins/org.dslforge.xtext.generator/src/org/dslforge/xtext/generator/web/editor/widget/GenWidget.xtend b/plugins/org.dslforge.xtext.generator/src/org/dslforge/xtext/generator/web/editor/widget/GenWidget.xtend index d279ad8..e1d5bd2 100644 --- a/plugins/org.dslforge.xtext.generator/src/org/dslforge/xtext/generator/web/editor/widget/GenWidget.xtend +++ b/plugins/org.dslforge.xtext.generator/src/org/dslforge/xtext/generator/web/editor/widget/GenWidget.xtend @@ -112,6 +112,7 @@ public class construct : function(properties) { this.base(arguments, properties); }, + members : { createEditor : function() { @@ -181,7 +182,7 @@ public class //Initialize the completion proposals proposals = this.proposals; - + //Handle the global index if (this.useSharedWorker) { if (typeof SharedWorker == 'undefined') { @@ -189,7 +190,7 @@ public class } else { //Compute worker's http URL var filePath = 'rwt-resources/src-js/org/dslforge/styledtext/global-index.js'; - var httpURL = computeWorkerPath(filePath); + var httpURL = this.computeWorkerPath(filePath); var worker = this.worker = new SharedWorker(httpURL); if (this.ready) { editor.on("change", function(event) { @@ -236,6 +237,7 @@ public class // the cursor changed self.onChangeCursor(); }); + editor.getSession().on('changeCursor', function() { if (editor.$mouseHandler.isMousePressed) { // remove last stored values @@ -273,23 +275,7 @@ public class }, onCompletionRequest : function(pos, prefix, callback) { - if (this.isFocused) { - var remoteObject = rap.getRemoteObject(this); - if (remoteObject) { - remoteObject.call("getProposals", { value : this.editor.getValue(), pos : pos, prefix : prefix}); - } - var proposals = this.proposals==null?[":"]:this.proposals; - var wordList = Object.keys(proposals); - callback(null, wordList.map(function(word) { - return { - iconClass: " " + typeToIcon(proposals[word].split(":")[1]), - name: word, - value: proposals[word].split(":")[0], - score: 1, - meta: "[" + proposals[word].split(":")[1] + "]" - }; - })); - } + this.base(arguments, pos, prefix, callback); }, setProposals : function(proposals) { @@ -322,27 +308,6 @@ public class } }); - var computeWorkerPath = function (path) { - path = path.replace(/^[a-z]+:\/\/[^\/]+/, ""); - path = location.protocol + "//" + location.host - + (path.charAt(0) == "/" ? "" : location.pathname.replace(/\/[^\/]*$/, "")) - + "/" + path.replace(/^[\/]+/, ""); - return path; - }; - - var typeToIcon = function(type) { - var cls = "ace-"; - var suffix; - if (type == "?") suffix = "unknown"; - else if (type == "keyword") suffix = type; - else if (type == "identifier") suffix = type; - else if (type == "snippet") suffix = "snippet"; - else if (type == "number" || type == "string" || type == "bool") suffix = type; - else if (/^fn\(/.test(type)) suffix = "fn"; - else if (/^\[/.test(type)) suffix = "array"; - else suffix = "object"; - return cls + "completion " + cls + "completion-" + suffix; - }; }()); ''' }