summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorManu Sridharan2013-09-30 14:12:07 (EDT)
committer Mark Macdonald2013-09-30 17:46:36 (EDT)
commitd105e22dad6791edeb4f60f5178fd12552b833d3 (patch)
treee3640028e8d53fd74616a1a1d8f2d6ce6986a98b
parent2fdaaad88ce162a8eed118f4641d4611d2d60c69 (diff)
downloadorg.eclipse.orion.client-d105e22dad6791edeb4f60f5178fd12552b833d3.zip
org.eclipse.orion.client-d105e22dad6791edeb4f60f5178fd12552b833d3.tar.gz
org.eclipse.orion.client-d105e22dad6791edeb4f60f5178fd12552b833d3.tar.bz2
Improvements to content assist for node.js buffer globals. Fixes bug 418356
Signed-off-by: Manu Sridharan <msridhar@us.ibm.com>
-rw-r--r--bundles/org.eclipse.orion.client.ui/web/js-tests/esprima/esprimaJsContentAssistTests.js44
-rw-r--r--bundles/org.eclipse.orion.client.ui/web/js-tests/esprima/indexFileParsingTests.js11
-rw-r--r--bundles/org.eclipse.orion.client.ui/web/plugins/esprima/indexFiles/nodeIndex.js20
-rw-r--r--bundles/org.eclipse.orion.client.ui/web/plugins/esprima/typesFromIndexFile.js9
4 files changed, 76 insertions, 8 deletions
diff --git a/bundles/org.eclipse.orion.client.ui/web/js-tests/esprima/esprimaJsContentAssistTests.js b/bundles/org.eclipse.orion.client.ui/web/js-tests/esprima/esprimaJsContentAssistTests.js
index ff4df8b..b245616 100644
--- a/bundles/org.eclipse.orion.client.ui/web/js-tests/esprima/esprimaJsContentAssistTests.js
+++ b/bundles/org.eclipse.orion.client.ui/web/js-tests/esprima/esprimaJsContentAssistTests.js
@@ -2458,6 +2458,50 @@ define([
]);
};
+ tests["test node15"] = function() {
+ var results = computeContentAssist(
+ "/*jslint node:true*/\n" +
+ "buffer.IN", "IN"
+ );
+ return testProposals(results, [
+ ["INSPECT_MAX_BYTES", "INSPECT_MAX_BYTES : Number"]
+ ]);
+ };
+
+ tests["test node16"] = function() {
+ var results = computeContentAssist(
+ "/*jslint node:true*/\n" +
+ "var x = new Buffer(10);\n" +
+ "x.c", "c"
+ );
+ return testProposals(results, [
+ ["copy(targetBuffer, [targetStart], [sourceStart], [sourceEnd])", "copy(targetBuffer, [targetStart], [sourceStart], [sourceEnd]) : undefined"]
+ ]);
+ };
+
+ tests["test node17"] = function() {
+ var results = computeContentAssist(
+ "/*jslint node:true*/\n" +
+ "var x = new buffer.Buffer(10);\n" +
+ "x.c", "c"
+ );
+ return testProposals(results, [
+ ["copy(targetBuffer, [targetStart], [sourceStart], [sourceEnd])", "copy(targetBuffer, [targetStart], [sourceStart], [sourceEnd]) : undefined"]
+ ]);
+ };
+
+
+ tests["test node18"] = function() {
+ var results = computeContentAssist(
+ "/*jslint node:true*/\n" +
+ "Buffer.is", "is"
+ );
+ return testProposals(results, [
+ ["isBuffer(obj)", "isBuffer(obj) : undefined"],
+ ["isEncoding(encoding)", "isEncoding(encoding) : undefined"]
+ ]);
+ };
+
////////////////////////////////////////
// jsdoc tests
diff --git a/bundles/org.eclipse.orion.client.ui/web/js-tests/esprima/indexFileParsingTests.js b/bundles/org.eclipse.orion.client.ui/web/js-tests/esprima/indexFileParsingTests.js
index 4198666..cb36027 100644
--- a/bundles/org.eclipse.orion.client.ui/web/js-tests/esprima/indexFileParsingTests.js
+++ b/bundles/org.eclipse.orion.client.ui/web/js-tests/esprima/indexFileParsingTests.js
@@ -150,10 +150,17 @@ define(["plugins/esprima/typesFromIndexFile", "plugins/esprima/typeEnvironment",
}
};
return checkEnvironment(index, function (env) {
- var t = env.lookupTypeObj("x", "Fizz..prototype");
- // TODO figureout out what to check here!!!
+ assert.equal("String", env.lookupTypeObj("x", "Fizz..prototype").name, "bad environment");
});
};
+ tests["test top-level dot"] = function() {
+ var index = {
+ Fizz: "foo.bazz"
+ };
+ return checkEnvironment(index, function (env) {
+ assert.equal("foo..bazz", env.lookupTypeObj("Fizz").name, "bad environment");
+ });
+ };
return tests;
});
diff --git a/bundles/org.eclipse.orion.client.ui/web/plugins/esprima/indexFiles/nodeIndex.js b/bundles/org.eclipse.orion.client.ui/web/plugins/esprima/indexFiles/nodeIndex.js
index 8f128ed..31a5386 100644
--- a/bundles/org.eclipse.orion.client.ui/web/plugins/esprima/indexFiles/nodeIndex.js
+++ b/bundles/org.eclipse.orion.client.ui/web/plugins/esprima/indexFiles/nodeIndex.js
@@ -57,7 +57,7 @@ define("plugins/esprima/indexFiles/nodeIndex", [], function () {
},
"buffer": {
"INSPECT_MAX_BYTES": {
- "!type": "Object"
+ "!type": "Number"
},
"Buffer": {
"!type": "fn()",
@@ -170,6 +170,18 @@ define("plugins/esprima/indexFiles/nodeIndex", [], function () {
"length": {
"!type": "Object"
}
+ },
+ "isEncoding": {
+ "!type": "fn(encoding: Object)"
+ },
+ "isBuffer": {
+ "!type": "fn(obj: Object)"
+ },
+ "byteLength": {
+ "!type": "fn(string: Object, encoding?: Object)"
+ },
+ "concat": {
+ "!type": "fn(list: Object, totalLength?: Object)"
}
},
"SlowBuffer": {
@@ -595,6 +607,9 @@ define("plugins/esprima/indexFiles/nodeIndex", [], function () {
"emit": {
"!type": "fn(event: Object, arg1?: Object, arg2?: Object, other?: Object)"
}
+ },
+ "listenerCount": {
+ "!type": "fn(emitter: Object, event: Object)"
}
}
},
@@ -1690,7 +1705,8 @@ define("plugins/esprima/indexFiles/nodeIndex", [], function () {
"!name": "node",
"this": "<top>",
"global": "<top>",
- "buffer": "+Buffer",
+ "buffer": "buffer",
+ "Buffer": "buffer.Buffer",
"require": {
"!type": "fn(name: String) -> Object"
},
diff --git a/bundles/org.eclipse.orion.client.ui/web/plugins/esprima/typesFromIndexFile.js b/bundles/org.eclipse.orion.client.ui/web/plugins/esprima/typesFromIndexFile.js
index cb5997a..1638346 100644
--- a/bundles/org.eclipse.orion.client.ui/web/plugins/esprima/typesFromIndexFile.js
+++ b/bundles/org.eclipse.orion.client.ui/web/plugins/esprima/typesFromIndexFile.js
@@ -323,14 +323,14 @@ define("plugins/esprima/typesFromIndexFile", ["orion/Deferred", "plugins/esprima
if (type.slice(0,1) === "+") {
type = type.slice(1,type.length) + "..prototype";
}
- return name ? new typeUtils.Definition(name) : new typeUtils.Definition(type);
+ return new typeUtils.Definition(type);
} else { // an object type
var parsed = parseObjType(type, name);
var newTypeName = parsed.def.typeObj.name;
// here we check if type["!type"] is a plain type name. if so,
// we just have an empty type description for it (with no
// properties), and there is no need to update the type object
- if (newTypeName && !emptyTypeName(type["!type"])) {
+ if (newTypeName && newTypeName !== "Global" && !emptyTypeName(type["!type"])) {
if (newTypeName === "Object") {
// need to mangle the property names as in original types.js
var mangled = {};
@@ -374,7 +374,6 @@ define("plugins/esprima/typesFromIndexFile", ["orion/Deferred", "plugins/esprima
* adds the info from the given json index file. global variables are added to globals,
* and type information to typeInfo
*/
-
function addIndexInfo(json, globals, typeInfo) {
var p;
for (p in json) {
@@ -394,7 +393,9 @@ define("plugins/esprima/typesFromIndexFile", ["orion/Deferred", "plugins/esprima
}
}
} else if (typeof json[p] === "string") {
- globals[p] = json[p] === "<top>" ? new typeUtils.Definition("Global") : new typeUtils.Definition(json[p]);
+ var typeStr = json[p];
+ var typeObj = { "!type": typeStr };
+ globals[p] = definitionForType(typeInfo, typeObj, p);
} else {
// new global
var type = json[p];