About GitHub Copilot and JetBrains IDEs
GitHub Copilot 在编写代码时提供 AI 对程序员的自动完成样式的建议。 有关详细信息,请参阅“关于 GitHub Copilot Individual”。
If you use a JetBrains IDE, you can view and incorporate suggestions from GitHub Copilot directly within the editor. This guide demonstrates how to use GitHub Copilot within a JetBrains IDE for macOS, Windows, or Linux.
Prerequisites
-
若要使用 GitHub Copilot,必须拥有有效的 GitHub Copilot 订阅。 有关详细信息,请参阅“关于 GitHub Copilot 的计费”。
-
To use GitHub Copilot in JetBrains, you must have a compatible JetBrains IDE installed. GitHub Copilot is compatible with the following IDEs:
- IntelliJ IDEA (Ultimate, Community, Educational)
- Android Studio
- AppCode
- CLion
- Code With Me Guest
- DataGrip
- DataSpell
- GoLand
- JetBrains Client
- MPS
- PhpStorm
- PyCharm (Professional, Community, Educational)
- Rider
- RubyMine
- RustRover
- WebStorm
For more information, see the JetBrains IDEs tool finder.
Installing the GitHub Copilot plugin in your JetBrains IDE
To use GitHub Copilot in a JetBrains IDE, you must install the GitHub Copilot extension. The following procedure will guide you through installation of the GitHub Copilot plugin in IntelliJ IDEA. Steps to install the plugin in another supported IDE may differ.
-
In your JetBrains IDE, under the File menu for Windows, or under the name of your IDE for Mac (for example, PyCharm or IntelliJ), click Settings.
-
In the left-side menu of the Settings dialog box, click Plugins.
-
At the top of the Settings dialog box, click Marketplace. In the search bar, search for
copilot
, then click Install. -
After GitHub Copilot is installed, click Restart IDE.
-
After your JetBrains IDE has restarted, click the Tools menu. Click GitHub Copilot, then click Login to GitHub.
-
In the "Sign in to GitHub" dialog box, to copy the device code and open the device activation window, click Copy and Open.
-
A device activation window will open in your browser. Paste the device code, then click Continue.
-
GitHub will request the necessary permissions for GitHub Copilot. To approve these permissions, click Authorize GitHub Copilot Plugin.
-
After the permissions have been approved, your JetBrains IDE will show a confirmation. To begin using GitHub Copilot, click OK.
Seeing your first suggestion
注意:如果为 GitHub Copilot 启用了重复检测,则使用提供的代码示例时,可能会收到有限的建议或没有建议。 作为替代方法,你可以首先键入自己的代码,以查看来自 GitHub Copilot 的建议。 有关重复检测的详细信息,请参阅“在 GitHub.com 上配置 GitHub Copilot 设置”。
GitHub Copilot 为多种语言和各种框架提供建议,但尤其适用于 Python、JavaScript、TypeScript、Ruby、Go、C# 和 C++。 GitHub Copilot 还可以帮助生成数据库的查询。 The following samples are in Java, but other languages will work similarly.
-
在 JetBrains IDE 中,创建新的 Java (*.java) 文件。
-
In the Java file, create a class by typing
class Test
. GitHub Copilot will automatically suggest a class body in grayed text. The exact suggestion may vary. -
要接受建议,请按 Tab。
-
To prompt GitHub Copilot to suggest a function body, type the following line below the bracket of the
main
function. The exact suggestion may vary.Java int calculateDaysBetweenDates(
int calculateDaysBetweenDates(
-
要接受建议,请按 Tab。
GitHub Copilot will attempt to match the context and style of your code. You can always edit the suggested code.
Seeing alternative suggestions
对于任何给定的输入,GitHub Copilot 可以提供多个建议。 可以选择要使用的建议,或拒绝所有建议。
-
在 JetBrains IDE 中,创建新的 Java (*.java) 文件。
-
To prompt GitHub Copilot to show you a suggestion, type the following line in the Java file.
Java int calculateDaysBetweenDates(
int calculateDaysBetweenDates(
- (可选)如果有其他建议,可以选择查看。
OS See next suggestion See previous suggestion macOS Option+] Option+[ Windows Alt+] Alt+[ Linux Alt+] Alt+[ -
若要接受建议,请按 Tab。若要拒绝所有建议,请按 Esc。
Partially accepting suggestions
You may not want to accept an entire suggestion from GitHub Copilot. You can use keyboard shortcuts to accept either the next word of a suggestion, or the next line.
-
在 JetBrains IDE 中,创建新的 Java (*.java) 文件。
-
To prompt GitHub Copilot to show you a suggestion, type the following line in the Java file.
Java int calculateDaysBetweenDates(
int calculateDaysBetweenDates(
-
To accept a part of the suggestion, use one of the following keyboard shortcuts.
OS Accept Next Word Accept Next Line macOS Command+→ Command+Control+→ Windows Control+→ Control+Alt+→ Linux Control+→ Control+Alt+→ -
Alternatively, you can hover over the suggestion to see the GitHub Copilot command palette for choosing suggestions.
Seeing multiple suggestions in a new tab
你可能不想获得 GitHub Copilot 提供的任何初始建议。 可以使用键盘快捷方式来提示 GitHub Copilot 在新选项卡中显示多个建议。
-
在 JetBrains IDE 中,创建新的 Java (*.java) 文件。
-
To prompt GitHub Copilot to show you a suggestion, type the following line in the Java file.
Java int calculateDaysBetweenDates(
int calculateDaysBetweenDates(
-
Open a new tab with multiple additional suggestions.
- On macOS, press Command+Shift+A, then click Open GitHub Copilot, or press Command+Shift+</kbd> to open the new tab immediately.
- On Windows or Linux, press Ctrl+Enter, then click Open GitHub Copilot.
-
To accept a suggestion, above the suggestion, click Accept Solution. To reject all suggestions, close the tab.
Generating code suggestions from comments
可以在注释中使用自然语言描述要执行的操作,GitHub Copilot 会提供代码建议来实现你的目标。
-
在 JetBrains IDE 中,创建新的 Java (*.java) 文件。
-
To prompt GitHub Copilot to suggest an implementation of a function in the Java file, type the following lines.
Java // find all images without alternate text // and give them a red border void process () {
// find all images without alternate text // and give them a red border void process () {
Enabling and disabling GitHub Copilot
You can enable or disable GitHub Copilot for all languages, or for individual languages. The GitHub Copilot status icon in the bottom panel of your JetBrains IDE window indicates whether GitHub Copilot is enabled or disabled. When enabled, the icon is highlighted. When disabled, the icon is grayed out.
-
To enable or disable GitHub Copilot, click the status icon in the bottom panel of the JetBrains window.
-
If you are disabling GitHub Copilot, you will be asked whether you want to disable it globally, or for the language of the file you are currently editing.
- To disable suggestions from GitHub Copilot globally, click Disable Completions.
- To disable suggestions from GitHub Copilot for the specified language, click Disable Completions for LANGUAGE.
About GitHub Copilot and Visual Studio
GitHub Copilot 在编写代码时提供 AI 对程序员的自动完成样式的建议。 有关详细信息,请参阅“关于 GitHub Copilot Individual”。
If you use Visual Studio, you can view and incorporate suggestions from GitHub Copilot directly within the editor. This guide demonstrates how to use GitHub Copilot within Visual Studio for Windows.
Prerequisites
-
若要使用 GitHub Copilot,必须拥有有效的 GitHub Copilot 订阅。 有关详细信息,请参阅“关于 GitHub Copilot 的计费”。
-
To use GitHub Copilot in Visual Studio, you must have Visual Studio 2022 17.6 or later installed. For more information, see the Visual Studio IDE documentation.
注意:GitHub Copilot 当前不适用于 Visual Studio for Mac。
Installing the GitHub Copilot extension in Visual Studio
To use GitHub Copilot, you must first install the GitHub Copilot extension.
-
在 Visual Studio 菜单栏中,单击“扩展”,然后单击“管理扩展” 。
-
In the "Manage Extensions" window, click Visual Studio Marketplace, search for the GitHub Copilot extension, then click Download.
-
关闭“管理扩展”窗口,然后退出并重新启动 Visual Studio。
-
Optionally, to check that GitHub Copilot is installed and enabled, go back to Manage Extensions, click Installed to view your currently installed extensions, then click GitHub Copilot to see status information.
-
Open or create a new project in Visual Studio.
-
To enable GitHub Copilot, ensure you have added your GitHub account to Visual Studio. For more information, see Work with GitHub accounts in Visual Studio in the Microsoft documentation.
Seeing your first suggestion
注意:如果为 GitHub Copilot 启用了重复检测,则使用提供的代码示例时,可能会收到有限的建议或没有建议。 作为替代方法,你可以首先键入自己的代码,以查看来自 GitHub Copilot 的建议。 有关重复检测的详细信息,请参阅“在 GitHub.com 上配置 GitHub Copilot 设置”。
-
在 Visual Studio 中,创建新的 C# (*.cs) 文件。
-
In the C# file, type the following function signature. GitHub Copilot will automatically suggest an entire function body in grayed text, as shown below. The exact suggestion may vary.
C# int CalculateDaysBetweenDates(
int CalculateDaysBetweenDates(
-
要接受建议,请按 Tab。
Seeing alternative suggestions
对于任何给定的输入,GitHub Copilot 可以提供多个建议。 可以选择要使用的建议,或拒绝所有建议。
-
在 Visual Studio 中,创建新的 C# (*.cs) 文件。
-
In the C# file, type the following function signature. GitHub Copilot will show you a suggestion.
C# int CalculateDaysBetweenDates(
int CalculateDaysBetweenDates(
-
If alternative suggestions are available, you can see these alternatives by pressing Alt+. (or Alt+,).
-
Optionally, you can hover over the suggestion to see the GitHub Copilot command palette for choosing suggestions.
- 若要接受建议,请按 Tab。若要拒绝所有建议,请按 Esc。
Generating code suggestions from comments
可以在注释中使用自然语言描述要执行的操作,GitHub Copilot 会提供代码建议来实现你的目标。
-
在 Visual Studio 中,创建新的 C# (*.cs) 文件。
-
In the C# file, type the following comment. GitHub Copilot will suggest an implementation of the function.
C# using System.Xml.Linq; var doc = XDocument.Load("index.xhml"); // find all images
using System.Xml.Linq; var doc = XDocument.Load("index.xhml"); // find all images
-
要接受建议,请按 Tab。
启用或禁用 GitHub Copilot
Visual Studio 窗口底部面板中的 GitHub Copilot 状态图标指示 GitHub Copilot 启用还是禁用。 启用后,图标的背景色将与状态栏颜色相匹配。 禁用后,将有一条对角线穿过它。
-
若要启用或禁用 GitHub Copilot,请单击 Visual Studio 窗口底部面板中的 GitHub Copilot 图标。
-
如果要禁用 GitHub Copilot,系统会询问是全局禁用建议,还是要禁用当前正在编辑的文件的语言。
- 若要全局禁用 GitHub Copilot 的建议,请单击“全局启用”。
- 若要禁用指定语言的 GitHub Copilot 的建议,请单击“对 LANGUAGE 启用”。
About GitHub Copilot and Visual Studio Code
GitHub Copilot 在编写代码时提供 AI 对程序员的自动完成样式的建议。 有关详细信息,请参阅“关于 GitHub Copilot Individual”。
If you use Visual Studio Code, you can view and incorporate suggestions from GitHub Copilot directly within the editor. This guide demonstrates how to use GitHub Copilot within Visual Studio Code for macOS, Windows, or Linux.
Prerequisites
-
若要使用 GitHub Copilot,必须拥有有效的 GitHub Copilot 订阅。 有关详细信息,请参阅“关于 GitHub Copilot 的计费”。
-
To use GitHub Copilot in Visual Studio Code, you must have Visual Studio Code installed. For more information, see the Visual Studio Code download page.
Installing the GitHub Copilot extension in Visual Studio Code
To use GitHub Copilot, you must first install the GitHub Copilot extension.
-
In the Visual Studio Code Marketplace, go to the GitHub Copilot extension page and click Install.
-
A popup will appear, asking to open Visual Studio Code. Click Open Visual Studio Code.
-
In the "Extension: GitHub Copilot" tab in Visual Studio Code, click Install.
-
If you have not previously authorized Visual Studio Code in your GitHub account, you will be prompted to sign in to GitHub in Visual Studio Code.
-
If you have previously authorized Visual Studio Code for your account on GitHub, GitHub Copilot will be automatically authorized.
-
If you don't get the prompt to authorize, click the bell icon in the bottom panel of the Visual Studio Code window.
-
-
In your browser, GitHub will request the necessary permissions for GitHub Copilot. To approve these permissions, click Authorize Visual Studio Code.
-
To confirm the authentication, in Visual Studio Code, in the "Visual Studio Code" dialog box, click Open.
Seeing your first suggestion
注意:如果为 GitHub Copilot 启用了重复检测,则使用提供的代码示例时,可能会收到有限的建议或没有建议。 作为替代方法,你可以首先键入自己的代码,以查看来自 GitHub Copilot 的建议。 有关重复检测的详细信息,请参阅“在 GitHub.com 上配置 GitHub Copilot 设置”。
GitHub Copilot 为多种语言和各种框架提供建议,但尤其适用于 Python、JavaScript、TypeScript、Ruby、Go、C# 和 C++。 GitHub Copilot 还可以帮助生成数据库的查询。 The following samples are in JavaScript, but other languages will work similarly.
-
在 Visual Studio Code 中,创建一个新的 JavaScript (*.js) 文件。
-
In the JavaScript file, type the following function header. GitHub Copilot will automatically suggest an entire function body in grayed text, as shown below. The exact suggestion may vary.
JavaScript function calculateDaysBetweenDates(begin, end) {
function calculateDaysBetweenDates(begin, end) {
-
要接受建议,请按 Tab。
Note: If you don't see a suggestion, make sure GitHub Copilot is enabled. You should see the Copilot icon at the bottom right of the Visual Studio Code window.
如果文件已配置为 GitHub Copilot 的排除内容,则状态栏中的图标将有一条对角线穿过。 将鼠标悬停在该图标上可看到工具提示,告知哪些设置已应用此限制。
有关详细信息,请参阅“为 GitHub Copilot 配置内容排除”。
Seeing alternative suggestions
对于任何给定的输入,GitHub Copilot 可以提供多个建议。 可以选择要使用的建议,或拒绝所有建议。
-
在 Visual Studio Code 中,创建一个新的 JavaScript (*.js) 文件。
-
In the JavaScript file, type the following function header. GitHub Copilot will show you a suggestion.
JavaScript function calculateDaysBetweenDates(begin, end) {
function calculateDaysBetweenDates(begin, end) {
-
(可选)如果有其他建议,可以选择查看。
OS See next suggestion See previous suggestion macOS Option (⌥) or Alt+] Option (⌥) or Alt+[ Windows Alt+] Alt+[ Linux Alt+] Alt+[ -
Alternatively, you can hover over the suggestion to see the GitHub Copilot command palette for choosing suggestions.
-
若要接受建议,请按 Tab。若要拒绝所有建议,请按 Esc。
Partially accepting suggestions
You may not want to accept an entire suggestion from GitHub Copilot. You can use keyboard shortcuts to accept either the next word of a suggestion, or the next line.
-
在 Visual Studio Code 中,创建一个新的 JavaScript (*.js) 文件。
-
In the JavaScript file, type the following function header. GitHub Copilot will automatically suggest an entire function body in grayed text, as shown below. The exact suggestion may vary.
JavaScript function calculateDaysBetweenDates(begin, end) {
function calculateDaysBetweenDates(begin, end) {
-
If you want to accept only the next word of the suggestion, use one of the following keyboard shortcuts.
OS Accept Next Word macOS Command+→ Windows Control+→ Linux Control+→ -
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 "在环境中配置 GitHub Copilot." -
Alternatively, you can hover over the suggestion to see the GitHub Copilot command palette for choosing suggestions.
Seeing multiple suggestions in a new tab
你可能不想获得 GitHub Copilot 提供的任何初始建议。 可以使用键盘快捷方式来提示 GitHub Copilot 在新选项卡中显示多个建议。
-
在 Visual Studio Code 中,创建一个新的 JavaScript (*.js) 文件。
-
In the JavaScript file, type the following function header. GitHub Copilot will show you a suggestion.
JavaScript function calculateDaysBetweenDates(begin, end) {
function calculateDaysBetweenDates(begin, end) {
-
To open a new tab with multiple additional options, press Ctrl+Enter.
-
To accept a suggestion, above the suggestion, click Accept Solution. To reject all suggestions, close the tab.
Generating code suggestions from comments
可以在注释中使用自然语言描述要执行的操作,GitHub Copilot 会提供代码建议来实现你的目标。
-
在 Visual Studio Code 中,创建一个新的 JavaScript (*.js) 文件。
-
In the JavaScript file, type the following comment. GitHub Copilot will suggest an implementation of the function.
JavaScript // find all images without alternate text // and give them a red border function process() {
// find all images without alternate text // and give them a red border function process() {
Using a framework
You can also use GitHub Copilot to generate suggestions for APIs and frameworks. The following example uses GitHub Copilot to create a simple Express server that returns the current time.
-
在 Visual Studio Code 中,创建一个新的 JavaScript (*.js) 文件。
-
In the JavaScript file, type the following comment and then press Enter. GitHub Copilot will suggest an implementation of the Express app.
JavaScript // Express server on port 3000
// Express server on port 3000
-
To accept each line, press Tab, then Enter.
-
Type the following comment and then press Enter. GitHub Copilot will suggest an implementation for the default handler.
JavaScript // Return the current time
// Return the current time
-
To accept each line, press Tab.
启用或禁用 GitHub Copilot
可以在 Visual Studio Code 中启用或禁用 GitHub Copilot。 Visual Studio Code 窗口底部面板中的 GitHub Copilot 状态图标指示 GitHub Copilot 是启用还是禁用。 启用后,图标的背景色将与状态栏颜色相匹配。 禁用后,图标的背景色将与状态栏颜色形成对比。
-
若要启用或禁用 GitHub Copilot,请单击 Visual Studio Code 窗口底部面板中的状态图标。
-
如果要禁用 GitHub Copilot,系统会询问是全局禁用建议,还是要禁用当前正在编辑的文件的语言。
- 若要全局禁用 GitHub Copilot 的建议,请单击“全局禁用”。
- 若要禁用指定语言的 GitHub Copilot 的建议,请单击“对 LANGUAGE 禁用”。
About GitHub Copilot and Vim/Neovim
GitHub Copilot 在编写代码时提供 AI 对程序员的自动完成样式的建议。 有关详细信息,请参阅“关于 GitHub Copilot Individual”。
If you use Vim/Neovim, you can view and incorporate suggestions from GitHub Copilot directly within the editor.
Prerequisites
-
若要使用 GitHub Copilot,必须拥有有效的 GitHub Copilot 订阅。 有关详细信息,请参阅“关于 GitHub Copilot 的计费”。
-
To use GitHub Copilot in Vim/Neovim you must have Vim version 9.0.0185 / Neovim version 0.6 or above and Node.js version 18 or above installed. For more information, see the Vim / Neovim documentation and the Node.js website.
Installing the GitHub Copilot extension in Vim/Neovim on macOS
- GitHub 建议使用 Vim/Neovim 的内置插件管理器安装 GitHub Copilot 插件。 或者,可以使用所选的插件管理器来安装
github/copilot.vim
。
-
To install GitHub Copilot with Vim's built-in plugin manager, enter the following command in Terminal:
git clone https://github.com/github/copilot.vim \ ~/.vim/pack/github/start/copilot.vim
-
To install GitHub Copilot with Neovim's built-in plugin manager, enter the following command in Terminal:
git clone https://github.com/github/copilot.vim \ ~/.config/nvim/pack/github/start/copilot.vim
-
若要配置 GitHub Copilot,请打开 Vim/Neovim 并输入以下命令。
:Copilot setup
-
在 Vim/Neovim 配置中或使用 Vim/Neovim 命令启用 GitHub Copilot。
:Copilot enable
Installing the GitHub Copilot extension in Vim/Neovim on Windows
- GitHub 建议使用 Vim/Neovim 的内置插件管理器安装 GitHub Copilot 插件。 或者,可以使用所选的插件管理器来安装
github/copilot.vim
。
-
To install GitHub Copilot with Vim's built-in plugin manager, enter the following command in Git Bash:
git clone https://github.com/github/copilot.vim.git \ $HOME/vimfiles/pack/github/start/copilot.vim
-
To install GitHub Copilot with Neovim's built-in plugin manager, enter the following command in Git Bash:
git clone https://github.com/github/copilot.vim.git \ $HOME/AppData/Local/nvim/pack/github/start/copilot.vim
-
若要配置 GitHub Copilot,请打开 Vim/Neovim 并输入以下命令。
:Copilot setup
-
在 Vim/Neovim 配置中或使用 Vim/Neovim 命令启用 GitHub Copilot。
:Copilot enable
Installing the GitHub Copilot extension in Vim/Neovim on Linux
- GitHub 建议使用 Vim/Neovim 的内置插件管理器安装 GitHub Copilot 插件。 或者,可以使用所选的插件管理器来安装
github/copilot.vim
。
-
To install GitHub Copilot with Vim's built-in plugin manager, enter the following command:
git clone https://github.com/github/copilot.vim \ ~/.vim/pack/github/start/copilot.vim
-
To install GitHub Copilot with Neovim's built-in plugin manager, enter the following command:
git clone https://github.com/github/copilot.vim \ ~/.config/nvim/pack/github/start/copilot.vim
-
若要配置 GitHub Copilot,请打开 Vim/Neovim 并输入以下命令。
:Copilot setup
-
在 Vim/Neovim 配置中或使用 Vim/Neovim 命令启用 GitHub Copilot。
:Copilot enable
Learning to use GitHub Copilot in Vim/Neovim
For guidance on using GitHub Copilot in Vim/Neovim, you can view the plugin documentation. To see the documentation, open Vim/Neovim and run the following command:
:help copilot
About GitHub Copilot and Azure Data Studio
GitHub Copilot 在编写代码时提供 AI 对程序员的自动完成样式的建议。 有关详细信息,请参阅“关于 GitHub Copilot Individual”。
If you use Azure Data Studio, you can view and incorporate suggestions from GitHub Copilot directly within the editor. This guide demonstrates how to use GitHub Copilot within Azure Data Studio for macOS, Windows, or Linux.
Prerequisites
-
若要使用 GitHub Copilot,必须拥有有效的 GitHub Copilot 订阅。 有关详细信息,请参阅“关于 GitHub Copilot 的计费”。
-
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.
Installing the GitHub Copilot extension in Azure Data Studio
To use GitHub Copilot, you must first install the GitHub Copilot extension.
-
In Azure Data Studio, click the Extensions icon in the left-side menu.
-
In the "Extensions" tab, search for GitHub Copilot and then click Install.
-
If a popup window in Azure Data Studio prompts you to sign in to use GitHub Copilot, click Sign in to GitHub and follow the instructions on screen.
- If you have previously authorized Azure Data Studio for your account on GitHub, GitHub Copilot will be automatically authorized.
- If you don't get the prompt to authorize, you can view notifications by clicking the bell icon in the bottom panel of the Azure Data Studio window.
-
If you are following the authorization steps, in your browser, GitHub will request the necessary permissions for GitHub Copilot. To approve these permissions, click Authorize Azure Data Studio.
Seeing your first suggestion
注意:如果为 GitHub Copilot 启用了重复检测,则使用提供的代码示例时,可能会收到有限的建议或没有建议。 作为替代方法,你可以首先键入自己的代码,以查看来自 GitHub Copilot 的建议。 有关重复检测的详细信息,请参阅“在 GitHub.com 上配置 GitHub Copilot 设置”。
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 Azure Data Studio, create a new SQL file.
-
In the SQL file, type the following query. GitHub Copilot will automatically suggest a join condition in grayed text. The exact suggestion may vary.
SQL SELECT [UserId], [Red], [Orange], [Yellow], [Green], [Blue], [Purple], [Rainbow] FROM [Tag].[Scoreboard] INNER JOIN
SELECT [UserId], [Red], [Orange], [Yellow], [Green], [Blue], [Purple], [Rainbow] FROM [Tag].[Scoreboard] INNER JOIN
-
要接受建议,请按 Tab。
Seeing alternative suggestions
For some suggestions, GitHub Copilot may provide multiple alternatives. You can select which suggestion you want to use, or reject all suggestions.
-
In Azure Data Studio, create a new SQL file.
-
In the SQL file, type the following query. GitHub Copilot will show you a suggestion.
SQL SELECT [UserId], [Red], [Orange], [Yellow], [Green], [Blue], [Purple], [Rainbow] FROM [Tag].[Scoreboard] INNER JOIN
SELECT [UserId], [Red], [Orange], [Yellow], [Green], [Blue], [Purple], [Rainbow] FROM [Tag].[Scoreboard] INNER JOIN
-
Optionally, you can see alternative suggestions, if any are available.
OS See next suggestion See previous suggestion Windows Alt+[ Alt+] Linux Alt+[ Alt+] macOS Option+[ Option+]
Partially accepting suggestions
You may not want to accept an entire suggestion from GitHub Copilot. You can use keyboard shortcuts to accept either the next word of a suggestion, or the next line.
-
In Azure Data Studio, create a new SQL file.
-
In the SQL file, type the following query. GitHub Copilot will show you a suggestion.
SQL SELECT [UserId], [Red], [Orange], [Yellow], [Green], [Blue], [Purple], [Rainbow] FROM [Tag].[Scoreboard] INNER JOIN
SELECT [UserId], [Red], [Orange], [Yellow], [Green], [Blue], [Purple], [Rainbow] FROM [Tag].[Scoreboard] INNER JOIN
-
If you want to accept only the next word of the suggestion, use one of the following keyboard shortcuts.
OS Accept Next Word macOS Command+→ Windows Control+→ Linux Control+→ -
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. -
Alternatively, you can hover over the suggestion to see the GitHub Copilot command palette for choosing suggestions.
Generating code suggestions from comments
可以在注释中使用自然语言描述要执行的操作,GitHub Copilot 会提供代码建议来实现你的目标。
-
In Azure Data Studio, create a new SQL file.
-
In the SQL file, type the following query and comment. GitHub Copilot will suggest an implementation of the query.
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]
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]
Enabling or disabling GitHub Copilot
You can enable or disable GitHub Copilot from within Azure Data Studio. The GitHub Copilot status icon in the bottom panel of the Azure Data Studio window indicates whether GitHub Copilot is enabled or disabled. When enabled, the background color of the icon will match the color of the status bar. When disabled, the background color of the icon will contrast with the color of the status bar.
-
To enable or disable GitHub Copilot, click the status icon in the bottom panel of the Azure Data Studio window.
-
If you are disabling GitHub Copilot, you will be asked whether you want to disable suggestions globally, or for the language of the file you are currently editing.
- To disable suggestions from GitHub Copilot globally, click Disable Globally.
- To disable suggestions from GitHub Copilot for the specified language, click Disable for LANGUAGE.
Next steps
你已成功安装 GitHub Copilot 并收到了你的第一个建议,但这只是开始! 以下是一些有用的资源,可帮助你对 GitHub Copilot 执行后续操作。
- GitHub Copilot: See practical examples of how GitHub Copilot can help you work.
- 配置 GitHub Copilot: These guides provide details on how to configure GitHub Copilot to your personal preferences.
- 管理 GitHub Copilot 的计费: Learn more about billing for GitHub Copilot.
- GitHub Copilot 故障排除: These guides provide information for troubleshooting GitHub Copilot.