From bb58558e64d59b705118ab467b896c32af81c217 Mon Sep 17 00:00:00 2001 From: Sergio Baidon Date: Thu, 13 Sep 2018 16:38:06 -0500 Subject: [PATCH] Fix signature help not showing in block body bug --- src/services/signatureHelp.ts | 7 ++++--- .../fourslash/signatureHelpInAdjacentBlockBody.ts | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 tests/cases/fourslash/signatureHelpInAdjacentBlockBody.ts diff --git a/src/services/signatureHelp.ts b/src/services/signatureHelp.ts index 29a2b728db2..d63e16ce801 100644 --- a/src/services/signatureHelp.ts +++ b/src/services/signatureHelp.ts @@ -38,7 +38,8 @@ namespace ts.SignatureHelp { return undefined; } - const argumentInfo = getContainingArgumentInfo(startingToken, position, sourceFile, typeChecker); + const isManuallyInvoked = !!triggerReason && triggerReason.kind === "invoked"; + const argumentInfo = getContainingArgumentInfo(startingToken, position, sourceFile, typeChecker, isManuallyInvoked); if (!argumentInfo) return undefined; cancellationToken.throwIfCancellationRequested(); @@ -450,8 +451,8 @@ namespace ts.SignatureHelp { return createTextSpan(applicableSpanStart, applicableSpanEnd - applicableSpanStart); } - function getContainingArgumentInfo(node: Node, position: number, sourceFile: SourceFile, checker: TypeChecker): ArgumentListInfo | undefined { - for (let n = node; !isBlock(n) && !isSourceFile(n); n = n.parent) { + function getContainingArgumentInfo(node: Node, position: number, sourceFile: SourceFile, checker: TypeChecker, isManuallyInvoked: boolean): ArgumentListInfo | undefined { + for (let n = node; isManuallyInvoked || (!isBlock(n) && !isSourceFile(n)); n = n.parent) { // If the node is not a subspan of its parent, this is a big problem. // There have been crashes that might be caused by this violation. Debug.assert(rangeContainsRange(n.parent, n), "Not a subspan", () => `Child: ${Debug.showSyntaxKind(n)}, parent: ${Debug.showSyntaxKind(n.parent)}`); diff --git a/tests/cases/fourslash/signatureHelpInAdjacentBlockBody.ts b/tests/cases/fourslash/signatureHelpInAdjacentBlockBody.ts new file mode 100644 index 00000000000..576f3a28b47 --- /dev/null +++ b/tests/cases/fourslash/signatureHelpInAdjacentBlockBody.ts @@ -0,0 +1,15 @@ +/// + +////declare function foo(...args); +//// +////foo(() => {/*1*/}/*2*/) + +goTo.marker("1"); +verify.signatureHelpPresentForTriggerReason({ + kind: "invoked", +}); + +goTo.marker("2"); +verify.signatureHelpPresentForTriggerReason({ + kind: "invoked", +}); \ No newline at end of file