diff --git a/src/extensions/default/JavaScriptCodeHints/ParameterHintManager.js b/src/extensions/default/JavaScriptCodeHints/ParameterHintManager.js index 0c9654b6c98..e1b506e042d 100644 --- a/src/extensions/default/JavaScriptCodeHints/ParameterHintManager.js +++ b/src/extensions/default/JavaScriptCodeHints/ParameterHintManager.js @@ -132,7 +132,7 @@ define(function (require, exports, module) { * * @param {{inFunctionCall: boolean, functionCallPos: {line: number, ch: number}}} functionInfo - * tells if the caret is in a function call and the position - * of the function call. + * of the function call. */ function formatHint(functionInfo) { var hints = session.getParameterHint(functionInfo.functionCallPos), @@ -197,7 +197,7 @@ define(function (require, exports, module) { * Test if the function call at the cursor is different from the currently displayed * function hint. * - * @param functionCallPos + * @param {{line:number, ch:number}} functionCallPos - the offset of the function call. * @return {boolean} */ function hasFunctionCallPosChanged(functionCallPos) { @@ -237,7 +237,7 @@ define(function (require, exports, module) { * figuring it out again. * @return {jQuery.Promise} - The promise will not complete until the * hint has completed. Returns null, if the function hint is already - * displayed or the there is no function hint at the cursor. + * displayed or there is no function hint at the cursor. * */ function popUpHint(pushExistingHint, hint, functionInfo) { @@ -304,7 +304,7 @@ define(function (require, exports, module) { var functionInfo = session.getFunctionInfo(); if (functionInfo.inFunctionCall) { - // If in a different function hint, then dismiss the old one a + // If in a different function hint, then dismiss the old one and // display the new one if there is one on the stack if (hasFunctionCallPosChanged(functionInfo.functionCallPos)) { if (popHintFromStack()) { @@ -334,7 +334,7 @@ define(function (require, exports, module) { /** * Enable cursor tracking in the current session. * - * @param {Session} session - session to stop cursor tracking on. + * @param {Session} session - session to start cursor tracking on. */ function startCursorTracking(session) { $(session.editor).on("cursorActivity", handleCursorActivity); diff --git a/src/extensions/default/JavaScriptCodeHints/ScopeManager.js b/src/extensions/default/JavaScriptCodeHints/ScopeManager.js index b1fd6802dbb..c244da84e72 100644 --- a/src/extensions/default/JavaScriptCodeHints/ScopeManager.js +++ b/src/extensions/default/JavaScriptCodeHints/ScopeManager.js @@ -1282,7 +1282,7 @@ define(function (require, exports, module) { * Request a parameter hint from Tern. * * @param {Session} session - the active hinting session - * @param {{line: number, ch: number}} functionOffset - the offset the function call. + * @param {{line: number, ch: number}} functionOffset - the offset of the function call. * @return {jQuery.Promise} - The promise will not complete until the * hint has completed. */ diff --git a/src/extensions/default/JavaScriptCodeHints/Session.js b/src/extensions/default/JavaScriptCodeHints/Session.js index 5534cbdcc7e..34a2a7ead5a 100644 --- a/src/extensions/default/JavaScriptCodeHints/Session.js +++ b/src/extensions/default/JavaScriptCodeHints/Session.js @@ -635,7 +635,7 @@ define(function (require, exports, module) { /** * The position of the function call for the current fnType. * - * @param functionCallPos + * @param {{line:number, ch:number}} functionCallPos - the offset of the function call. */ Session.prototype.setFunctionCallPos = function (functionCallPos) { this.functionCallPos = functionCallPos; diff --git a/src/extensions/default/JavaScriptQuickEdit/unittests.js b/src/extensions/default/JavaScriptQuickEdit/unittests.js index 7f438ffb221..6cd8e927a19 100644 --- a/src/extensions/default/JavaScriptQuickEdit/unittests.js +++ b/src/extensions/default/JavaScriptQuickEdit/unittests.js @@ -273,7 +273,8 @@ define(function (require, exports, module) { }); describe("Code hints tests within quick edit window ", function () { - var JSCodeHints; + var JSCodeHints, + ParameterHintManager; /* * Ask provider for hints at current cursor position; expect it to @@ -343,6 +344,76 @@ define(function (require, exports, module) { }); } + /* + * Wait for a hint response object to resolve, then apply a callback + * to the result + * + * @param {Object + jQuery.Deferred} hintObj - a hint response object, + * possibly deferred + * @param {Function} callback - the callback to apply to the resolved + * hint response object + */ + function _waitForParameterHint(hintObj, callback) { + var complete = false, + hint = null; + + hintObj.done(function () { + hint = JSCodeHints.getSession().getParameterHint(); + complete = true; + }); + + waitsFor(function () { + return complete; + }, "Expected parameter hint did not resolve", 3000); + + runs(function () { callback(hint); }); + } + + /** + * Show a function hint based on the code at the cursor. Verify the + * hint matches the passed in value. + * + * @param {Array<{name: string, type: string, isOptional: boolean}>} + * expectedParams - array of records, where each element of the array + * describes a function parameter. If null, then no hint is expected. + * @param {number} expectedParameter - the parameter at cursor. + */ + function expectParameterHint(expectedParams, expectedParameter) { + var request = ParameterHintManager.popUpHint(); + if (expectedParams === null) { + expect(request).toBe(null); + return; + } + + function expectHint(hint) { + var params = hint.parameters, + n = params.length, + i; + + // compare params to expected params + expect(params.length).toBe(expectedParams.length); + expect(hint.currentIndex).toBe(expectedParameter); + + for (i = 0; i < n; i++) { + + expect(params[i].name).toBe(expectedParams[i].name); + expect(params[i].type).toBe(expectedParams[i].type); + if (params[i].isOptional) { + expect(expectedParams[i].isOptional).toBeTruthy(); + } else { + expect(expectedParams[i].isOptional).toBeFalsy(); + } + } + + } + + if (request) { + _waitForParameterHint(request, expectHint); + } else { + expectHint(JSCodeHints.getSession().getParameterHint()); + } + } + /** * Wait for the editor to change positions, such as after a jump to * definition has been triggered. Will timeout after 3 seconds @@ -390,6 +461,7 @@ define(function (require, exports, module) { var extensionRequire = testWindow.brackets.getModule("utils/ExtensionLoader"). getRequireContextForExtension("JavaScriptCodeHints"); JSCodeHints = extensionRequire("main"); + ParameterHintManager = extensionRequire("ParameterHintManager"); } beforeEach(function () { @@ -399,6 +471,7 @@ define(function (require, exports, module) { afterEach(function () { JSCodeHints = null; + ParameterHintManager = null; }); it("should see code hint lists in quick editor", function () { @@ -414,9 +487,7 @@ define(function (require, exports, module) { runs(function () { testEditor = EditorManager.getActiveEditor(); testEditor.setCursorPos(testPos); - var hintObj = expectHints(JSCodeHints.jsHintProvider); - hintsPresentExact(hintObj, ["getMonthName(mo: number) -> string"]); - + expectParameterHint([{name: "mo", type: "Number"}], 0); }); });