mirror of
https://github.com/RustyRaptor/brackets.git
synced 2026-12-04 00:15:22 -07:00
Update tern and acorn to latest - fixes a number of bugs.
Modified some of the expected output for unittests as tern was updated to produce arguably better results, particularly for jump-to-def. Changed the jump to def logic so that it doesn't stomp on all the pending requests, and instead plays nicely with the other request types.
This commit is contained in:
1 parent
104ff29c51
commit
dfb35c30f5
5 files changed
+84
-85
No files matched your search
@@ -346,6 +346,56 @@ define(function (require, exports, module) {
|
||||
return numInitialFiles !== numResolvedFiles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a pending request waiting for the tern-worker to complete.
|
||||
*
|
||||
* @param {string} file - the name of the file
|
||||
* @param {number} offset - the offset into the file the request is for
|
||||
* @param {string} type - the type of request
|
||||
* @return {jQuery.Promise} - the promise for the request
|
||||
*/
|
||||
function addPendingRequest(file, offset, type) {
|
||||
var requests,
|
||||
key = file + "@" + offset,
|
||||
$deferredRequest;
|
||||
if (CollectionUtils.hasProperty(pendingTernRequests, key)) {
|
||||
requests = pendingTernRequests[key];
|
||||
} else {
|
||||
requests = {};
|
||||
pendingTernRequests[key] = requests;
|
||||
}
|
||||
|
||||
if (CollectionUtils.hasProperty(requests, type)) {
|
||||
$deferredRequest = requests[type];
|
||||
} else {
|
||||
requests[type] = $deferredRequest = $.Deferred();
|
||||
}
|
||||
return $deferredRequest.promise();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get any pending $.Deferred object waiting on the specified file and request type
|
||||
* @param {string} file - the file
|
||||
* @param {number} offset - the offset in the file the request was at
|
||||
* @param {string} type - the type of request
|
||||
* @return {jQuery.Deferred} - the $.Deferred for the request
|
||||
*/
|
||||
function getPendingRequest(file, offset, type) {
|
||||
var key = file + "@" + offset;
|
||||
if (CollectionUtils.hasProperty(pendingTernRequests, key)) {
|
||||
var requests = pendingTernRequests[key],
|
||||
requestType = requests[type];
|
||||
|
||||
delete pendingTernRequests[key][type];
|
||||
|
||||
if (!Object.keys(requests).length) {
|
||||
delete pendingTernRequests[key];
|
||||
}
|
||||
|
||||
return requestType;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Promise for the definition from TernJS, for the file & offset passed in.
|
||||
* @return {jQuery.Promise} - a promise that will resolve to definition when
|
||||
@@ -360,9 +410,7 @@ define(function (require, exports, module) {
|
||||
text: text
|
||||
});
|
||||
|
||||
var $deferredJump = $.Deferred();
|
||||
pendingTernRequests[file] = $deferredJump;
|
||||
return $deferredJump.promise();
|
||||
return addPendingRequest(file, offset, HintUtils.TERN_JUMPTODEF_MSG);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -393,43 +441,18 @@ define(function (require, exports, module) {
|
||||
*/
|
||||
function handleJumptoDef(response) {
|
||||
|
||||
var file = response.file;
|
||||
var $deferredJump = pendingTernRequests[file];
|
||||
var file = response.file,
|
||||
offset = response.offset;
|
||||
|
||||
pendingTernRequests[file] = null;
|
||||
var $deferredJump = getPendingRequest(file, offset, HintUtils.TERN_JUMPTODEF_MSG);
|
||||
|
||||
// pendingTernRequests[file] = null;
|
||||
|
||||
if ($deferredJump) {
|
||||
$deferredJump.resolveWith(null, [response]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a pending request waiting for the tern-worker to complete.
|
||||
*
|
||||
* @param {string} file - the name of the file
|
||||
* @param {number} offset - the offset into the file the request is for
|
||||
* @param {string} type - the type of request
|
||||
* @return {jQuery.Promise} - the promise for the request
|
||||
*/
|
||||
function addPendingRequest(file, offset, type) {
|
||||
var requests,
|
||||
key = file + "@" + offset,
|
||||
$deferredRequest;
|
||||
if (CollectionUtils.hasProperty(pendingTernRequests, key)) {
|
||||
requests = pendingTernRequests[key];
|
||||
} else {
|
||||
requests = {};
|
||||
pendingTernRequests[key] = requests;
|
||||
}
|
||||
|
||||
if (CollectionUtils.hasProperty(requests, type)) {
|
||||
$deferredRequest = requests[type];
|
||||
} else {
|
||||
requests[type] = $deferredRequest = $.Deferred();
|
||||
}
|
||||
return $deferredRequest.promise();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Promise for the completions from TernJS, for the file & offset passed in.
|
||||
* @param {string} dir - the directory the file is in
|
||||
@@ -529,29 +552,6 @@ define(function (require, exports, module) {
|
||||
return {promise: $deferredHints.promise()};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get any pending $.Deferred object waiting on the specified file and request type
|
||||
* @param {string} file - the file
|
||||
* @param {number} offset - the offset in the file the request was at
|
||||
* @param {string} type - the type of request
|
||||
* @return {jQuery.Deferred} - the $.Deferred for the request
|
||||
*/
|
||||
function getPendingRequest(file, offset, type) {
|
||||
var key = file + "@" + offset;
|
||||
if (CollectionUtils.hasProperty(pendingTernRequests, key)) {
|
||||
var requests = pendingTernRequests[key],
|
||||
requestType = requests[type];
|
||||
|
||||
delete pendingTernRequests[key][type];
|
||||
|
||||
if (!Object.keys(requests).length) {
|
||||
delete pendingTernRequests[key];
|
||||
}
|
||||
|
||||
return requestType;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the response from the tern web worker when
|
||||
* it responds with the list of completions
|
||||
@@ -714,6 +714,7 @@ define(function (require, exports, module) {
|
||||
return resolvedFiles[newFile] !== undefined;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Do the work to initialize a code hinting session.
|
||||
*
|
||||
|
||||
@@ -34,7 +34,7 @@ importScripts("thirdparty/requirejs/require.js");
|
||||
require(["./HintUtils"], function (hintUtils) {
|
||||
HintUtils = hintUtils;
|
||||
var ternRequire = require.config({baseUrl: "./thirdparty"});
|
||||
ternRequire(["tern/lib/tern", "tern/plugin/requirejs"], function (tern, requirejs) {
|
||||
ternRequire(["tern/lib/tern", "tern/plugin/requirejs", "tern/plugin/doc_comment"], function (tern, requirejs, docComment) {
|
||||
Tern = tern;
|
||||
});
|
||||
});
|
||||
@@ -87,7 +87,7 @@ importScripts("thirdparty/requirejs/require.js");
|
||||
defs: env,
|
||||
async: true,
|
||||
getFile: getFile,
|
||||
plugins: {requirejs: {}}
|
||||
plugins: {requirejs: {}, doc_comment: true}
|
||||
};
|
||||
ternServer = new Tern.Server(ternOptions);
|
||||
|
||||
|
||||
+1
-1
Submodule src/extensions/default/JavaScriptCodeHints/thirdparty/acorn updated: f3c70d76ef...9eee5300db.
+1
-1
Submodule src/extensions/default/JavaScriptCodeHints/thirdparty/tern updated: 14a0211b6a...d5289c7f0c.
@@ -685,24 +685,6 @@ define(function (require, exports, module) {
|
||||
});
|
||||
});
|
||||
|
||||
it("should replace property hints but not following delimiters", function () {
|
||||
var start = { line: 6, ch: 0 },
|
||||
middle = { line: 6, ch: 4 },
|
||||
end = { line: 6, ch: 9 },
|
||||
endplus = { line: 6, ch: 10 };
|
||||
|
||||
testDoc.replaceRange("(A1.prop)", start, start);
|
||||
testEditor.setCursorPos(middle);
|
||||
var hintObj = expectHints(JSCodeHints.jsHintProvider);
|
||||
selectHint(JSCodeHints.jsHintProvider, hintObj, "propA");
|
||||
|
||||
runs(function () {
|
||||
expect(testEditor.getCursorPos()).toEqual(end);
|
||||
expect(testDoc.getRange(start, endplus)).toEqual("(A1.propA)");
|
||||
expect(testDoc.getLine(endplus.line).length).toEqual(10);
|
||||
});
|
||||
});
|
||||
|
||||
it("should list hints for string, as string assigned to 's', 's' assigned to 'r' and 'r' assigned to 't'", function () {
|
||||
var start = { line: 26, ch: 0 },
|
||||
middle = { line: 26, ch: 2 };
|
||||
@@ -896,7 +878,7 @@ define(function (require, exports, module) {
|
||||
testEditor.setCursorPos(testPos);
|
||||
var hintObj = expectHints(JSCodeHints.jsHintProvider);
|
||||
runs(function () {
|
||||
hintsPresentExact(hintObj, ["funFunc2Arg(f: fn(s: string, n: number) -> string) -> string"]);
|
||||
hintsPresentExact(hintObj, ["funFunc2Arg(f: fn(s: string, n: number) -> string)"]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -979,6 +961,24 @@ define(function (require, exports, module) {
|
||||
});
|
||||
});
|
||||
|
||||
it("should replace property hints but not following delimiters", function () {
|
||||
var start = { line: 6, ch: 0 },
|
||||
middle = { line: 6, ch: 4 },
|
||||
end = { line: 6, ch: 9 },
|
||||
endplus = { line: 6, ch: 10 };
|
||||
|
||||
testDoc.replaceRange("(A1.prop)", start, start);
|
||||
testEditor.setCursorPos(middle);
|
||||
var hintObj = expectHints(JSCodeHints.jsHintProvider);
|
||||
selectHint(JSCodeHints.jsHintProvider, hintObj, "propA");
|
||||
|
||||
runs(function () {
|
||||
expect(testEditor.getCursorPos()).toEqual(end);
|
||||
expect(testDoc.getRange(start, endplus)).toEqual("(A1.propA)");
|
||||
expect(testDoc.getLine(endplus.line).length).toEqual(10);
|
||||
});
|
||||
});
|
||||
|
||||
it("should jump to var", function () {
|
||||
var start = { line: 44, ch: 10 };
|
||||
|
||||
@@ -1001,7 +1001,7 @@ define(function (require, exports, module) {
|
||||
|
||||
testEditor.setCursorPos(start);
|
||||
runs(function () {
|
||||
editorJumped({line: 4, ch: 34, file: "MyModule.js"}); //jump to another file
|
||||
editorJumped({line: 4, ch: 13, file: "MyModule.js"}); //jump to another file
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1010,7 +1010,7 @@ define(function (require, exports, module) {
|
||||
|
||||
testEditor.setCursorPos(start);
|
||||
runs(function () {
|
||||
editorJumped({line: 56, ch: 1}); //jump to prototype.calc
|
||||
editorJumped({line: 53, ch: 21}); //jump to prototype.calc
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1037,7 +1037,7 @@ define(function (require, exports, module) {
|
||||
|
||||
testEditor.setCursorPos(start);
|
||||
runs(function () {
|
||||
editorJumped({line: 94, ch: 45});
|
||||
editorJumped({line: 94, ch: 17});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1117,9 +1117,7 @@ define(function (require, exports, module) {
|
||||
runs(function () {
|
||||
testEditor.setCursorPos(start);
|
||||
var hintObj = expectHints(JSCodeHints.jsHintProvider);
|
||||
runs(function () {
|
||||
hintsPresentExact(hintObj, ["a", "b", "b1", "c", "d"]);
|
||||
});
|
||||
hintsPresentExact(hintObj, ["a", "b", "b1", "c", "d"]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user