Skip to content

Commit 042a890

Browse files
committed
Fix type hints not being provided for async functions.
1 parent 0b52166 commit 042a890

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Change Log
22

3+
## [1.1.1] - 2020-04-22
4+
5+
* Fixed type hints not being provided for async functions.
6+
37
## [1.1.0] - 2020-04-19
48

59
### Improvements:

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "vscode-python-typehint",
33
"displayName": "Python Type Hint",
4-
"version": "1.1.0",
4+
"version": "1.1.1",
55
"publisher": "njqdev",
66
"description": "Type hint completion for Python.",
77
"icon": "images/icon.png",
@@ -46,7 +46,7 @@
4646
"workspace.searchEnabled": {
4747
"type": "boolean",
4848
"default": true,
49-
"description": "Search other files in the workspace when estimating types for a parameter. Disabling this will increase type hinting speed."
49+
"description": "If enabled, other files in the workspace are searched when estimating types for a parameter. Disabling this will increase performance."
5050
},
5151
"workspace.searchLimit": {
5252
"type": "number",

src/completionProvider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,14 @@ export class ParamHintCompletionProvider extends CompletionProvider implements C
150150
private shouldProvideItems(precedingText: string, activePos: Position, doc: TextDocument): boolean {
151151

152152
if (activePos.character > 0 && !/#/.test(precedingText)) {
153-
let provide = /^[ \t]*def /.test(precedingText);
153+
let provide = /^[ \t]*(def |async *def )/.test(precedingText);
154154

155155
if (!provide) {
156156
const nLinesToCheck = activePos.line > 4 ? 4 : activePos.line;
157157
const previousLines = doc.getText(
158158
new Range(doc.lineAt(activePos.line - nLinesToCheck).range.start, activePos)
159159
);
160-
provide = new RegExp(`^[ \t]*def(?![\\s\\S]+(\\):|-> *${simpleIdentifier}:))`, "m").test(previousLines);
160+
provide = new RegExp(`^[ \t]*(async *)?def(?![\\s\\S]+(\\):|-> *${simpleIdentifier}:))`, "m").test(previousLines);
161161
}
162162
return provide;
163163
}

test/providers/completionProvider.test.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,20 @@ suite('ParamHintCompletionProvider', () => {
5151
let actual = await providerResult(provider, data);
5252
assert.notEqual(actual, null);
5353
});
54+
55+
test("provides items for async function", async () => {
56+
let data = "async def test(test:";
57+
let pos = new vsc.Position(0, data.length);
58+
let expected = null;
59+
let actual = await provideCompletionItems(provider, data, pos);
60+
assert.notEqual(actual, null, messageFor({ data, expected }, actual));
61+
62+
let line2 = " test:";
63+
data = "async def test(\n" + line2;
64+
pos = new vsc.Position(1, line2.length);
65+
actual = await provideCompletionItems(provider, data, pos);
66+
assert.notEqual(actual, null, messageFor({ data, expected }, actual));
67+
});
5468

5569
test("does not provide items unless a function def is detected", async () => {
5670
let text = " :";
@@ -116,7 +130,7 @@ async function providerResult(
116130
functionText: string,
117131
trailingText?: string
118132
): Promise<vsc.CompletionList | null> {
119-
let content = `def func(${functionText}`;
133+
let content = ` def func(${functionText}`;
120134
const lines: string[] = content.split("\n");
121135
const lastLineIdx = lines.length - 1;
122136
const lastPos = new vsc.Position(lastLineIdx, lines[lastLineIdx].length);

0 commit comments

Comments
 (0)