Skip to main content

Obtención de sugerencias de código en el IDE con GitHub Copilot

Use GitHub Copilot para obtener sugerencias de código en el editor.

About GitHub Copilot and Azure Data Studio

This guide demonstrates how to get coding suggestions from GitHub Copilot in Azure Data Studio. To see instructions for other popular coding environments, use the tool switcher at the top of the page.

Prerequisites

  • Access to Copilot. To use GitHub Copilot in Azure Data Studio, you need either an active Copilot subscription (such as Copilot Pro, Copilot Enterprise, or Copilot Business) or access through Copilot Free, which provides limited functionality. For information about how to get access to Copilot, see What is GitHub Copilot?.

  • Compatible version of Azure Data Studio. To use GitHub Copilot in Azure Data Studio, you must have Azure Data Studio version 1.44.0 or later installed. For more information, see the Azure Data Studio download page in the Azure Data Studio documentation.

  • GitHub Copilot extension for Azure Data Studio. To use GitHub Copilot in Azure Data Studio, you must install the GitHub Copilot extension. For more information, see Installing the GitHub Copilot extension in your environment.

Getting code suggestions

GitHub Copilot can provide you with inline suggestions as you create SQL databases in Azure Data Studio. For example, if you're writing a query that joins two tables, Copilot may suggest the join condition from columns in the open editor, other files in the workspace, and common syntax patterns.

In a SQL file, type the following query:

SQL
SELECT [UserId], [Red], [Orange], [Yellow], [Green], [Blue], [Purple], [Rainbow]
FROM [Tag].[Scoreboard]
INNER JOIN

GitHub Copilot will automatically suggest a join condition in grayed text. The exact suggestion may vary. To accept the suggestion, press Tab.

You can also describe something you want to do using natural language within a comment, and Copilot will suggest the code to accomplish your goal. For example, type this comment in a SQL file:

SQL
SELECT TokenColor, COUNT(UserID) AS UserCount
FROM Tag.Users
GROUP BY TokenColor
-- pivot that query on tokencolor for Purple, Blue, Green, Yellow, Orange, Red
-- and rename the columns to match the colors
SELECT [Purple], [Blue], [Green], [Yellow], [Orange], [Red]

GitHub Copilot will automatically suggest code. To accept the suggestion, press Tab.

Tip

If you receive limited or no suggestions from Copilot, you may have duplication detection enabled. For more information on duplication detection, see Managing Copilot policies as an individual subscriber.

Showing alternative suggestions

For some suggestions, GitHub Copilot may provide multiple alternatives. You can select which suggestion you want to use, or reject all suggestions.

For example, type this query in a SQL file:

SQL
SELECT [UserId], [Red], [Orange], [Yellow], [Green], [Blue], [Purple], [Rainbow]
FROM [Tag].[Scoreboard]
INNER JOIN

GitHub Copilot will show you a suggestion.

Now hover over the suggestion to show the GitHub Copilot control for choosing suggestions. To display next or previous suggestions, click the forward or back arrow button in the control.

You can also use keyboard shortcuts to show alternative suggestions:

OSSee next suggestionSee previous suggestion
macOSOption+[Option+]
Windows or LinuxAlt+[Alt+]

To accept a suggestion, click "Accept" in the Copilot control, or press Tab. To reject all suggestions, press Esc.

Accepting partial suggestions

If you don't want to accept an entire suggestion from GitHub Copilot, you can accept the next word or the next line of a suggestion.

For example, type this query in a SQL file:

SQL
SELECT [UserId], [Red], [Orange], [Yellow], [Green], [Blue], [Purple], [Rainbow]
FROM [Tag].[Scoreboard]
INNER JOIN

GitHub Copilot will show you a suggestion in grayed text. The exact suggestion may vary.

Now hover over the suggestion to show the GitHub Copilot control for choosing suggestions. To accept only the next word of the suggestion, click Accept Word in the control.

Alternatively, you can use a keyboard shortcut to accept the next word of a suggestion:

OSAccept Next Word
macOSCommand+
Windows or LinuxControl+

If you want to accept the next line of the suggestion, you will need to set a custom keyboard shortcut for the command editor.action.inlineSuggest.acceptNextLine. For more information on setting custom keyboard shortcuts, see Keyboard shortcuts in Azure Data Studio in the Microsoft documentation.

Next steps