Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/default/JavaScriptCodeHints/ScopeManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/default/JavaScriptCodeHints/Session.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
79 changes: 75 additions & 4 deletions src/extensions/default/JavaScriptQuickEdit/unittests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 () {
Expand All @@ -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 () {
Expand All @@ -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);
});
});

Expand Down