mirror of
https://github.com/RustyRaptor/brackets.git
synced 2026-12-04 00:15:22 -07:00
rename ScopeManager.requestFunctionHint to ScopeManager.requestParameterHint.
add unittests for HintUtils.formatParameterHint
This commit is contained in:
1 parent
8ae1abe419
commit
d837cd19e2
5 files changed
+88
-18
No files matched your search
@@ -36,17 +36,19 @@ define(function (require, exports, module) {
|
||||
/**
|
||||
* Format the given parameter array. Handles separators between
|
||||
* parameters, syntax for optional parameters, and the order of the
|
||||
* parameter type and parameter name.
|
||||
* parameter type and parameter name. If the appendSeparators parameter
|
||||
* is supplied, the appendParameter is also required.
|
||||
*
|
||||
* @param {!Array.<name: {string}, type: {string},
|
||||
* isOptional: {boolean}>} params - array of parameter descriptors
|
||||
* @param {function(string)} appendSeparators - callback function to append separators.
|
||||
* @param {function(string)=} appendSeparators - callback function to append separators.
|
||||
* The separator is passed to the callback.
|
||||
* @param {function(string, number)} appendParameter - callback function to append parameter.
|
||||
* The formatted parameter type and name is passed to the callback along with the
|
||||
* current index of the parameter.
|
||||
* @param {boolean=} typesOnly - only show parameter types. The
|
||||
* default behavior is to include both parameter names and types.
|
||||
* @return {string} - formatted parameter hint unless appendSeparators
|
||||
*/
|
||||
function formatParameterHint(params, appendSeparators, appendParameter, typesOnly) {
|
||||
var result = "",
|
||||
@@ -66,29 +68,44 @@ define(function (require, exports, module) {
|
||||
}
|
||||
|
||||
if (i > 0) {
|
||||
result += " ";
|
||||
separators += ", ";
|
||||
}
|
||||
|
||||
separators += "[";
|
||||
pendingOptional = true;
|
||||
} else {
|
||||
if (i > 0) {
|
||||
separators += ", ";
|
||||
}
|
||||
}
|
||||
|
||||
if (i > 0) {
|
||||
separators += ", ";
|
||||
if (appendSeparators) {
|
||||
appendSeparators(separators);
|
||||
} else {
|
||||
result += separators;
|
||||
}
|
||||
|
||||
appendSeparators(separators);
|
||||
|
||||
if (!typesOnly) {
|
||||
param += " " + value.name;
|
||||
}
|
||||
|
||||
appendParameter(param, i);
|
||||
if (appendParameter) {
|
||||
appendParameter(param, i);
|
||||
} else {
|
||||
result += param;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
if (pendingOptional) {
|
||||
appendSeparators("]");
|
||||
if (appendSeparators) {
|
||||
appendSeparators("]");
|
||||
} else {
|
||||
result += "]";
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
exports.formatParameterHint = formatParameterHint;
|
||||
|
||||
@@ -268,7 +268,7 @@ define(function (require, exports, module) {
|
||||
var $deferredPopUp = $.Deferred();
|
||||
|
||||
if (!hint) {
|
||||
request = ScopeManager.requestFunctionHint(session, functionInfo.functionCallPos);
|
||||
request = ScopeManager.requestParameterHint(session, functionInfo.functionCallPos);
|
||||
} else {
|
||||
session.setFnType(hint);
|
||||
request = $.Deferred();
|
||||
|
||||
@@ -1274,14 +1274,14 @@ define(function (require, exports, module) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Request a function type hint from Tern.
|
||||
* Request a parameter hint from Tern.
|
||||
*
|
||||
* @param {Session} session - the active hinting session
|
||||
* @param {{line: number, ch: number}} functionOffset - the offset the function call.
|
||||
* @return {jQuery.Promise} - The promise will not complete until the
|
||||
* hint has completed.
|
||||
*/
|
||||
function requestFunctionHint(session, functionOffset) {
|
||||
function requestParameterHint(session, functionOffset) {
|
||||
var $deferredHints = $.Deferred(),
|
||||
fileInfo = getFileInfo(session),
|
||||
offset = getOffset(session, fileInfo, functionOffset),
|
||||
@@ -1429,7 +1429,7 @@ define(function (require, exports, module) {
|
||||
exports.handleFileChange = handleFileChange;
|
||||
exports.requestHints = requestHints;
|
||||
exports.requestJumptoDef = requestJumptoDef;
|
||||
exports.requestFunctionHint = requestFunctionHint;
|
||||
exports.requestParameterHint = requestParameterHint;
|
||||
exports.handleProjectClose = handleProjectClose;
|
||||
exports.handleProjectOpen = handleProjectOpen;
|
||||
|
||||
|
||||
@@ -382,11 +382,7 @@ importScripts("thirdparty/requirejs/require.js");
|
||||
var result = "function(",
|
||||
params = processInferFnTypeParameters(inferType);
|
||||
|
||||
function appendValue(value) {
|
||||
result += value;
|
||||
}
|
||||
|
||||
HintUtils2.formatParameterHint(params, appendValue, appendValue, true);
|
||||
result += HintUtils2.formatParameterHint(params, null, null, true);
|
||||
if (inferType.retval) {
|
||||
result += "):";
|
||||
result += inferTypeToString(inferType.retval);
|
||||
|
||||
@@ -40,6 +40,7 @@ define(function (require, exports, module) {
|
||||
Preferences = require("Preferences"),
|
||||
ScopeManager = require("ScopeManager"),
|
||||
HintUtils = require("HintUtils"),
|
||||
HintUtils2 = require("HintUtils2"),
|
||||
ParameterHintManager = require("ParameterHintManager");
|
||||
|
||||
var extensionPath = FileUtils.getNativeModuleDirectoryPath(module),
|
||||
@@ -1804,5 +1805,61 @@ define(function (require, exports, module) {
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe("JavaScript Code Hinting format parameters tests", function () {
|
||||
|
||||
it("should format parameters with no params", function () {
|
||||
var params = [];
|
||||
|
||||
expect(HintUtils2.formatParameterHint(params)).toBe("");
|
||||
});
|
||||
|
||||
it("should format parameters with one param", function () {
|
||||
var params = [{name: "param1", type: "String"}];
|
||||
|
||||
expect(HintUtils2.formatParameterHint(params)).toBe("String param1");
|
||||
});
|
||||
|
||||
it("should format parameters with one optional param", function () {
|
||||
var params = [{name: "param1", type: "String", isOptional: true}];
|
||||
|
||||
expect(HintUtils2.formatParameterHint(params)).toBe("[String param1]");
|
||||
});
|
||||
|
||||
it("should format parameters with one required, one optional param", function () {
|
||||
var params = [{name: "param1", type: "String"},
|
||||
{name: "param2", type: "String", isOptional: true}];
|
||||
|
||||
expect(HintUtils2.formatParameterHint(params)).toBe("String param1, [String param2]");
|
||||
});
|
||||
|
||||
it("should format parameters with required param following an optional param", function () {
|
||||
var params = [{name: "param1", type: "String"},
|
||||
{name: "param2", type: "String", isOptional: true},
|
||||
{name: "param3", type: "String"}];
|
||||
|
||||
expect(HintUtils2.formatParameterHint(params)).toBe("String param1, [String param2, String param3]");
|
||||
});
|
||||
|
||||
it("should format parameters with optional param following an optional param", function () {
|
||||
var params = [{name: "param1", type: "String"},
|
||||
{name: "param2", type: "String", isOptional: true},
|
||||
{name: "param3", type: "String", isOptional: true}];
|
||||
|
||||
expect(HintUtils2.formatParameterHint(params)).toBe("String param1, [String param2], [String param3]");
|
||||
});
|
||||
|
||||
it("should format parameters with optional param following optional and required params", function () {
|
||||
var params = [{name: "param1", type: "String"},
|
||||
{name: "param2", type: "String", isOptional: true},
|
||||
{name: "param3", type: "String"},
|
||||
{name: "param4", type: "String", isOptional: true}];
|
||||
|
||||
expect(HintUtils2.formatParameterHint(params)).toBe("String param1, [String param2, String param3], [String param4]");
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user