Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Show JS parameter hint #4637

Merged
merged 29 commits into from
Aug 18, 2013
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
d86ae75
Function Hints
Jul 22, 2013
a176d7e
parameter hint fixes
Jul 25, 2013
cc6d344
refactor
Jul 25, 2013
6ffa193
fix unit tests and move function hint type parsing into the tern worker.
Jul 26, 2013
088c6c9
Add HintUtil2.formatParameterHint and fix bugs
Jul 29, 2013
e4d8d66
rename ScopeManager.requestFunctionHint to ScopeManager.requestParame…
Jul 30, 2013
a147ef5
Fix exception after picking hint from code hints combo.
Jul 30, 2013
9752790
HintUtils2.formatParameterHint always returns the format string
Jul 31, 2013
eceea10
improve error handling
Aug 2, 2013
9e15de2
Function Hints
Jul 22, 2013
a9c9167
parameter hint fixes
Jul 25, 2013
5205cba
refactor
Jul 25, 2013
adb56c0
fix unit tests and move function hint type parsing into the tern worker.
Jul 26, 2013
8ae1abe
Add HintUtil2.formatParameterHint and fix bugs
Jul 29, 2013
d837cd1
rename ScopeManager.requestFunctionHint to ScopeManager.requestParame…
Jul 30, 2013
3492796
Fix exception after picking hint from code hints combo.
Jul 30, 2013
b41ad22
HintUtils2.formatParameterHint always returns the format string
Jul 31, 2013
794c5d1
improve error handling
Aug 2, 2013
7cc3191
fix bug in failed path of ParameterHintManager.popUpHint
Aug 2, 2013
a57289b
Merge branch 'fn-param-hints' of http://github.com/dloverin/brackets …
Aug 2, 2013
d9acb97
fix bad merge
Aug 2, 2013
4969b77
undo accidental change of tern
Aug 2, 2013
c994eaf
Fix issue where "<no parameters>" would be hinted when Tern could not…
Aug 5, 2013
82dd657
jsdoc fixes
Aug 5, 2013
388ddcf
change function-hint-container left and right padding from 1 to 3
Aug 5, 2013
dd6b19d
Add feature to hint on '(' key and fix typos
Aug 12, 2013
d95544d
remove half-done feature to pop up parameter hints on '(' key
Aug 12, 2013
0c892a9
Work around issue https://github.com/marijnh/tern/issues/207 by calli…
Aug 16, 2013
72d7b2b
allow 'empty' updates for parameter hints
Aug 16, 2013
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
2 changes: 1 addition & 1 deletion src/command/CommandManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ define(function (require, exports, module) {

if (command) {
try {
$(exports).triggerHandler("beforeExecuteCommand");
$(exports).triggerHandler("beforeExecuteCommand", id);
} catch (err) {
console.error(err);
}
Expand Down
4 changes: 2 additions & 2 deletions src/extensions/default/JavaScriptCodeHints/HintUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
define(function (require, exports, module) {
"use strict";

var acorn = require("thirdparty/acorn/acorn");
var Acorn = require("thirdparty/acorn/acorn");

var LANGUAGE_ID = "javascript",
HTML_LANGUAGE_ID = "html",
Expand Down Expand Up @@ -64,7 +64,7 @@ define(function (require, exports, module) {
i;

for (i = 0; i < key.length; i++) {
result = acorn.isIdentifierChar(key.charCodeAt(i));
result = Acorn.isIdentifierChar(key.charCodeAt(i));
if (!result) {
break;
}
Expand Down
109 changes: 109 additions & 0 deletions src/extensions/default/JavaScriptCodeHints/HintUtils2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
* Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/

/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50, regexp: true */
/*global define */

/**
* HintUtils2 was created as a place to put utilities that do not require third party dependencies so
* they can be used by tern-worker.js and other JS files.
* This is done because of the require config in tern-worker.js needed to load tern libraries. Libraries
* that include, say "acorn", will fail to load.
*/
define(function (require, exports, module) {
"use strict";

/**
* Format the given parameter array. Handles separators between
* parameters, syntax for optional parameters, and the order of the
* parameter type and parameter name.
*
* @param {!Array.<{name: string, type: string, isOptional: boolean}>} params -
* array of parameter descriptors
* @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
*/
function formatParameterHint(params, appendSeparators, appendParameter, typesOnly) {
var result = "",
pendingOptional = false;

params.forEach(function (value, i) {
var param = value.type,
separators = "";

if (value.isOptional) {
// if an optional param is following by an optional parameter, then
// terminate the bracket. Otherwise enclose a required parameter
// in the same bracket.
if (pendingOptional) {
separators += "]";
}

pendingOptional = true;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the current param is not optional but the previous one is optional, then we need to append "]" in the "else" block and reset pendingOptional to false. issue #4748


if (i > 0) {
separators += ", ";
}

if (value.isOptional) {
separators += "[";
}

if (appendSeparators) {
appendSeparators(separators);
}

result += separators;

if (!typesOnly) {
param += " " + value.name;
}

if (appendParameter) {
appendParameter(param, i);
}

result += param;

});

if (pendingOptional) {
if (appendSeparators) {
appendSeparators("]");
}

result += "]";
}

return result;
}

exports.formatParameterHint = formatParameterHint;
});
Loading