Quick Tip: Use Copilot Labs for pesky refactors

I've been testing daily how to adjust my development workflow and process to leverage tools like Chat GPT, Github Copilot, and Github Copilot Labs more effectively.

Ironically, I wanted to create some very basic pagination for this very blog. So, I reached out to Chat GPT with a simple prompt to create an algorithm for creating a list of pages, max 5 visible based on a total page count, where the current page is in the middle of the list if possible. And it delivered a great answer!

This was a great solution and works as expected with the one exception, for me, that it considered pageCount to be a human-readable number such as "There are 5 pages" and currentPage to be a zero-based index, where 0 represents the first page.

On the surface, this is frankly to be expected and a usual solution. I was just not happy with the overhead of considering the page index I'm rendering mapped to the page count. So I reached for the "Custom" brush via Github Copilot Labs in Visual Studio Code using the prompt "refactor this function where 'currentPage` is base one", and it refactored my function inline to the following:


It's just what I wanted to make my process that much easier and it took no time at all. I didn't need to sit and consider if it was a good use of time to refactor it myself. I just reached for the tool and it delivered what I wanted.

It's an obvious way to use a tool designed exactly for this purpose, but I hope this helps you consider new ways to use these burgeoning AI tools in your work.



Github Copilot Labs
AI Tools