这是用户在 2025-2-25 14:56 为 https://code.visualstudio.com/docs/copilot/copilot-edits 保存的双语快照页面,由 沉浸式翻译 提供双语支持。了解如何保存?

🚀 Get in VS Code!
🚀 在 VS Code 中免费获取 GitHub Copilot!

Copilot Edits  Copilot 编辑

Use Copilot Edits to start an AI-powered code editing session and iterate quickly on code changes across multiple files by using natural language. Copilot Edits applies the edits directly in the editor, where you can review them in-place, with the full context of the surrounding code.
使用 Copilot Edits 开始一个由 AI 驱动的代码编辑会话,并通过使用自然语言快速迭代多个文件中的代码更改。Copilot Edits 直接在编辑器中应用更改,您可以在代码的完整上下文中就地查看它们。

Copilot Edits can function in two modes:
Copilot 编辑可以在两种模式下运行:

  • Edit mode: select which files to edit, provide the relevant context and prompt, and Copilot will suggest code edits.
    编辑模式:选择要编辑的文件,提供相关上下文和提示,Copilot 将建议代码编辑。
  • Agent mode (preview): let Copilot autonomously plan the tasks and relevant files that are needed to implement the request. Copilot will apply code edits and suggest terminal commands, and will continuously iterate to resolve any issues that arise.
    代理模式(预览):让 Copilot 自主规划实现请求所需的任务和相关文件。Copilot 将应用代码编辑并建议终端命令,并持续迭代以解决出现的任何问题。
Note   注意

Agent mode is currently in preview and is only available in VS Code Insiders. Provide feedback and report issues in the Copilot repository.
代理模式目前处于预览阶段,仅在 VS Code Insiders 中可用。请在 Copilot 仓库中提供反馈和报告问题。

Important   重要

If you're using notebooks, Copilot Edits support is currently limited. We recommend that you use Copilot Chat or Inline Chat with notebooks in VS Code.
如果您使用笔记本,Copilot 编辑功能目前支持有限。我们建议您在 VS Code 中使用 Copilot 聊天或内联聊天与笔记本一起使用。

The following video demonstrates how to use Copilot Edits to extend a basic Express app, such as adding a new page, navigation bar, and theme switcher.
以下视频演示了如何使用 Copilot Edits 扩展基本 Express 应用程序,例如添加新页面、导航栏和主题切换器。

Tip   提示

If you don't yet have a Copilot subscription, you can use Copilot for free by signing up for the Copilot Free plan and get a monthly limit of completions and chat interactions.
如果您还没有 Copilot 订阅,可以通过注册 Copilot 免费计划免费使用 Copilot,并获得每月的完成次数和聊天交互限制。

Start a Copilot Edits session
开始一个 Copilot 编辑会话

You access Copilot Edits through the Copilot Edits view, where you can enter natural language prompts for getting edit suggestions. By default, the Copilot Edits view is available in the Secondary Side Bar.
您可以通过“Copilot Edits”视图访问 Copilot Edits,在该视图中,您可以输入自然语言提示以获取编辑建议。默认情况下,“Copilot Edits”视图在“次要侧边栏”中可用。

Screenshot showing the Copilot Edits view and welcome message.

To access the Copilot Edits view:
访问 Copilot 编辑视图:

  • Use the Ctrl+Shift+I keyboard shortcut
    使用 Ctrl+Shift+I 快捷键

  • Open the Copilot menu in the VS Code title bar, and then select Open Copilot Edits
    打开 VS Code 标题栏中的 Copilot 菜单,然后选择打开 Copilot 编辑

    Screenshot showing the Copilot menu in VS Code title bar, highlighting the Open Edit Session item.

  • Use the View: Toggle Copilot Edits or Copilot Edits: Focus on Copilot Edits View command in the Command Palette (Ctrl+Shift+P)
    使用“视图:切换代码助手编辑”或“代码助手编辑:聚焦代码助手编辑视图”命令在命令面板(Ctrl+Shift+P)中

Because making code changes can be an iterative process, an edit session in Copilot Edits can consist of a sequence of requests (or turns). You can send as many requests as you need to get the code to where you want it.
因为代码更改可能是一个迭代过程,Copilot Edits 中的编辑会话可以由一系列请求(或回合)组成。您可以发送所需数量的请求,以将代码修改到您想要的状态。

Use edit mode  使用编辑模式

In edit mode, you select which files to edit and provide the relevant context and prompt. Copilot will suggest code edits based on your prompt.
在编辑模式下,您选择要编辑的文件并提供相关上下文和提示。Copilot 将根据您的提示建议代码编辑。

  1. Open the Copilot Edits view (Ctrl+Shift+I)
    打开 Copilot 编辑视图(Ctrl+Shift+I)

  2. Select Edit from the mode dropdown
    从模式下拉菜单中选择编辑

    Screenshot showing the Copilot Edits view, highlighting edit mode selected.

  3. Use Add Files to add files to the working set
    使用“添加文件”添加文件到工作集

    The working set indicates which files in the workspace can be edited by Copilot Edits.
    工作集指示哪些工作空间中的文件可以通过 Copilot Edits 进行编辑。

  4. Enter a prompt to request code edits. Be specific and precise about the changes you want, and decompose larger tasks into smaller tasks.
    输入提示以请求代码编辑。请具体明确您想要的更改,并将较大的任务分解为较小的任务。

    Copilot Edits streams the edits in the editor. In the working set, files that were edited by Copilot are marked in bold.
    Copilot Edits 在编辑器中流式传输编辑。在工作集中,由 Copilot 编辑的文件以粗体显示。

    Tip   提示

    Let Copilot find the right files automatically by adding #codebase in your prompt. Make sure to enable the github.copilot.chat.edits.codesearch.enabled (preview) setting to get the best results.
    通过在提示中添加 #codebase ,让 Copilot 自动找到正确的文件。请确保启用 github.copilot.chat.edits.codesearch.enabled(预览)设置以获得最佳结果。

  5. Review the suggested edits and accept or discard the suggested edits
    审查建议的编辑并接受或拒绝建议的编辑

  6. Iterate on the code changes
    迭代代码更改

    If you're not entirely happy with the edits, you can ask follow-up questions, such as "don't include the phone number", or "use jest instead of vitest". Or you can incrementally edit your code further. For example, when building a web app, use a series of prompts such as "add a navigation bar", "add a theme switcher", "store order items in JSON format in MongoDB".
    如果您对编辑不完全满意,可以提出后续问题,例如“不要包含电话号码”,或“使用 jest 代替 vitest”。或者您可以进一步逐步编辑您的代码。例如,在构建一个 Web 应用时,可以使用一系列提示,如“添加导航栏”、“添加主题切换器”、“将订单项以 JSON 格式存储在 MongoDB 中”。

Use agent mode (preview)
使用代理模式(预览)

In agent mode, Copilot Edits operates in a more autonomous and dynamic manner to achieve the desired outcome. To process a request, Copilot loops over the following steps and iterates multiple times as needed:
在代理模式下,Copilot Edits 以更自主和动态的方式运行,以实现预期结果。为了处理请求,Copilot 会循环以下步骤,并根据需要多次迭代:

  • Determines the relevant context and files to edit autonomously.
    确定相关上下文和要编辑的文件以自主操作。
  • Offers both code changes and terminal commands to complete the task. For example, Copilot might compile code, install packages, run tests, and more.
    提供代码更改和终端命令以完成任务。例如,Copilot 可能会编译代码、安装包、运行测试等。
  • Monitors the correctness of code edits and terminal command output and iterates to remediate issues.
    监控代码编辑的正确性和终端命令输出,并迭代修复问题。

Copilot Edits agent mode uses a set of tools to accomplish these tasks. These tools can run in parallel to accomplish the requested task.
Copilot Edits 代理模式使用一系列工具来完成这些任务。这些工具可以并行运行以完成请求的任务。

To use agent mode in Copilot Edits:
要在 Copilot Edits 中使用代理模式:

  1. Enable agent mode in by setting the chat.agent.enabled setting to true.
    启用代理模式,通过设置 chat.agent.enabled 设置为 true

  2. Open the Copilot Edits view (Ctrl+Shift+I)
    打开 Copilot 编辑视图(Ctrl+Shift+I)

  3. Select Agent from the mode dropdown
    选择模式下拉列表中的代理

    Screenshot showing the Copilot Edits view, highlighting agent mode selected.

  4. Enter a prompt to request code edits.
    输入提示以请求代码编辑。

    You don't have to specify the working set. In agent mode, Copilot Edits determines the relevant context and files to edit autonomously.
    您无需指定工作集。在代理模式下,Copilot Edits 自动确定相关上下文和要编辑的文件。

    Screenshot showing the Copilot Edits view, highlighting that Copilot searched the codebase for relevant files.

    Copilot Edits streams the edits in the editor and updates the working set. In addition, Copilot can suggest terminal commands to run.
    Copilot Edits 在编辑器中流式传输编辑并更新工作集。此外,Copilot 可以建议运行终端命令。

  5. Review the suggested code edits, and confirm if Copilot can run the proposed terminal commands
    审查建议的代码编辑,并确认 Copilot 能否运行所提出的终端命令

    As a user, you stay in control of the changes that are made to your project and can review the generated edits and need to confirm the terminal commands to run.
    作为用户,您始终掌控着对项目所做的更改,可以审查生成的编辑并需要确认要运行的终端命令。

    Screenshot showing the Copilot Edits view, highlighting the terminal command that Copilot wants to run.

  6. Copilot Edits detects issues and problems in code edits and terminal commands, and will iterate and perform additional actions to resolve them.
    Copilot Edits 检测代码编辑和终端命令中的问题和问题,并将迭代并执行其他操作以解决它们。

    Screenshot showing the Copilot Edits view, highlighting that Copilot verified the code edits for errors.

    Note   注意

    The chat.agent.maxRequests setting controls the maximum number of requests that Copilot Edits can make in agent mode.
    聊天代理的最大请求设置控制了 Copilot Edits 在代理模式下的最大请求数量。

  7. Continue to ask follow-up questions and iterate on the code changes that Copilot Edits provides.
    继续提出后续问题并对 Copilot Edits 提供的代码更改进行迭代。

Note   注意

Agent mode for Copilot Edits is currently only available in VS Code Insiders.
Copilot 编辑的代理模式目前仅在 VS Code Insiders 中可用。

Manage the working set
管理工作集

The working set is the set of files that you want Copilot Edits to work on for your edit session. Copilot Edits does not make changes outside the working set, except when suggesting to create a new file. When you use agent mode, Copilot autonomously determines which files to edit and adds them to the working set.
工作集是你希望 Copilot Edits 在编辑会话中处理的文件集合。Copilot Edits 不会在工作集之外进行更改,除非建议创建新文件。当你使用代理模式时,Copilot 会自主确定要编辑的文件并将它们添加到工作集。

Screenshot of Copilot Edits, showing the working set contains 3 files, including the currently opened file.

Important   重要

The working set is currently limited to 10 files.
当前工作集限制为 10 个文件。

Copilot Edits automatically adds the active editor to the working set. If you have multiple editor groups, the active editor for each group is added to the working set. To add all open editors, select Add Files..., and then choose Open Editors from the Files Quick Pick.
Copilot Edits 自动将活动编辑器添加到工作集。如果您有多个编辑器组,则每个组的活动编辑器都将添加到工作集。要添加所有打开的编辑器,请选择“添加文件...”,然后从“文件快速选择”中选择“打开的编辑器”。

You have many options to add files to the working set:
您有多个选项可以将文件添加到工作集:

  • Select Add Files... or use the Attach icon (Ctrl+/), and then select files in the Quick Pick.
    选择“添加文件...”或使用“附件”图标(Ctrl+/),然后从快速选择中选择文件。

    Tip   提示

    To quickly select multiple items from a Quick Pick, use the Up and Down keys to navigate the list, use the Right key to add the item as context, and then repeat this for other items.
    快速从快速选择中选择多个项目,使用上下键导航列表,使用右键将项目添加为上下文,然后对其他项目重复此操作。

    Screenshot showing the Copilot Edits view and the file search Quick Pick, highlighting the buttons to add context.

  • Let Copilot find the right files automatically by adding #codebase in your prompt.
    通过在提示中添加 #codebase ,让 Copilot 自动找到正确的文件。

    Make sure to enable the github.copilot.chat.edits.codesearch.enabled (preview) setting to get the best results.
    确保启用 github.copilot.chat.edits.codesearch.enabled(预览)设置以获得最佳结果。

  • Drag and drop editor tabs, or files or folders from the Explorer view, Search view, or editor breadcrumb onto the Copilot Edits view.
    拖放编辑标签页、文件或文件夹从资源管理器视图、搜索视图或编辑面包屑导航到 Copilot Edits 视图。

    When you drop a folder onto the Copilot Edits view, all files in that folder are added to the working set.
    当您将文件夹拖放到 Copilot Edits 视图中时,该文件夹中的所有文件都将添加到工作集。

  • Right-click on a file in the Explorer view or Search view and select Add File to Copilot Edits.
    在资源管理器视图或搜索视图中右键单击一个文件,然后选择将文件添加到 Copilot 编辑。

  • Select a suggested file. When you add one or more files to the working set, Copilot Edits proposes other relevant files based on the Git history.
    选择一个建议的文件。当你将一个或多个文件添加到工作集时,Copilot Edits 会根据 Git 历史记录提出其他相关文件。

    If you don't want to see these suggestions, you can disable them with the github.copilot.chat.edits.suggestRelatedFilesFromGitHistory setting.
    如果您不想看到这些建议,可以通过 github.copilot.chat.edits.suggestRelatedFilesFromGitHistory 设置来禁用它们。

When Copilot Edits generates edits for your project, it visually indicates which files in the working set are edited. Select a file in the working set to open it and view the proposed edits in the editor.
当 Copilot Edits 为您生成项目编辑时,它会直观地显示工作集中哪些文件被编辑。选择工作集中的文件以打开它并在编辑器中查看建议的编辑。

Screenshot showing the Copilot Edits response for "Add a feedback field in the contact page" and showing the diff in the editor.

Accept or discard edits
接受或丢弃编辑

Copilot Edits gives you a code review flow where you can accept or discard each of the AI-generated edits. If you discard the edits, the modified files are restored to their previously accepted state.
Copilot Edits 为您提供了一种代码审查流程,您可以在其中接受或拒绝每个由 AI 生成的编辑。如果您拒绝编辑,则修改后的文件将恢复到之前接受的状态。

With the editor overlay controls, you can navigate between the suggested edits by using the and controls. Use the Accept or Discard button to accept or reject the edits for a given file.
使用编辑器叠加控件,您可以通过使用和控件在建议的编辑之间导航。使用“接受”或“拒绝”按钮接受或拒绝给定文件的编辑。

Screenshot showing the Editor with proposed changes, highlighting the review controls in the editor table bar.

To accept or discard a specific edit within a file, hover over the code edit and use the Accept or Discard controls for that edit.
在文件中接受或丢弃特定编辑,将鼠标悬停在代码编辑上,并使用该编辑的接受或丢弃控件。

Alternatively, you can also accept or discard the changes from the working set in the Copilot Edits view:
另外,您也可以在 Copilot Edits 视图中接受或拒绝工作集的更改:

  • Select Accept (Ctrl+Enter) or Discard (Ctrl+Backspace) in the working set title bar to accept or discard all edits in the working set
    选择接受(Ctrl+Enter)或丢弃(Ctrl+Backspace)在工作集标题栏中,以接受或丢弃工作集中的所有编辑

  • Select the Accept or Discard icon on an individual working set file to apply the action to that specific file
    选择单个工作集文件上的接受或丢弃图标以将该操作应用于该特定文件

Screenshot showing the Copilot Edits view, highlighting the Accept All and Discard All buttons.

With the chat.editing.autoAcceptDelay setting, you can configure a delay after which the suggested edits are automatically accepted. Hover over the editor overlay controls to cancel the auto-accept countdown.
使用 chat.editing.autoAcceptDelay 设置,您可以配置在建议的编辑自动接受后的延迟。将鼠标悬停在编辑器覆盖控制上以取消自动接受倒计时。

When you close VS Code, the status of the pending edits is remembered. When you reopen VS Code, the pending edits are restored and you can still accept or discard the edits.
当你关闭 VS Code 时,挂起的编辑状态会被记住。当你重新打开 VS Code 时,挂起的编辑会被恢复,你仍然可以接受或丢弃这些编辑。

Note   注意

In agent mode, edits are automatically saved to disk, regardless if Auto Save (files.autoSave) is enabled. You can still review the edits and choose to discard them if needed.
在代理模式下,编辑会自动保存到磁盘,无论是否启用了自动保存(files.autoSave)。您仍然可以查看编辑并选择在需要时丢弃它们。

Undo edits  撤销编辑

As you're sending requests to make edits to your code, you might want to roll back some of these changes, for example because you want to use another implementation strategy.
当你发送请求以编辑你的代码时,你可能想要撤销其中一些更改,例如因为你想要使用另一种实现策略。

You can use the Undo Last Edit control in the Copilot Edits view title bar to revert the last edits and return to the state before sending the last request. After you perform an undo of the last edits, you can redo those edits again by using the Redo Last Edit control in the Copilot Edits view title bar.
您可以使用“撤销上次编辑”控件在“Copilot 编辑”视图标题栏中撤销上次编辑并返回发送上次请求之前的状态。在您执行撤销上次编辑操作后,可以通过使用“重做上次编辑”控件在“Copilot 编辑”视图标题栏中再次执行这些编辑。

Screenshot showing the Copilot Edits view, highlighting the Undo and Redo actions in the view title bar.

You can also use the Undo Edits (Delete) control when hovering over a request in the Copilot Edits view to revert all edits that were made from that request onwards.
您还可以在 Copilot Edits 视图中悬停于一个请求上方时使用撤销编辑(删除)控件来撤销从该请求开始所做的所有编辑。

Screenshot showing the Copilot Edits view, highlighting the Undo Edits control for a specific request.

Tip   提示

Sometimes Copilot starts walking down the wrong path when generating edits. Once that happens, it can be hard to convince it about another approach by adding to the conversation. In that case, use Undo Last Edit to the point where you agree with Copilot's responses. Then restart from there with a refined prompt.
有时 Copilot 在生成编辑时可能会走错路。一旦发生这种情况,通过添加到对话中来说服它采用另一种方法可能会很困难。在这种情况下,使用“撤销上次编辑”直到你同意 Copilot 的回复。然后从那里重新开始,使用更精细的提示。

Send a chat request to Copilot Edits
发送给 Copilot Edits 的聊天请求

Copilot Chat is great for asking questions and exploring ideas about your project or technology topics in general. Rather than applying each code block from Copilot Chat to your code, you can transfer the chat session to Copilot Edits. Copilot Edits is optimized for code editing and can apply code suggestions directly in your code, across multiple files simultaneously.
Copilot Chat 非常适合提问和探讨关于您的项目或一般技术主题的想法。与其将 Copilot Chat 中的每个代码块应用到您的代码中,您可以将聊天会话转移到 Copilot Edits。Copilot Edits 针对代码编辑进行了优化,可以直接在您的代码中、跨多个文件同时应用代码建议。

In the Chat view, select the Edit with Copilot button at the bottom of the chat conversation to apply the suggested code changes with Copilot Edits. If you have multiple chat requests in the chat session, you can select which requests you want to transfer to Copilot Edits.
在聊天视图中,选择聊天对话底部的“使用 Copilot 编辑”按钮,以应用 Copilot 编辑建议的代码更改。如果您在聊天会话中有多个聊天请求,您可以选择要将哪些请求转移到 Copilot 编辑。

Screenshot highlighting the Edit with Copilot button in the Chat view to move a chat conversation to Copilot Edits.

After moving a chat request to Copilot Edits, the chat request is removed from the chat conversation in the Chat view.
将聊天请求移动到 Copilot 编辑后,聊天请求将从聊天视图中移除。

Agent mode tools  代理模式工具

To complete a request, Copilot Edits uses a set of tools to accomplish the individual tasks. Consider these tools as specialized utilities that Copilot can use to perform a specific task. Examples of such tasks are listing the files in a directory, editing a file in your workspace, running a terminal command, getting the output from the terminal, and more.
完成请求时,Copilot Edits 使用一系列工具来完成单个任务。将这些工具视为 Copilot 可以用来执行特定任务的专用工具。此类任务的示例包括列出目录中的文件、编辑工作空间中的文件、运行终端命令、获取终端输出等。

Based on the outcome of a tool, Copilot might invoke other tools to accomplish the overall request. For example, if a code edit results in syntax errors in the file, Copilot might explore another approach and suggest different code changes.
基于工具的结果,Copilot 可能会调用其他工具来完成整体请求。例如,如果代码编辑导致文件中出现语法错误,Copilot 可能会探索另一种方法并建议不同的代码更改。

Although agent mode can operate in an autonomous manner, you maintain control over the generated edits and the terminal commands that are run.
尽管代理模式可以自主运行,但您仍可控制生成的编辑和运行的终端命令。

Settings  设置

The following list contains the settings related to Copilot Edits. You can configure settings through the Setting editor (Ctrl+,).
以下列表包含与 Copilot 编辑相关的设置。您可以通过设置编辑器(Ctrl+,)来配置设置。

  • chat.editing.confirmEditRequestRemoval - ask for confirmation before undoing an edit (default: true)
    聊天编辑.确认编辑请求删除 - 在撤销编辑前请求确认(默认: true
  • chat.editing.confirmEditRequestRetry - ask for confirmation before performing a redo of the last edit (default: true)
    聊天编辑.确认编辑请求重试 - 在执行上一次编辑的重做之前请求确认(默认: true
  • chat.editing.alwaysSaveWithGeneratedChanges - automatically save generated changes from Copilot Edits to disk (default: false)
    聊天编辑.始终保存生成的更改到磁盘(默认: false
  • chat.agent.enabled - enable or disable agent mode in Copilot Edits (default: false)
    聊天代理启用 - 在 Copilot Edits 中启用或禁用代理模式(默认: false
  • chat.editing.autoAcceptDelay - configure a delay after which suggested edits are automatically accepted, use zero to disable auto-accept (default: 0)
    聊天编辑自动接受延迟 - 配置在建议编辑自动接受之前的延迟时间,使用零来禁用自动接受(默认:0)
  • github.copilot.chat.edits.codesearch.enabled (preview) - let Copilot find the right files by adding #codebase to your prompt, similar to how agent mode works (default: false)
    github.copilot.chat.edits.codesearch.enabled (预览) - 通过在提示中添加 #codebase 让 Copilot 找到正确的文件,类似于代理模式的工作方式(默认: false
  • chat.agent.maxRequests - maximum number of requests that Copilot Edits can make in agent mode (default: 5 for Copilot Free users, 15 for other users)
    chat.agent.maxRequests - Copilot Edits 在代理模式下的最大请求数量(默认:Copilot Free 用户为 5,其他用户为 15)

Keyboard shortcuts  键盘快捷键

The following list contains the default keyboard shortcuts related to Copilot Edits. You can modify any of the default keyboard shortcuts by using the Keyboard Shortcuts editor (Ctrl+K Ctrl+S).
以下列表包含与 Copilot 编辑相关的默认键盘快捷键。您可以通过使用键盘快捷键编辑器(Ctrl+K Ctrl+S)修改任何默认键盘快捷键。

  • Ctrl+Shift+I - Open the Copilot Edits view
    Ctrl+Shift+I - 打开 Copilot 编辑视图
  • Ctrl+Alt+Enter - Send a prompt from the Chat view to Copilot Edits
    Ctrl+Alt+Enter - 从聊天视图向 Copilot 编辑发送提示
  • Ctrl+/ - Attach context to your prompt
    Ctrl+/ - 将上下文附加到您的提示中
  • unassigned - Save all edited files to disk
    未分配 - 将所有编辑过的文件保存到磁盘
  • Ctrl+Enter - Accept all edits
    Ctrl+Enter - 接受所有编辑
  • Ctrl+Backspace - Discard all edits
    Ctrl+Backspace - 放弃所有编辑
  • Shift+Alt+F5 - Navigate to the previous edit within a file
    Shift+Alt+F5 - 跳转到文件中的上一个编辑位置
  • Alt+F5 - Navigate to the next edit within a file
    Alt+F5 - 跳转到文件中的下一个编辑位置
Tip   提示

If you want to change a keyboard shortcut for an action that's specific to the Copilot Edits view, you need to include the following condition in the when clause: chatLocation == 'editing-session'.
如果您想更改特定于 Copilot Edits 视图的操作的键盘快捷键,您需要在 when 子句中包含以下条件: chatLocation == 'editing-session'

Limitations  局限性

  • Multiple simultaneous edit sessions are not supported yet.
    同时进行的多个编辑会话尚不支持。
  • The use of @workspace /new to scaffold a new project is not supported yet in an Edit session. For now, use Copilot Chat for the initial scaffolding.
    使用 @workspace /new 在编辑会话中构建新项目尚不支持。目前,请使用 Copilot Chat 进行初始构建。
  • Although #codebase is great at finding relevant context for your query, subsequent generated edits are of widely varying quality. Experiment with the github.copilot.chat.edits.codesearch.enabled (preview) setting for an improved, agentic experience to find files, or explicitly add files to your working set to create better results.
    尽管 #codebase 在查找查询的相关上下文方面很出色,但后续生成的编辑质量参差不齐。尝试使用 github.copilot.chat.edits.codesearch.enabled(预览)设置来获得更好的、更智能的体验以查找文件,或明确添加文件到您的工作集以创建更好的结果。
  • Support for Jupyter notebooks, other custom text formats, and binary file formats is absent or untested.
    Jupyter 笔记本、其他自定义文本格式和二进制文件格式的支持不存在或未经过测试。
  • The working set is currently limited to 10 files.
    当前工作集限制为 10 个文件。
  • Copilot Edits is limited to 7 editing requests per 10 minutes.
    Copilot Edits 每十分钟限制 7 次编辑请求。

Frequently asked questions
常见问题

How is Copilot Edits different from Copilot Chat?
Copilot Edits 与 Copilot Chat 有何不同?

Both Copilot Chat and Copilot Edits use a conversational interface, where you can use natural language prompts to get AI-powered suggestions. There are several distinct differences between Copilot Edits and Copilot Chat.
Copilot Chat 和 Copilot Edits 都使用对话界面,您可以使用自然语言提示来获取 AI 驱动的建议。Copilot Edits 和 Copilot Chat 之间有几个明显的区别。

Copilot Edits puts you in the context of code editing, where you start an edit session and use prompts for making changes to your codebase. Copilot Edits can generate and apply code changes directly across multiple files in your codebase. You can immediately preview the generated edits within the context of your code.
Copilot Edits 让您处于代码编辑的上下文中,您开始一个编辑会话并使用提示来修改您的代码库。Copilot Edits 可以直接在您的代码库的多个文件中生成和应用代码更改。您可以在代码的上下文中立即预览生成的编辑。

The Chat view gives you a more general-purpose chat interface for asking questions about your code or technology topics in general. Copilot can also provide code suggestions and generate code blocks as part of the chat conversation. You need to manually apply each code block to the different files in your project to evaluate their validity.
聊天视图为您提供了一个更通用的聊天界面,用于询问有关您的代码或一般技术主题的问题。Copilot 还可以在聊天对话中提供代码建议并生成代码块。您需要手动将每个代码块应用到项目中的不同文件以评估其有效性。

Inline Chat keeps you in the coding flow by providing a chat interface in the editor, where you can preview the generated code suggestions directly in the context of your code. The scope of Inline Chat is limited to the editor in which it's started, so it can only provide code suggestions for a single file. You can also use Inline Chat to ask general-purpose questions.
内联聊天通过在编辑器中提供聊天界面,让您可以直接在代码上下文中预览生成的代码建议,从而保持编码流程。内联聊天的范围仅限于启动它的编辑器,因此它只能为单个文件提供代码建议。您还可以使用内联聊天提出通用问题。

Copilot Edits also provides you a code review flow where you can easily review generated edits and decide to accept or discard them. Copilot Chat does not have this code review mechanism. In addition, you can undo past edits and roll back changes to a previous accepted state.
Copilot Edits 还为您提供了一个代码审查流程,您可以轻松审查生成的编辑并决定接受或丢弃它们。Copilot Chat 没有这个代码审查机制。此外,您可以撤销过去的编辑并将更改回滚到之前接受的状态。

The following table shows a comparison of the capabilities of each experience.
下表显示了每个体验的功能比较。

Capability  能力 Copilot Edits  Copilot 编辑 Chat view  聊天视图 Inline Chat  行内聊天 Quick Chat  快速聊天
Multi-file edits  多文件编辑 ✅* ✅*
Preview code edits  预览代码编辑
Code review flow  代码审查流程
Roll back changes  撤销更改
Attach context  附加上下文
Use participants & commands
使用参与者与命令
Generate shell commands  生成 shell 命令
General-purpose chat  通用聊天

* code blocks are included in the chat conversation and need to be applied to the right file manually
代码块包含在聊天对话中,需要手动应用到正确的文件中

Can I change the location of the Copilot Edits view?
我可以更改 Copilot 编辑视图的位置吗?

You can drag and drop the Copilot Edits view into the Activity Bar to show it in the Primary Side Bar. You can also move it to the Secondary Side Bar. Learn more about custom layouts in VS Code.
您可以拖放 Copilot Edits 视图到活动栏中,以在主侧边栏中显示它。您还可以将其移动到次级侧边栏。了解 VS Code 中自定义布局的更多信息。

Why would I use edit mode instead of agent mode?
我为什么要使用编辑模式而不是代理模式?

Consider the following criteria to choose between edit mode and agent mode:
考虑以下标准来选择编辑模式与代理模式:

  • Edit scope: you might use edit mode if your request involves only code edits and you know the precise scope and working set for the changes.
    编辑范围:如果您的要求仅涉及代码编辑且您知道更改的精确范围和工作集,则可能使用编辑模式。
  • Preview feature: agent mode is still in preview and might not work for all scenarios.
    预览功能:代理模式仍在预览中,可能不适用于所有场景。
  • Duration: agent mode involves multiple steps to process a request, so it might take longer to get a response. For example, to determine the relevant context and files to edit, determine the plan of action, and more.
    持续时间:代理模式涉及多个步骤来处理请求,因此获取响应可能需要更长的时间。例如,确定相关的上下文和要编辑的文件、确定行动方案等。
  • Non-deterministic: agent mode evaluates the outcome of the generated edits and might iterate multiple times. As a result, agent mode can be more non-deterministic than edit mode.
    非确定性:代理模式评估生成的编辑结果,可能多次迭代。因此,代理模式可能比编辑模式更具非确定性。
  • Request quota: in agent mode, depending on the complexity of the task, one prompt might result in many requests to the backend.
    请求配额:在代理模式下,根据任务复杂度,一个提示可能导致对后端发起多个请求。

Can I use Copilot Edits with notebooks?
我可以使用 Copilot Edits 与笔记本一起使用吗?

Copilot Edits support is limited when you're using notebooks. For example, agent mode is not available for working with notebooks in VS Code.
Copilot 编辑功能在使用笔记本时受到限制。例如,在 VS Code 中使用笔记本时,无法使用代理模式。

We recommend that you use Copilot Chat or Inline Chat with notebooks in VS Code instead.
我们建议您在 VS Code 中使用 Copilot Chat 或笔记本内联聊天。