Skip to content

Commit

Permalink
Handle typed throws when generating comment completions (#1314)
Browse files Browse the repository at this point in the history
  • Loading branch information
plemarquand authored Jan 15, 2025
1 parent cbff0d0 commit 6f426e1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/editor/CommentCompletion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ class FunctionDocumentationCompletionProvider implements vscode.CompletionItemPr
}
if (mark[0] === "throws") {
throws = true;

// Check for a type annotation on the throw i.e. throws(MyError)
parser.match(/^\s*(\(.*\))/);
}
}
// if we find a `->` then function returns a value
Expand Down
21 changes: 21 additions & 0 deletions test/integration-tests/editor/CommentCompletion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,27 @@ suite("CommentCompletion Test Suite", () => {
]);
});

test("Comment completion on complex typed throwing function", async () => {
const { document, positions } = await openDocument(`
/// 1️⃣
func foo(bar: Int, baz: String) -> Data throws(MyError) { return Data() }`);
const position = positions["1️⃣"];

const items = await provider.functionCommentCompletion.provideCompletionItems(
document,
position
);
assert.deepEqual(items, [
expectedCompletionItem(
` $1
/// - Parameters:
/// - bar: $2
/// - baz: $3
/// - Returns: $4`
),
]);
});

test("Comment Insertion", async () => {
const { document, positions } = await openDocument(`
/// 1️⃣
Expand Down

0 comments on commit 6f426e1

Please sign in to comment.