Learning About Copilot and Its Features

Introduction

This article explores how GitHub Copilot can enhance your development workflow. From generating AI-powered commit messages to improving code quality and automating tests, Copilot offers powerful tools to boost productivity. We'll cover key features, setup steps, and shortcuts to help you make the most of this AI assistant in your coding projects.

GitHub Copilot Keyboard Shortcuts
 

Action Shortcut
Accept an inline suggestion Tab
Dismiss an inline suggestion Esc
Move to the next inline suggestion Alt + ]
Move to the previous inline suggestion Alt + [
Trigger an inline suggestion Alt + \
Open additional Copilot suggestions Ctrl + Alt + I
Open the Chat view Ctrl + L
Clear the Chat view Ctrl + Down
Focus on the Chat view input box Alt + Enter
  • Upgrading Visual Studio to Version 17.9.0: After upgrading, the sparkling button now appears, making it possible to view AI-generated commit messages.
  • Enabling Commit Message Suggestions: To allow Copilot to suggest commit messages, navigate to Tools > Options > GitHub > Copilot Chat and enable 'Commit Message Suggestions.'
  • Changing the Database Name for Testing: The database name has been updated from Staging to Dev for testing purposes. By clicking the 'Add AI-generated Commit Message' icon, an appropriate message will be created for our commit.
  • Committing AI-Generated Messages to Bitbucket: By selecting 'Insert AI Suggestion,' the commit message will automatically be submitted to Bitbucket.
  • Using VS Code Copilot for Commit Messages: After making changes in your code and staging them, click the Star (*) icon to the right, and Copilot will generate a commit message for you.
  • Generating Automated Test Cases with Copilot: Press Ctrl + I to open the command section, then enter a valid command to run the desired tests. I’ve selected specific code areas that will trigger Copilot to generate the corresponding test cases.
  • Evaluate and Track Development Efficiency with Copilot: Select a function and ask Copilot to explain the logic and purpose behind the code, helping to improve understanding.
  • Enhancing Code Quality with Copilot: In Visual Studio, right-click a section of code and request Copilot to 'Assess and enhance code quality.' The copilot will suggest improvements and show the modified version of the code. You can preview these changes and click 'Accept' if you wish to implement them.

Fixing Code Issues Using Copilot’s Suggestions

  • Identify the section of the code where an issue arises.
  • Use Copilot’s suggestions to navigate to related functions or variables, saving you time.
  • Position your cursor on the line with the error.
  • Trigger Copilot’s recommendations by using the relevant shortcut for your IDE.
  • Review Copilot’s proposed code snippets, considering alternatives or restructuring for better readability.
  • Assess the suggestions and ensure they fit the needs of your code.
  • Apply the fixes to your code as required.

Generating Code via Command Prompts and Best Practices

  • Provide clear and concise context to help Copilot understand your intentions.
  • Name your functions, classes, and blocks descriptively to improve clarity.
  • Include comments outlining the desired behavior and functionality.
  • Write precise and straightforward instructions when interacting with Copilot.
  • Place the cursor where you want the code to be generated and allow Copilot to suggest relevant code.
  • Review Copilot’s recommendations and select the most suitable options.

Thanks, I hope it will be useful for your reference.