Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle typed throws when generating comment completions #1314

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading