Skip to content

Commit 6f426e1

Browse files
authored
Handle typed throws when generating comment completions (#1314)
1 parent cbff0d0 commit 6f426e1

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/editor/CommentCompletion.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ class FunctionDocumentationCompletionProvider implements vscode.CompletionItemPr
179179
}
180180
if (mark[0] === "throws") {
181181
throws = true;
182+
183+
// Check for a type annotation on the throw i.e. throws(MyError)
184+
parser.match(/^\s*(\(.*\))/);
182185
}
183186
}
184187
// if we find a `->` then function returns a value

test/integration-tests/editor/CommentCompletion.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,27 @@ suite("CommentCompletion Test Suite", () => {
164164
]);
165165
});
166166

167+
test("Comment completion on complex typed throwing function", async () => {
168+
const { document, positions } = await openDocument(`
169+
/// 1️⃣
170+
func foo(bar: Int, baz: String) -> Data throws(MyError) { return Data() }`);
171+
const position = positions["1️⃣"];
172+
173+
const items = await provider.functionCommentCompletion.provideCompletionItems(
174+
document,
175+
position
176+
);
177+
assert.deepEqual(items, [
178+
expectedCompletionItem(
179+
` $1
180+
/// - Parameters:
181+
/// - bar: $2
182+
/// - baz: $3
183+
/// - Returns: $4`
184+
),
185+
]);
186+
});
187+
167188
test("Comment Insertion", async () => {
168189
const { document, positions } = await openDocument(`
169190
/// 1️⃣

0 commit comments

Comments
 (0)