Copilot smart actions in Visual Studio Code
For several common scenarios, you can use smart actions to get help from Copilot without having to write a prompt. Examples of these smart actions are generating commit messages, generating documentation, explaining or fixing code, or performing a code review. These smart actions are available throughout the VS Code UI.
Generate a commit message and PR information
Copilot can help generate commit messages and the PR title and description based on the code changes in a commit or the changes in a pull request. Use the sparkle icon in the Source Control view or PR extension to generate a title and description that summarizes your changes.
Rename symbols
When you rename a symbol in your code, Copilot suggests a new name based on the context of the symbol and the codebase.
Generate alt text for images in Markdown
Use AI to generate or update alt text for images in Markdown files. To generate alt text:
Open a Markdown file.
Put the cursor on an image link.
Select the Code Action (lightbulb) icon and select Generate alt text.
If you already have an alt text, select the Code Action, and select Refine alt text.
Generate documentation
Use Copilot to generate code documentation for multiple languages.
Open your application code file.
Optionally, select the code you want to document.
Right-click and select Copilot > Generate Docs.
Generate tests
To generate tests for your application code without writing a prompt, you can use the editor smart actions.
Open your application code file.
Optionally, select the code you want to test.
Right-click and select Copilot > Generate Tests.
Copilot generates test code in an existing test file, or creates a new test file if one doesn't exist.
Optionally, refine the generated tests by providing additional context in the Inline Chat prompt.
Explain code
Copilot can help with explaining a piece of code.
Open your application code file.
Select the code you want to fix.
Right-click and select Copilot > Explain.
Copilot provides an explanation of the selected block of code.
Fix coding errors
To fix coding issues for your application code without writing a prompt, you can use the editor smart actions.
Open your application code file.
Select the code you want to fix.
Right-click and select Copilot > Fix.
Copilot provides a code suggestion to fix the code.
Optionally, refine the generated code by providing additional context in the chat prompt.
Alternatively, if there's a compile or linting problem in a code file, Copilot shows a code action in the editor to help resolve the issue.
Fix testing errors
Copilot integrates with the Test Explorer in VS Code and can help with fixing failing tests.
- In the Test Explorer, hover over a failing test
- Select the Fix Test Failure button (sparkle icon)
- Review and apply Copilot's suggested fix
Alternatively, you can:
- Open the Chat view
- Enter the
/fixTestFailure
command - Follow Copilot's suggestions to fix the test
Agent mode monitors the test output when running tests, and automatically attempts to fix and rerun failing tests.
Fix terminal errors
When a command fails to run in the terminal, Copilot displays a sparkle in the gutter that offers a Quick Fix to explain what happened.
Review code
Copilot can help with reviewing your code, either for a code block in the editor or all changes included in a pull request (requires the Pull Requests extension).
To review a code block in the editor:
Open your application code file.
Select the code you want to fix.
Right-click and select Copilot > Review and Comment.
Copilot creates review comments in the Comments panel and also shows them inline in the editor.
To review all changes in a pull request:
Create a pull request with the Pull Requests extension
Select the Copilot Code Review button in the Files Changed view.
Copilot creates review comments in the Comments panel and also shows them inline in the editor.
Semantic search results (Preview)
The Search view in VS Code enables you to search for text across your files. Semantic search enables you to find results that are semantically relevant to your search query, even if they don't match the text exactly. This is particularly useful when you're looking for code snippets or documentation that relate to a concept rather than a specific term, or when you don't know the exact terms to search for.
Configure semantic search in the Search view with the search.searchView.semanticSearchBehavior setting. You can choose to run semantic search automatically, or only when you explicitly request it.
You can also get AI-generated keyword suggestions in the Search view to provide relevant alternative search terms. Enable search keyword suggestions with the search.searchView.keywordSuggestions setting.
You can reference search results in your chat prompt by selecting Get results from the search view from the Add Context Quick Pick. Alternatively, type #searchResults
in the chat prompt.
Search settings with AI (Experimental)
If you don't know the exact name of a setting you want to change, you can use AI to help find the relevant settings based on your search query. For example, you can search for "increase text size" to find the setting that controls the editor font size.
Enable this functionality with the workbench.settings.showAISearchToggle setting. In the Settings editor, you can then toggle the AI search results on or off with the Search Settings with AI button.