Meet Cody, an AI coding assistant that understands your code and context
Recently, I came across this wonderful free and open-source tool named Cody AI. I was attending a MongoDB webinar and they were using Cody to make their coding faster and easier.
Like every other coding assistant, you can ask Cody questions and it gives answers, coding snippets. Cody can be used as a web app in the browser, as a desktop app, or as an extension in VS Code and a few other code editors. You can find more about Cody here.
When we use it as an extension in VS Code, it appears in the command palette too. You can ask questions, generate new code, and edit code from the command palette.
It appears in the editor inside your code too. You can select a block and ask to reactor it or add any new functionality there.
Let me show you, how Cody reads and understand the context. As a .NET dev, I am gonna use a .NET project here. I cloned a famous open-source repo from GitHub. You can find the repo here.
Then I opened the project in VS Code and opened a class called ‘BrandService’. Then I asked, “Can you explain what is happening in this class?” in the Cody extension pane.
See the response below. It also shows the related and dependent files.
You can open and see the related files, and if you click on any of them, Cody will explain about that file or class too.
Then I selected a method and asked Cody to improve it.
Here are the improvements suggested by Cody. All suggestions may not be relevant, but you can make a decision based on them.
You can place cursor anywhere in the code and ask Cody to generate code by giving the desired functionality. You can do it in-line like in the above example or you can use Cody pane in your sidebar. I used the sidebar menu.
Then you can insert the code using the highlighted option in the image to the exact place where your cursor was. You can also copy the code or generate a new file. See below for the newly created function, as per my instructions.
I have shown a very basic version of Cody’s capabilities here. You can find more here in their documentation — Sourcegraph docs.
Happy coding with Cody !!