Skip to content

Latest commit

 

History

History
229 lines (201 loc) · 7.38 KB

4.agent-and-commands.md

File metadata and controls

229 lines (201 loc) · 7.38 KB

Github Copilot agents, commands and chat variables

Index

  1. @workspace
  2. @terminal
  3. @vscode
  4. /explain
  5. /fix
  6. /tests
  7. #file
  8. #selection

@workspace

The @workspace has context about the code in your workspace. Use @workspace when you want Copilot to consider the structure of your project, how different parts of your code interact, or design patterns in your project. @workspace can find and attach relevant files to the request context automatically.

Examples:

  • Understanding the codebase:
@workspace how is authentication implemented in the project?
@workspace how is error handling implemented in the project?
  • Navigating and locating code:
@workspace find a function from project which is used for generating random alpha numeric code
@workspace find the code where api request retry capabilities are built.
@workspace where is the database connection string configured?

When we are asking Copilot to do some task and we also want Copilot to find and attach relevant files in the context.

@workspace Write a repository function to get users greater than 18 years.
@workspace create a README file summarizing the project's features
@workspace add a new API route for the forgot password form

NOTE: Workspace will try to find and attach relevant files but if we know the relevant files then we should attach with #file explicitly.

Copilot-Workspace

@terminal

The @terminal agent allows you to write terminal commands from natural language and enable you to run the commands. Now we don't have to worry about Linux commands.

Examples:

@terminal show me the contents of the .bashrc file
@terminal stage all changes and commit with the message "Initial setup completed"
@terminal show commit history for the current branch
@terminal compile the TypeScript files in the src folder
@terminal show the current IP address
@terminal display open network ports
@terminal change file permissions for script.sh to be executable
@terminal set an environment variable API_KEY with a specific value
@terminal create a shell script to check server status and send an email if it’s down

NOTE: We can also open an inline chat in vscode integrated terminal via inline chat shortcut or right click menu.

Copilot-Terminal

@vscode:

@vscode agent is used to get help around vscode editor through natural language.

Examples:

@vscode enable auto-format on save
@vscode configure the editor to use 4 spaces for indentation
@vscode set the theme to Dark+
@vscode arrange the editor layout in split view
@vscode configure this workspace to use the Python interpreter located at /env/bin/python
@vscode locate where to change tabs to spaces in settings
@vscode locate the auto-save delay setting
@vscode show me the shortcut to jump to the next occurrence of a word

image

/explain:

The /explain command is used to get a detailed explanation of selected code snippets or specific lines in your codebase. It provides insights into how the code works, what each part of the code does, and why certain functions or methods are used. This command is especially useful for understanding complex or unfamiliar code, improving readability, and speeding up onboarding in collaborative projects.

Examples:

/explain the logic behind the nested if-else conditions
/explain the regular expression used in the sanitizeInput function
/explain the recursive calls in the searchTree function
/explain this SQL query joining multiple tables
/explain the parameters used in this axios call
/explain this statistical calculation for standard deviation
/explain the data flow from parent to child components
/explain how this Redux action updates the state
/explain how exceptions are managed in this function

image

/fix:

The /fix command is designed to automatically identify and suggest solutions for issues or errors in your code. This can include syntax errors, logical issues, performance bottlenecks, and security vulnerabilities. The /fix command is particularly useful for debugging, optimizing, and refactoring code without needing to manually search for potential problems.

Examples:

/fix missing semicolons and braces in this code block
/fix this function so it returns the correct output
/fix performance issues in this data processing function
/fix the SQL injection vulnerability in this query
/fix this code to prevent cross-site scripting
/fix the code to manage empty arrays
/fix this function by refactoring it into smaller parts
/fix variable names to make the code clearer
/fix the data type issues in this function
/fix the error message to be more descriptive
/fix the try-catch block to cover all potential issues

image

/tests:

As per our experience it is better to use @workspace agent then /tests command for better results. Refer Test cases generation

#file:

#file variable is a context reference that allows you to specify particular files within your workspace when posing questions or commands. By referencing a file directly, you provide Copilot with precise context, enabling it to generate more accurate and relevant responses tailored to the content of that file.

Examples:

@workspace Write test cases covering positive and negative scenarios for maximum code coverage. Refer way to write tests from the files #file:video-kyc-webhook-fallback-scheduler.spec.ts. More context #file:repayment.repository.ts #file:repayment.entity.ts
@workspace write a repository function to get repayments by pending retry count, where pending retries are more than 1, repayment are in failed state and repayments are schedule for today. #file:repayment.entity.ts #file:repayments.enum.ts #file:repayment.types.ts

image

#selection:

The #selection is used to focus on a specific code selection within your file. When you reference #selection, Copilot understands that you want it to analyze, explain, or work on the particular highlighted section of code, making it ideal for targeted tasks like explanations, refactoring, or generating tests for selected code.

image

Examples:

/fix #selection Refactor to improve readability.
/explain #selection SQL query joining multiple tables
/fix #selection so it returns the correct output
/tests #selection generate unit tests for the function covering all positive and negative scenarios for maximum code coverage

image