summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorMike Rennie2013-11-14 17:09:03 (EST)
committer Gerrit Code Review @ Eclipse.org2013-11-14 17:14:47 (EST)
commit842bd8ae78c81bba8891ca8bdb03164291d4ba3b (patch)
tree8c8472f441a7f5c173926450826437badd490f99
parent70ae64d3a8664e2b880125446676b7bfcd51b21b (diff)
downloadorg.eclipse.orion.client-842bd8ae78c81bba8891ca8bdb03164291d4ba3b.zip
org.eclipse.orion.client-842bd8ae78c81bba8891ca8bdb03164291d4ba3b.tar.gz
org.eclipse.orion.client-842bd8ae78c81bba8891ca8bdb03164291d4ba3b.tar.bz2
Bug 421783 - Provide a JSDoc outlinev20131114-2214refs/changes/10/18410/2
Change-Id: I310d94b1160a05326f51421354ac46e14d84feb3 Signed-off-by: Mike Rennie <Michael_Rennie@ca.ibm.com>
-rw-r--r--bundles/org.eclipse.orion.client.javascript/web/javascript/occurrences.js7
-rw-r--r--bundles/org.eclipse.orion.client.javascript/web/javascript/outliner.js154
-rw-r--r--bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/javascriptPlugin.js6
3 files changed, 127 insertions, 40 deletions
diff --git a/bundles/org.eclipse.orion.client.javascript/web/javascript/occurrences.js b/bundles/org.eclipse.orion.client.javascript/web/javascript/occurrences.js
index 368a384..36f9815 100644
--- a/bundles/org.eclipse.orion.client.javascript/web/javascript/occurrences.js
+++ b/bundles/org.eclipse.orion.client.javascript/web/javascript/occurrences.js
@@ -9,11 +9,10 @@
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
-/*global define console*/
+/*global define console escope*/
define([
-"esprima/esprima",
"orion/Deferred"
-], function(Esprima, Deferred) {
+], function(Deferred) {
/**
* @name javascript.JavaScriptOccurrences
@@ -211,7 +210,7 @@ define([
},
/**
- * @name findOccurrence
+ * @name findOccurrence
* @description Finds the occurrence from the given context in the given AST node
* @function
* @private
diff --git a/bundles/org.eclipse.orion.client.javascript/web/javascript/outliner.js b/bundles/org.eclipse.orion.client.javascript/web/javascript/outliner.js
index deecf30..b148133 100644
--- a/bundles/org.eclipse.orion.client.javascript/web/javascript/outliner.js
+++ b/bundles/org.eclipse.orion.client.javascript/web/javascript/outliner.js
@@ -9,68 +9,158 @@
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
-/*global define esprima*/
-define(["esprima/esprima"
-], function() {
+/*global define*/
+define([
+'orion/objects'
+], function(Objects) {
/**
- * @name javascript.JavaScriptOutliner
+ * @name javascript.JSDocOutliner
* @description creates a new instance of the outliner
* @constructor
* @public
*/
- function JavaScriptOutliner() {
+ function JSDocOutliner() {
}
- JavaScriptOutliner.prototype = /** @lends javascript.JavaScriptOutliner.prototype*/ {
+ Objects.mixin(JSDocOutliner.prototype, /** @lends javascript.JSDocOutliner.prototype*/ {
/**
- * @name getOutline
+ * @name computeOutline
* @description callback from the <code>orion.edit.outliner</code> service to create
* an outline
* @function
* @public
- * @memberof javascript.JavaScriptOutliner.prototype
- * @param {String} contents - the contents to make an outline from
- * @param {String} title - the title
+ * @memberof javascript.JSDocOutliner.prototype
+ * @param {orion.edit.EditorContext} editorContext The editor context
+ * @param {Object} options The options
+ * @returns {orion.Promise} to compute the outline
*/
- getOutline: function(contents, title) {
- //TODO
- return [];
+ computeOutline: function(editorContext, options) {
+ this.sourceCounter = 1;
+ var that = this;
+ var astoptions = {loc:true, comment:true, tolerant:true, tokens:false, range:false, raw:false};
+ return editorContext.getAST(astoptions).then(function(ast) {
+ if(ast && ast.comments) {
+ var elements = [];
+ ast.comments.forEach(function(node) {
+ if(node.type === "Block") {
+ //Outline element {label, className, line, children, href}
+ elements.push({
+ start : node.range[0] > 0 ? node.range[0] : 1,
+ end : node.range[1],
+ label : that._getNameFrom(node, ['@name']),
+ //className : that._getNameFrom(node, ['@class', '@memberof']),
+ children : that._getTagChildren(node)
+ });
+ }
+ });
+ return elements;
+ }
+ });
},
/**
- * @name getSourceOutline
- * @description creates a raw heiarchical source outline
+ * @name _getNameFrom
+ * @description tries to compute a name for the element using the given array of names to look for
* @function
* @private
- * @memberof javascript.JavaScriptOutliner.prototype
- * @param {String} contents - the contents to make an outline from
- * @param {String} title - the title
+ * @memberof javascript.JSDocOutliner
+ * @param {Object} node The AST doc node
+ * @param {Array|String} tags An array of strings of the names of tags to look for to try and find a name
+ * @returns the name to use for the given node if it could be computed, or 'Doc Node #N' if a name could not be computed
*/
- getSourceOultine: function(contents, title) {
- //TODO use shared AST, do not recompute if possible
- return [];
+ _getNameFrom: function(node, tags) {
+ var that = this;
+ var length = tags.length;
+ for(var i = 0; i < length; i++) {
+ var val = node.value;
+ var tag = tags[i]+' ';
+ var index = val.indexOf(tag);
+ if(index > -1) {
+ //hack, just assume a name does not have spaces
+ var start = index+tag.length;
+ var end = val.indexOf(' ', start);
+ if(end > -1) {
+ return val.substring(start, end);
+ }
+ }
+ }
+ return "Doc node #"+that.sourceCounter++;
},
/**
- * @name getJsDocOutline
- * @description creates a heiarchical source outline based solely on JSDoc tags
+ * @name _getTagChildren
+ * @description Computes all of the tags of a doc node as a child array
* @function
* @private
- * @memberof javascript.JavaScriptOutliner.prototype
- * @param {String} contents - the contents to make an outline from
- * @param {String} title - the title
+ * @memberof javascript.JSDocOutliner
+ * @param {Object} node The AST doc node
+ * @returns {Array|Object} Returns the array of child tags
+ */
+ _getTagChildren: function(node) {
+ var val = node.value;
+ //hack assume all tags start with '@' and end in a space
+ var kids = [];
+ var idx = 0, atidx = 0;
+ var length = val.length;
+ var intag = false;
+ while(idx < length) {
+ var char = val.charAt(idx);
+ if(char === '@') {
+ intag = true;
+ atidx = idx;
+ }
+ else if(intag && (char === ' ' || char === '\n' || char === '\r')) {
+ intag = false;
+ kids.push({
+ label : val.substring(atidx, idx),
+ start: atidx + node.range[0]+2, //hack - the value of the node chops off the first two chars '/*'
+ end: idx + node.range[0]+2
+ });
+ }
+ idx++;
+ }
+ if(kids.length === 0) {
+ //Returning an emppty array causes twisties to be shown with no children, return null
+ return null;
+ }
+ return kids;
+ }
+ });
+
+ JSDocOutliner.prototype.contructor = JSDocOutliner;
+
+ /**
+ * @name javascript.JsOutliner
+ * @description creates a new instance of the outliner
+ * @constructor
+ * @public
+ */
+ function JsOutliner() {
+ }
+
+ Objects.mixin(JsOutliner.prototype, /** @lends javascript.JsOutliner.prototype*/ {
+
+ /**
+ * @name computeOutline
+ * @description callback from the <code>orion.edit.outliner</code> service to create
+ * an outline
+ * @function
+ * @public
+ * @memberof javascript.JsOutliner.prototype
+ * @param {orion.edit.EditorContext} editorContext The editor context
+ * @param {Object} options The options
+ * @returns {}
*/
- getJsDocOutline: function(contents, title) {
- //TODO use shared AST, do not recompute if possible
+ computeOutline: function(editorContext, options) {
return [];
}
- };
+ });
- JavaScriptOutliner.prototype.contructor = JavaScriptOutliner;
+ JsOutliner.prototype.contructor = JsOutliner;
return {
- JavaScriptOutliner: JavaScriptOutliner
- };
+ JSDocOutliner: JSDocOutliner,
+ JsOutliner: JsOutliner};
}); \ No newline at end of file
diff --git a/bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/javascriptPlugin.js b/bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/javascriptPlugin.js
index 2cdc25c..c49d639 100644
--- a/bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/javascriptPlugin.js
+++ b/bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/javascriptPlugin.js
@@ -43,12 +43,10 @@ define([
]
});
- var outliner = new Outliner.JavaScriptOutliner();
-
/**
* Register the jsdoc-based outline
*/
- provider.registerServiceProvider("orion.edit.outliner", outliner,
+ provider.registerServiceProvider("orion.edit.outliner", new Outliner.JSDocOutliner(),
{ contentType: ["application/javascript"],
name: "JSDoc outline",
id: "orion.javascript.outliner.jsdoc"
@@ -57,7 +55,7 @@ define([
/**
* Register the raw source-based outline
*/
- provider.registerServiceProvider("orion.edit.outliner", outliner,
+ provider.registerServiceProvider("orion.edit.outliner", new Outliner.JsOutliner(),
{ contentType: ["application/javascript"],
name: "Source outline",
id: "orion.javascript.outliner.source"