Skip to content
This repository was archived by the owner on Nov 18, 2022. It is now read-only.

Commit 8a1dcfe

Browse files
author
Radu M
committed
Prevent hover with function signature from being shown when declaring the function
Signed-off-by: Radu M <[email protected]>
1 parent c85bf69 commit 8a1dcfe

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/providers/signatureHelpProvider.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class SignatureHelpProvider implements vscode.SignatureHelpProvider {
2525
document,
2626
position,
2727
token,
28-
).then(hover => this.hoverToSignatureHelp(hover));
28+
).then(hover => this.hoverToSignatureHelp(hover, position, document));
2929
} else if (context.triggerCharacter === ',') {
3030
if (
3131
this.previousFunctionPosition &&
@@ -36,7 +36,7 @@ export class SignatureHelpProvider implements vscode.SignatureHelpProvider {
3636
document,
3737
this.previousFunctionPosition,
3838
token,
39-
).then(hover => this.hoverToSignatureHelp(hover));
39+
).then(hover => this.hoverToSignatureHelp(hover, position, document));
4040
} else {
4141
return null;
4242
}
@@ -71,6 +71,8 @@ export class SignatureHelpProvider implements vscode.SignatureHelpProvider {
7171

7272
private hoverToSignatureHelp(
7373
hover: vscode.Hover,
74+
position: vscode.Position,
75+
document: vscode.TextDocument,
7476
): vscode.SignatureHelp | undefined {
7577
/*
7678
The contents of a hover result has the following structure:
@@ -114,8 +116,13 @@ export class SignatureHelpProvider implements vscode.SignatureHelpProvider {
114116
.replace('```', '');
115117

116118
// the signature help tooltip is activated on `(` or `,`
117-
// and without this, it could show the tooltip after non-functions
118-
if (!label.includes('fn')) {
119+
// here we make sure the label received is for a function,
120+
// and that we are not showing the hover for the same line
121+
// where we are declaring a function.
122+
if (
123+
!label.includes('fn') ||
124+
document.lineAt(position.line).text.includes('fn ')
125+
) {
119126
return undefined;
120127
}
121128

0 commit comments

Comments
 (0)