Use Github Copilot’s Modify Feature to Refactor Your Code Quickly

I’ve been using Github Copilot with VSCode for about half a year now. I think many developers will agree with me when I say it’s been pretty nice but not a complete game-changer for writing code. Sure, its autocomplete has moments of greatness (especially with simpler code or code that already has a well-defined pattern). But, I usually spend more time debugging or making sense of its suggestions than I would have if I had just written the code myself. I’ve been a little disappointed in my experience with it on my work project because of this and was looking for different ways to use it to speed up my programming. Recently, I’ve found what feels like Copilot’s hidden gem: its “modify” feature.

How does it work?

It’s pretty simple. The “Modify with Copilot” feature enables you to ask Copilot to refactor some selected code with a prompt you enter to help it out. In VSCode, this feature is available when you highlight a chunk of code and press the all-too-familiar cmd + “.” keyboard shortcut (I believe it’s ctrl + “.” on Windows) to bring up some VSCode “Code Actions”. With the Copilot extension installed, you’ll see the “Modify with Copilot” option available in the dropdown menu.

In my experience, I’ve found this feature incredibly useful when I’m doing long and tedious code refactors. This is where Copilot shines for me. If you start a long refactor for maybe changing the syntax of some enums in Typescript for example, you can then point Copilot to where you started refactoring to give it a pattern to follow for the rest of the refactor.

Check it out!

Here is a quick screen recording showing what I’m talking about:

Modifying some highlighted code with Github Copilot

I urge you to try this out for yourself if you find yourself doing large, repetitive tasks or refactors in your programming. I think you’ll find it super helpful!


Join the conversation

Your email address will not be published. Required fields are marked *