Prompt Cursor to Create New Function API with Composer Context

John Lindquist
InstructorJohn Lindquist
Share this video with your friends

Social Share Links

Send Tweet
Published 4 months ago
Updated 2 months ago

Another great use-case for Cusor Composer is to handle creating new API that is similar to previous functions that you've already written.

In this lesson we'll give composer context of two of our files and a line of code to extract logic into an API for our application to use.

[00:00] I'm going to select this line of code, hit command I, and then you can see that that line and the two files that are open in my tabs are in my context. So I want to extract the appearance logic and expose a set appearance API. Then just by hitting enter, it will start working through my files, and we can check what it did down here. You can see that it added [00:19] the set appearance method here. It followed the patterns of adding logs from my other methods and then set up all the logic around dark and light. And then it also, in my index file, it exposed the set appearance method so that it calls the add on with the proper values here. So I'm just going to accept all. And now we have a working set appearance [00:39] API across multiple files simply based on the one line I had selected and a prompt.