CodeWhisperer's features are becoming a part of Amazon Q Developer. Learn more
Full function generation
CodeWhisperer can generate an entire function based on a comment that you've written. As you finish your comment CodeWhisperer will suggest a function signature. If you accept the suggestion, CodeWhisperer 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, CodeWhisperer will refactor based on your input.
- Lambda
-
In the following example, using JavaScript and Lambda, 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 CodeWhisperer then suggests a full implementation of the
read_from_s3
method.Note
Sometimes, as in the previous example, CodeWhisperer 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. CodeWhisperer then suggests a full implementation of the
quicksort
method.CodeWhisperer 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. CodeWhisperer 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, CodeWhisperer then suggests a function signature.
In the following image, the user in the previous example has accepted the suggested function signature. CodeWhisperer can then suggest a complete implementation of the
binary_search
function. - AWS Cloud9
-
The following list contains examples of how CodeWhisperer makes suggestions and advances you through the entire process of creating a function.
-
In the example below, in Java, a user inputs a comment. CodeWhisperer suggests a function signature.
After the user accepts that suggestion, CodeWhisperer 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 CodeWhisperer. On the following line, CodeWhisperer generates a suggestion based on the comment.
-
- AWS Toolkit for Visual Studio Code
-
In the following example using C# and VS Code, CodeWhisperer recommends a full function.
In the following example, using TypeScript and VS Code, CodeWhisperer generates a function based on the user's docstrings.
- AWS Toolkit for JetBrains
-
CodeWhisperer can generate an entire function based on a comment that you've written. As you finish your comment, CodeWhisperer will suggest a function signature. If you accept the suggestion, CodeWhisperer 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, CodeWhisperer will refactor based on your input.
In the following example, using Python in Pycharm, CodeWhisperer generates both a full function and the corresponding unit test.
The following list contains examples of how CodeWhisperer 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 CodeWhisperer.
-
In the image below, the user has accepted the CodeWhisperer suggestion for a function signature. Accepting the suggestion automatically advanced the cursor and CodeWhisperer 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 CodeWhisperer. On the following line, CodeWhisperer has generated a new suggestion based on the content of the comment.
-
- SageMaker Studio
-
In this example using Python and SageMaker Studio, CodeWhisperer recommends a full function after the user types part of the signature.