Skip to content

Latest commit

 

History

History
121 lines (99 loc) · 6.26 KB

3.copilot-features.md

File metadata and controls

121 lines (99 loc) · 6.26 KB

Important Copilot Features

Index

  1. Code intellisense/completion
  2. Copilot Chat
  3. Comment based code generation
  4. Test cases generation
  5. Code Refactoring
  6. Code documentation

Code intellisense/completion:

Copilot does the code completion alongside us based on the current code written in a file. It auto completes the line or provide next 2-3 lines suggestion which we can accept or reject.

How to use this feature effectively:

  • Keep related files open and close unrelated files, copilot create the context from the current open files.
  • Existing written code should be readable with proper names, it helps copilot to better understand the context.
  • Iterate suggestions, if the first suggestion isn’t perfect, hit the shortcut to cycle through alternate suggestions.

Copilot Chat:

The superpower lies here!!! Copilot chat should be used a lot to see notifiable different in productivity gain. Inline chat and chat in window are mostly same with with similar capabilities.

Why to use chat:

  • Chat is more powerful than auto completion feature
  • Chat use GPT 4o model by default which has larger context window than GPT 3 or GPT 3.5 model which is used in auto completion
  • Chat enables the use of Copilot-provided agents, commands, and variables, which helps us to create better context
  • We can directly create file from the generate code in chat
  • We get better explanation of the generated code
  • We can use our prompt engineering skills to get desired results

When to use copilot chat:

Mostly we use it when we want to generate large code in various scenarios. But there are more usecases as below:

  • Code explanation: Asking Copilot to explain what a particular function or piece of code does.
  • Debugging Assistance: Asking Copilot why an error is occurring or to suggest fixes for a specific exception.
  • Writing Boilerplate Code: Creating APIs, form validations, UI components, or basic configurations, etc.
  • Optimizing Code: Asking for suggestions to optimize a slow SQL query or refactor a lengthy function.
  • Writing Tests: Asking Copilot to create test cases for a new feature or validate edge cases are covered
  • Learning and Upskilling: Asking how to use a feature in React, write a unit test in Jest, or implement caching with Redis.
  • Explaining Errors and Logs: Asking for explanations of complex stack traces or strategies to resolve a build failure.
  • Generating Documentation
  • Code Conversion: Converting Python code to JavaScript or SQL to NoSQL queries
  • Many more

How to use this feature effectively:

  • Understand properly about chat agent, commands and chat variables
  • Create a new chat for a new request, this keeps the context clean. Ask follow-up questions in the same chat.
  • Proper files names also helps, @workspace agent see filenames to attach with your chat request for better context.
  • Existing code readability definitely helps
  • Attach known files related to your chat request using #file
  • Change model like GPT 4o, Cluade 3.5 Sonnet or GPT o1 preview, whichever is giving better result

Comment based code generation:

Instead of using comment based code generation better to use copilot chat which is more powerful.

Test cases generation:

Copilot saves the maximum time in writing unit/integration/e2e test cases. We can generate test cases by two ways,

  1. @workspace with prompt
  2. /tests command with prompt As per our experience @workspace give better result.

How to use this feature effectively:

  • Use @workspace agent to generate test cases
  • Mention in the prompt to cover positive and negative scenarios to cover all the code execution flows.
  • With #file, add a sample spec file so that Copilot can write test cases in similar way.
  • With #file also attach other related files in the context
  • We can also select some specific function and use #selection in prompt to generate test cases
  • If Copilot is missing scenarios then we can break process in two steps, in first prompt we ask Copilot to generate all test cases and then in the follow-up prompt we ask Copilot to implement them.

Examples:

@workspace Write unit test case for #file:initiate-esign.service.ts, cover all positive and negative scenarios for maximum coverage. Do it step by step by identifying all test scenarios first and them implement them. Refer this file to see how other service test cases are written #file:post-disbursement-in-lms.service.spec.ts

@workspace Write test case for controller #file:bulk-loan-application.controller.ts. Cover all positive and negative cases. Also handle RoleAuthGuard properly.
@workspace #selection Write unit test cases for this function covering all positive and negative scenarios for maximum coverage. Do it step by step by identifying all test scenarios first and them implement them.
@workspace Identify missing unit test scenarios in this spec file #file:post-disbursement-in-lms.service.spec.ts to cover all positive and negative scenarios for maximum coverage. Do it step by step by identifying the missing scenarios first and them implement them.

Refactor code:

Use Copilot to help us write better code.

Examples:

  • Use it to write better names, press F2(rename shortcut) and copilot can provide better name as per current code context
  • Refactor a large function into smaller ones
  • Ask copilot about what coding design principles are breaking in current code and ask to fix it.

See more refactoring usecases with example from copilot team here: Refactoring code with GitHub Copilot

Documenting the code:

Copilot can help us write API documentation, class documentation, etc

Examples:

@workspace Generate a README for this project.
Add a file-level comment summarizing its purpose.
Add comments to explain the YAML configuration.
Add comments to document the API endpoint with OpenAPI version 3.0.
Add a docstring to the calculate_sum function