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

Commit 3630a96

Browse files
committed
Additional check to avoid showing signature help for non-functions
1 parent 3b529cf commit 3630a96

File tree

1 file changed

+9
-32
lines changed

1 file changed

+9
-32
lines changed

src/providers/signatureHelpProvider.ts

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,15 @@ export class SignatureHelpProvider implements vscode.SignatureHelpProvider {
2525
document,
2626
position,
2727
token,
28-
).then(hover => {
29-
return this.hoverToSignatureHelp(hover);
30-
});
28+
).then(hover => this.hoverToSignatureHelp(hover));
3129
} else if (context.triggerCharacter === ',') {
32-
if (this.previousFunctionPosition) {
30+
if (this.previousFunctionPosition && position.line === this.previousFunctionPosition.line) {
3331
return this.provideHover(
3432
this.languageClient,
3533
document,
3634
this.previousFunctionPosition,
3735
token,
38-
).then(hover => {
39-
return this.hoverToSignatureHelp(hover);
40-
});
36+
).then(hover => this.hoverToSignatureHelp(hover));
4137
} else {
4238
return null;
4339
}
@@ -64,12 +60,8 @@ export class SignatureHelpProvider implements vscode.SignatureHelpProvider {
6460
),
6561
token,
6662
).then(
67-
data => {
68-
resolve(lc.protocol2CodeConverter.asHover(data));
69-
},
70-
error => {
71-
reject(error);
72-
},
63+
data => resolve(lc.protocol2CodeConverter.asHover(data)),
64+
error => reject(error),
7365
);
7466
});
7567
}
@@ -100,11 +92,11 @@ export class SignatureHelpProvider implements vscode.SignatureHelpProvider {
10092
docs: Option<String>,
10193
) -> Vec<MarkedString> {}
10294
This means the first object is the type - function signature,
103-
but for the following, there is no way of certainly knowing which is the
95+
but for the following, there is no way of certainly knowing which is the
10496
function documentation that we want to display in the tooltip.
105-
97+
10698
Assuming the context is never populated for a function definition (this might be wrong
107-
and needs further validation, but initial tests show it to hold true in most cases), and
99+
and needs further validation, but initial tests show it to hold true in most cases), and
108100
we also assume that most functions contain rather documentation, than just a URL without
109101
any inline documentation, we check the length of contents, and we assume that if there are:
110102
- two objects, they are the signature and docs, and docs is contents[1]
@@ -124,22 +116,7 @@ export class SignatureHelpProvider implements vscode.SignatureHelpProvider {
124116
return undefined;
125117
}
126118

127-
let doc: vscode.MarkdownString | undefined;
128-
switch (hover.contents.length) {
129-
case 1:
130-
doc = undefined;
131-
break;
132-
case 2:
133-
doc = hover.contents[1] as vscode.MarkdownString;
134-
break;
135-
case 3:
136-
doc = hover.contents[2] as vscode.MarkdownString;
137-
break;
138-
case 4:
139-
doc = hover.contents[3] as vscode.MarkdownString;
140-
break;
141-
}
142-
119+
const doc = hover.contents.length > 1 ? hover.contents.slice(-1)[0] as vscode.MarkdownString : undefined;
143120
const si = new vscode.SignatureInformation(label, doc);
144121

145122
// without parsing the function definition, we don't have a way to get more info on parameters.

0 commit comments

Comments
 (0)