This repository has been archived by the owner on Sep 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Show JS parameter hint #4637
Merged
Merged
Show JS parameter hint #4637
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
d86ae75
Function Hints
a176d7e
parameter hint fixes
cc6d344
refactor
6ffa193
fix unit tests and move function hint type parsing into the tern worker.
088c6c9
Add HintUtil2.formatParameterHint and fix bugs
e4d8d66
rename ScopeManager.requestFunctionHint to ScopeManager.requestParame…
a147ef5
Fix exception after picking hint from code hints combo.
9752790
HintUtils2.formatParameterHint always returns the format string
eceea10
improve error handling
9e15de2
Function Hints
a9c9167
parameter hint fixes
5205cba
refactor
adb56c0
fix unit tests and move function hint type parsing into the tern worker.
8ae1abe
Add HintUtil2.formatParameterHint and fix bugs
d837cd1
rename ScopeManager.requestFunctionHint to ScopeManager.requestParame…
3492796
Fix exception after picking hint from code hints combo.
b41ad22
HintUtils2.formatParameterHint always returns the format string
794c5d1
improve error handling
7cc3191
fix bug in failed path of ParameterHintManager.popUpHint
a57289b
Merge branch 'fn-param-hints' of http://github.com/dloverin/brackets …
d9acb97
fix bad merge
4969b77
undo accidental change of tern
c994eaf
Fix issue where "<no parameters>" would be hinted when Tern could not…
82dd657
jsdoc fixes
388ddcf
change function-hint-container left and right padding from 1 to 3
dd6b19d
Add feature to hint on '(' key and fix typos
d95544d
remove half-done feature to pop up parameter hints on '(' key
0c892a9
Work around issue https://github.com/marijnh/tern/issues/207 by calli…
72d7b2b
allow 'empty' updates for parameter hints
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
src/extensions/default/JavaScriptCodeHints/HintUtils2.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
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; | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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