Using Amazon Q Developer for full function generation
Amazon Q can generate an entire function based on a comment that you've written. As you finish your comment Amazon Q will suggest a function signature. If you accept the suggestion, Amazon Q automatically advances your cursor to the next part of the function and makes a suggestion. Even if you enter an additional comment or line of code in between suggestions, Amazon Q will refactor based on your input.
- C
-
- C++
-
- JavaScript
-
In the following example, the user generates, and then edits, a full function based on a set of comments.
In the following image, a user has written a function signature for reading a file from Amazon S3. Amazon Q then suggests a full implementation of the
read_from_s3
method.Note
Sometimes, as in the previous example, Amazon Q includes
import
statements as part of its suggestions. As a best practice, manually move theseimport
statements to the top of your file.As another example, in the following image, a user has written a function signature. Amazon Q then suggests a full implementation of the
quicksort
method.Amazon Q considers past code snippets when making suggestions. In the following image, the user in the previous example has accepted the suggested implementation for
quicksort
above. The user then writes another function signature for a genericsort
method. Amazon Q then suggests an implementation based on what has already been written.In the following image, a user has written a comment. Based on this comment, Amazon Q then suggests a function signature.
In the following image, the user in the previous example has accepted the suggested function signature. Amazon Q can then suggest a complete implementation of the
binary_search
function. - Java
-
The following list contains examples of how Amazon Q makes suggestions and advances you through the entire process of creating a function.
-
In the following example, a user inputs a comment. Amazon Q suggests a function signature.
After the user accepts that suggestion, Amazon Q suggests a function body.
-
In the image below, a user inputs a comment in the body of the function prior to accepting a suggestion from Amazon Q. On the following line, Amazon Q generates a suggestion based on the comment.
-
- C#
-
In the following example, Amazon Q recommends a full function.
- TypeScript
-
In the following example, Amazon Q generates a function based on the user's docstrings.
- Python
-
Amazon Q can generate an entire function based on a comment that you've written. As you finish your comment, Amazon Q will suggest a function signature. If you accept the suggestion, Amazon Q automatically advances your cursor to the next part of the function and makes a suggestion. Even if you enter an additional comment or line of code in between suggestions, Amazon Q will refactor based on your input.
In the following example, Amazon Q generates both a full function and the corresponding unit test.
The following list contains examples of how Amazon Q makes suggestions and advances you through the entire process of creating a function.
-
In the image below, a user has input a comment. The function signature, located below the comment, is a suggestion from Amazon Q.
-
In the image below, the user has accepted the Amazon Q suggestion for a function signature. Accepting the suggestion automatically advanced the cursor and Amazon Q has made a new suggestion for the function body.
-
In the image below, a user input a comment in the body of the function prior to accepting a suggestion from Amazon Q. On the following line, Amazon Q has generated a new suggestion based on the content of the comment.
In this example, Amazon Q recommends a full function after the user types part of the signature.
-