Skip to content

Commit eb5db01

Browse files
committed
fix(lsp): show the function name in parameter hints, fix unbalanced "(("
The LSP parameter-hint popup rendered "((tableName: any)" - a doubled, unbalanced paren and no function name. requestParameterHints dropped the signature label and activeSignature, so the provider couldn't supply the function name; the manager then fell back to editor.getToken() at the caret, which is the just-typed "(". - LSPClient: pass the full signature label and activeSignature through. - DefaultProviders: use the active signature (not all overloads merged into one param list) and derive the function name from its label. - ParameterHintsManager: use the provider-supplied functionName when present, falling back to the editor token only when absent (preserves Tern behavior). Now renders e.g. "getTableIndexes(tableName: any)" - named and balanced.
1 parent 5fcb306 commit eb5db01

3 files changed

Lines changed: 39 additions & 17 deletions

File tree

src/features/ParameterHintsManager.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,16 @@ define(function (require, exports, module) {
269269
}
270270

271271
if (hints.parameters.length > 0) {
272-
let token = editor.getToken(hints.functionCallPos);
273-
_formatParameterHint(token.string, hints.parameters, appendSeparators, appendParameter);
272+
// Prefer a function name supplied by the provider (LSP signatureHelp gives the full
273+
// signature label). Only fall back to the editor token for providers that locate the call
274+
// site themselves (Tern sets functionCallPos); without that fallback guard, an LSP hint -
275+
// whose functionCallPos is undefined - would read the token at the caret, i.e. the just
276+
// typed "(", and render an unbalanced "((".
277+
let functionName = hints.functionName;
278+
if (functionName == null) {
279+
functionName = editor.getToken(hints.functionCallPos).string;
280+
}
281+
_formatParameterHint(functionName, hints.parameters, appendSeparators, appendParameter);
274282
} else {
275283
$hintContent.append(_.escape(Strings.NO_ARGUMENTS));
276284
}

src/languageTools/DefaultProviders.js

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -630,28 +630,35 @@ define(function (require, exports, module) {
630630
cursorPos: pos
631631
}).done(function (msgObj) {
632632
let paramList = [];
633-
let label;
634-
let activeParameter;
635633
if (msgObj) {
636-
let res;
637-
res = msgObj.signatures;
638-
activeParameter = msgObj.activeParameter;
634+
let res = msgObj.signatures;
635+
let activeParameter = msgObj.activeParameter;
639636
if (res && res.length) {
640-
res.forEach(function (element) {
641-
label = element.documentation;
642-
let param = element.parameters;
643-
param.forEach(ele => {
644-
paramList.push({
645-
label: ele.label,
646-
documentation: ele.documentation
647-
});
637+
// Use the active signature (not all of them concatenated - overloads would
638+
// otherwise merge their parameters into one bogus list).
639+
let sig = res[msgObj.activeSignature || 0] || res[0];
640+
(sig.parameters || []).forEach(function (ele) {
641+
paramList.push({
642+
label: ele.label,
643+
documentation: ele.documentation
648644
});
649645
});
650646

647+
// The function name for the popup header, taken from the signature label
648+
// (everything before the parameter list "("). Without this the manager falls back
649+
// to the editor token at the caret - which is the just-typed "(" - producing an
650+
// unbalanced "((tableName: any)".
651+
let functionName = "";
652+
if (typeof sig.label === "string") {
653+
let paren = sig.label.indexOf("(");
654+
functionName = (paren >= 0 ? sig.label.slice(0, paren) : sig.label).trim();
655+
}
656+
651657
$deferredHints.resolve({
652658
parameters: paramList,
653659
currentIndex: activeParameter,
654-
functionDocumentation: label
660+
functionDocumentation: sig.documentation,
661+
functionName: functionName
655662
});
656663
} else {
657664
$deferredHints.reject();

src/languageTools/LSPClient.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,9 @@ define(function (require, exports, module) {
364364
}
365365
const signatures = result.signatures.map(function (sig) {
366366
return {
367+
// Full signature string (e.g. "getTableIndexes(tableName: any): Promise<…>") -
368+
// the provider derives the function name from it for the parameter-hint popup.
369+
label: sig.label,
367370
documentation: _markupToString(sig.documentation) || sig.label,
368371
parameters: (sig.parameters || []).map(function (p) {
369372
return {
@@ -373,7 +376,11 @@ define(function (require, exports, module) {
373376
})
374377
};
375378
});
376-
deferred.resolve({ signatures: signatures, activeParameter: result.activeParameter });
379+
deferred.resolve({
380+
signatures: signatures,
381+
activeSignature: result.activeSignature,
382+
activeParameter: result.activeParameter
383+
});
377384
} catch (err) {
378385
console.warn("[LSP] request failed:", err && (err.message || err));
379386
deferred.reject(err);

0 commit comments

Comments
 (0)