Streamline Adding and Refactoring Code with Cursor Copilot++

John Lindquist
InstructorJohn Lindquist
Share this video with your friends

Social Share Links

Send Tweet
Published 4 months ago
Updated 2 months ago

Cursor Copilot++ can help with your entire workflow from generating logic that you describe, updating existing code and fixing errors with AI, as well as extracting duplicate logic into a utils function.

[00:00] I'll hit command k. I'll say create a function named slash which replaces backslashes with forward slashes to fix Windows Pads and make sure to export the function. I'll hit generate and hit command enter to accept it. So now Copilot [00:19] plus plus will allow me to take my slash function, and I'm going to wrap it around this. So I just type sl suggested slash and I'll hit tab. I still need to import it, and I recommend setting up shortcuts for go to, previous and next problems, something you can easily remember. So I'll go to the next problem. This will automatically jump me [00:39] there. I can hit command period here to apply a quick fix, and I'll add that missing import. Now I'll go to the next problem again, and it looks like that was a promise, so we need to await that. Now because this is either string or null, let's go ahead and fix this with AI, and I will command accept that. I'll hit escape to dismiss the problem [00:59] dialogue. Now if I go over to my music file and I have some similar code, it's going to suggest the things that I was just doing. So if I hit s l, it'll now do slash await. Now let's jump back to the problem, we'll add the import, and now it's suggesting that entire fix that we did before, and I can just hit tab, it'll implement that fix. So now we can jump over to our documents file, [01:19] put the cursor here, type sl, hit tab to accept all of that, jump back to slash, command period to add the import, and now tab to generate all of that code that we used before. I'll hit escape to dismiss that, and then I can even hop into Composer, hit say reference open editors, so all of the files I have open, and I can [01:39] say extract any duplicate logic into the utils TS file, hit enter, and watch it work its magic as it removes all of the duplication that I just added. So let's see what it did. You can see all of that is gone. I'll hit accept all, and now in music and downloads, all of that has moved [01:58] over into utils where it got get random file, and it even included the process random file, which is the logic we implemented with slash.