Debug Code
Learn how Cody helps you identify errors in your code and provides code fixes.
Cody is optimized to identify and fix errors in your code. Its debugging capability and autocomplete suggestions can significantly accelerate your debugging process, increasing developer productivity. All Cody IDE extensions (VS Code, JetBrains) support code debugging and fixes capabilities.
Use chat for code fixes
When you encounter a code error, you can use the chat interface and ask Cody about it. You can paste the faulty code snippets directly in the chat window, and Cody will provide a fix.
The suggestions can be a corrected code snippet you can copy and paste into your code. Or you can ask a follow-up question for additional context to help debug the code. Moreover, you can paste an error message in the chat and ask Cody to provide a list of possible solutions.
Let's look at a simple example to understand how Cody can help you debug your code. The following code snippet should print the sum of two numbers.
JSfunction sum(a, b) { var result = a + b; console.log('The sum is: ' + $result); } sum(3 , 4);
When you try to console.log
the result
, it does not print the correct summed value. Cody can help you both identify the error and provide a solution to fix it. Let's debug the code snippet. Paste the code snippet inside the Cody chat window and ask Cody to fix it.
In addition, Cody helps you reduce the chances of getting syntax and typo errors. The Cody IDE extensions provide context-aware suggestions based on your codebase, helping you avoid common mistakes and reduce debugging time.
Detecting code smell
Cody can detect early code smells to ensure coding best practices and quality and provide suggestions to improve your code. By detecting such potential errors early on, you can avoid scalability and code maintainability issues that might arise in the future.
You can detect code smells by the Find Code Smells command from the Prompts drop-down menu in the chat panel.
Code Actions
When you make a mistake while writing code, Cody's Code Actions come into play and a red warning triggers. Along with this, you get a lightbulb icon. If you click on this lightbulb icon, there is an Ask Cody to fix option.
- Click the lightbulb icon in the project file
- Select Ask Cody to fix option
- Cody is working notice will appear and provide a quick fix that you can Accept, Reject, or Open Diff view to see the changes