How I Code with GitHub Copilot in Visual Studio 2022 to Boost Productivity Everyday

How I Code with GitHub Copilot in Visual Studio 2022 to Boost Productivity Everyday

Brief Summary

This video demonstrates how to use GitHub Copilot within Visual Studio 2022 to enhance developer productivity. It covers a range of features, from understanding existing code and generating documentation to debugging, adding new functionality, and creating commit messages. The video also touches on using extensions with Copilot to generate diagrams and integrate them into documentation.

  • Code understanding and documentation
  • Debugging and error analysis
  • Code generation and refactoring
  • Commit message generation and PR summaries
  • Integration with extensions

Intro & App Overview

The video addresses common questions about using GitHub Copilot with Visual Studio, particularly Visual Studio 2022 on Windows. The presenter aims to demonstrate how to use GitHub Copilot within Visual Studio for various tasks, including code understanding, documentation, debugging, adding new functionalities, and generating Git commits and PR summaries. The demonstration features a coffee tracking application built using GitHub Copilot. The application allows users to add and modify coffee details, track coffee bags, and view consumption charts.

GitHub Copilot Chat - Understanding Code

The presenter demonstrates using the Copilot chat window in Visual Studio to understand a project's structure and components. By asking "What is this application doing? How is it built? And what are the key components?", Copilot analyzes the project and provides a summary of its purpose, key features, technologies, NuGet packages, and key components. The response includes clickable links to navigate directly to specific models, services, or view models within the code. Additionally, hovering over a class and selecting "Describe with Copilot" provides a quick overview of the class's functionality, such as its use of a SQLite database and data retrieval methods.

In-line Chat, Documentation, Refactoring, and more

The presenter explains how to use Copilot in line to describe methods by right-clicking and selecting "Ask Copilot," then using the "/explain" command. This highlights the selected code and provides a detailed breakdown of its functionality. Copilot also suggests improvements to the code, such as avoiding multiple enumerations and optimizing LINQ queries. Additionally, Copilot can add friendly names to enums and generate documentation for code by using the "/Doc" command, which automatically adds descriptions and documentation in line.

Analyzing and improving code while debugging

The presenter demonstrates how to use Copilot to analyze code during debugging. When an exception occurs, such as an argument exception due to invalid input, hovering over a variable and selecting "Analyze with Copilot" provides insights into the cause of the exception. Copilot uses the locals and call stack to explain what is happening and suggests steps to validate input ahead of time to prevent the exception. Similarly, Copilot can analyze methods and services by selecting "Analyze with Copilot" in the watch window or locals window, providing detailed information about their functionality and properties.

Analyzing Exceptions with GitHub Copilot

The presenter explains how to use Copilot to analyze exceptions. By clicking the "Ask Copilot" button when an exception is thrown, Copilot describes everything that happened in the exception, using the call stack, locals, and exception details. This analysis helps to understand the cause of the exception and suggests how to validate inputs to prevent it. The presenter also notes that Copilot maintains a history of chats, allowing users to jump back and forth between different analyses and discussions.

Adding new functionality with GitHub Copilot Edits

The presenter demonstrates using GitHub Copilot edits to add new functionality to the application. By starting a new edits thread and specifying the desired feature, such as adding a delete button to the edit coffee page, Copilot generates a plan and code changes. Copilot identifies the necessary files, such as the view model and coffee service, and suggests code modifications, including adding a delete command, a delete coffee command, and a delete button with a confirmation dialog. The presenter reviews and accepts the changes, which are then automatically applied to the code.

Code suggestions with GitHub Copilot

The presenter demonstrates how GitHub Copilot provides code suggestions while coding. When adding a new observable property to the statistics view model, Copilot offers ghost text suggestions to complete the code. These suggestions include grouping coffees by name and calculating ounces, which the presenter accepts and modifies as needed. Copilot also provides recommendations for filling in the code automatically, making the coding process more efficient.

Commit & PR Message Generation & Customization

The presenter demonstrates how to use GitHub Copilot to generate commit messages. By clicking the "Generate commit message" button in the Git commit window, Copilot analyzes the changes and creates a commit message. The presenter customizes the commit message generation by adding instructions in the Copilot settings, such as making the first line a paragraph outlining the changes and adding a bullet list with emojis of the key updates. These customizations ensure that the commit messages are more informative and aligned with the presenter's preferred style. Copilot can also review active code changes and provide feedback. Additionally, Copilot generates pull request summaries with PR classifications and detailed information, which can be further customized before creating the pull request.

Using Extensions to generate Mermaid Charts

The presenter demonstrates how to use extensions with GitHub Copilot chat. By using the "@" symbol, Copilot can access extensions like Mermaid to generate diagrams. The presenter asks Copilot to create a diagram of the bag of coffee, and Copilot generates a class diagram. The presenter then asks for a database diagram, and Copilot creates an entity relation diagram. The presenter copies the Mermaid code and pastes it into the readme file, which is then rendered by the Markdown editor V2 extension, displaying the diagram in the documentation.

Wrap-up

The presenter summarizes the features of GitHub Copilot in Visual Studio 2022, highlighting its integration into the IDE and its ability to enhance productivity. The presenter encourages viewers to subscribe to the Visual Studio YouTube channel and explore blog posts for more information on new features. The presenter expresses enthusiasm for GitHub Copilot and its impact on coding, debugging, and adding new features.

Watch the Video

Share

Stay Informed with Quality Articles

Discover curated summaries and insights from across the web. Save time while staying informed.

© 2024 BriefRead