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

Commit 5de9d5c

Browse files
committed
Merge pull request #4637 from dloverin/fn-param-hints
Show JS parameter hint
2 parents 32025e6 + 72d7b2b commit 5de9d5c

File tree

15 files changed

+1470
-227
lines changed

15 files changed

+1470
-227
lines changed

src/command/CommandManager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ define(function (require, exports, module) {
237237

238238
if (command) {
239239
try {
240-
$(exports).triggerHandler("beforeExecuteCommand");
240+
$(exports).triggerHandler("beforeExecuteCommand", id);
241241
} catch (err) {
242242
console.error(err);
243243
}

src/extensions/default/JavaScriptCodeHints/HintUtils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
define(function (require, exports, module) {
2828
"use strict";
2929

30-
var acorn = require("thirdparty/acorn/acorn");
30+
var Acorn = require("thirdparty/acorn/acorn");
3131

3232
var LANGUAGE_ID = "javascript",
3333
HTML_LANGUAGE_ID = "html",
@@ -64,7 +64,7 @@ define(function (require, exports, module) {
6464
i;
6565

6666
for (i = 0; i < key.length; i++) {
67-
result = acorn.isIdentifierChar(key.charCodeAt(i));
67+
result = Acorn.isIdentifierChar(key.charCodeAt(i));
6868
if (!result) {
6969
break;
7070
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
* Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a
5+
* copy of this software and associated documentation files (the "Software"),
6+
* to deal in the Software without restriction, including without limitation
7+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
* and/or sell copies of the Software, and to permit persons to whom the
9+
* Software is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20+
* DEALINGS IN THE SOFTWARE.
21+
*
22+
*/
23+
24+
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50, regexp: true */
25+
/*global define */
26+
27+
/**
28+
* HintUtils2 was created as a place to put utilities that do not require third party dependencies so
29+
* they can be used by tern-worker.js and other JS files.
30+
* This is done because of the require config in tern-worker.js needed to load tern libraries. Libraries
31+
* that include, say "acorn", will fail to load.
32+
*/
33+
define(function (require, exports, module) {
34+
"use strict";
35+
36+
/**
37+
* Format the given parameter array. Handles separators between
38+
* parameters, syntax for optional parameters, and the order of the
39+
* parameter type and parameter name.
40+
*
41+
* @param {!Array.<{name: string, type: string, isOptional: boolean}>} params -
42+
* array of parameter descriptors
43+
* @param {function(string)=} appendSeparators - callback function to append separators.
44+
* The separator is passed to the callback.
45+
* @param {function(string, number)=} appendParameter - callback function to append parameter.
46+
* The formatted parameter type and name is passed to the callback along with the
47+
* current index of the parameter.
48+
* @param {boolean=} typesOnly - only show parameter types. The
49+
* default behavior is to include both parameter names and types.
50+
* @return {string} - formatted parameter hint
51+
*/
52+
function formatParameterHint(params, appendSeparators, appendParameter, typesOnly) {
53+
var result = "",
54+
pendingOptional = false;
55+
56+
params.forEach(function (value, i) {
57+
var param = value.type,
58+
separators = "";
59+
60+
if (value.isOptional) {
61+
// if an optional param is following by an optional parameter, then
62+
// terminate the bracket. Otherwise enclose a required parameter
63+
// in the same bracket.
64+
if (pendingOptional) {
65+
separators += "]";
66+
}
67+
68+
pendingOptional = true;
69+
}
70+
71+
if (i > 0) {
72+
separators += ", ";
73+
}
74+
75+
if (value.isOptional) {
76+
separators += "[";
77+
}
78+
79+
if (appendSeparators) {
80+
appendSeparators(separators);
81+
}
82+
83+
result += separators;
84+
85+
if (!typesOnly) {
86+
param += " " + value.name;
87+
}
88+
89+
if (appendParameter) {
90+
appendParameter(param, i);
91+
}
92+
93+
result += param;
94+
95+
});
96+
97+
if (pendingOptional) {
98+
if (appendSeparators) {
99+
appendSeparators("]");
100+
}
101+
102+
result += "]";
103+
}
104+
105+
return result;
106+
}
107+
108+
exports.formatParameterHint = formatParameterHint;
109+
});

0 commit comments

Comments
 (0)