# @github/copilot-language-server 中文文档

规范地址：https://npmcn.com/package/%40github/copilot-language-server/

版本：1\.570\.0
npm 元数据更新时间：2026-11-13T06:54:52.807Z
中文译文更新时间：2026-11-16T10:46:56.945Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40github/copilot-language-server
原文对照：https://npmcn.com/package/%40github/copilot-language-server/?lang=original
项目主页：https://github.com/github/copilot-language-server-release
源码仓库：https://github.com/github/copilot-language-server-release

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：90.8 MB，356 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- 运行依赖：1 个
- 首次发布：2024-09-04T14:07:50.724Z
- 最新版本发布：2026-11-13T06:54:52.573Z
- 近 30 天下载量：825878（2026-10-17 至 2026-11-15，npm 官方下载统计）
- 已发布版本数：423（近 12 个月 255 个）

## 中文简介

您的 AI 双程序员

## 安装

```sh
npm install @github/copilot-language-server
```

也可以使用：`pnpm add @github/copilot-language-server`、`yarn add @github/copilot-language-server`、`bun add @github/copilot-language-server`

## README

# @ github/ 副驾驶语言服务器

副驾驶语言服务器允许任何编辑器或IDE与 GitHub 集成 副驾驶通过 [语言服务器协议](https://microsoft.github.io/language-server-protocol/)。 。 。 .

**[GitHub 副驾驶](https://github.com/features/copilot)** 是一个AI配对程序员工具,可以帮助您更快和更聪明地写入代码.

**报名 [GitHub 免费副驾驶](https://github.com/settings/copilot)来啊!**

请看 [gitHub 副驾驶的使用条款](https://docs.github.com/en/site-policy/github-terms/github-terms-for-additional-products-and-features#github-copilot)

## 开始

要与副驾驶语言服务器整合, 请从 npm 下载最新版本 :

```sh
npm install @github/copilot-language-server
```

要运行语言服务器,可单独使用特定平台的二进制 作为可选依赖性包含的软件包。 譬如说, [`@github/copilot-language-server-darwin-arm64`](https://www.npmjs.com/package/@github/copilot-language-server-darwin-arm64)对于手臂上的macOS64: 例如,在arm64上的macOS:

```sh
./node_modules/@github/copilot-language-server-darwin-arm64/copilot-language-server --version
```

如果重新包装语言服务器, 所有平台专用的二进制都可用 在释放中: [https://github.com/github/copilot-language-server-release-release/releases 互联网档案馆的存檔,存档日期2013-12-02. 互联网档案馆的存檔,存档日期2013-12-02](https://github.com/github/copilot-language-server-release/releases) 例如,要下载所有二进制的拉链:

```
gh release download -R github/copilot-language-server-release -p 'copilot-language-server-native-*'
```

你也可以用这个 [节点.js](https://nodejs.org/en/download/) 第20.8版或以后版本:

```sh
npx @github/copilot-language-server --version
```

```sh
node ./node_modules/@github/copilot-language-server/dist/language-server.js --version
```

如果使用 `language-server.js` 分配,必须保留全部 `dist` 目录内容.

与语言服务器的通信通常发生在 stdio 上 `--stdio`编辑 `language-server.js` 发行时另外支持节点 IPC `--node-ipc`。 。 。 .

## 代理客户协议( ACP)

副驾驶语言服务器也支持 [代理客户协议( ACP)](https://agentclientprotocol.com/), (中文(简体) ), 与非加太公司兼容的客户融合 [JetBrains 空军](https://www.jetbrains.com/air/), (中文(简体) ), [JetBrains 大赦国际助理](https://www.jetbrains.com/help/ai-assistant/acp.html), (中文(简体) ), [齐德](https://zed.dev/)还有更多.

### 在非加太模式下运行

要以 ACP 模式启动语言服务器 :

```sh
npx -y @github/copilot-language-server --acp
```

或者如果安装在本地 :

```sh
node ./node_modules/@github/copilot-language-server/dist/language-server.js --acp
```

沟通发生在 stdin/ stdout.

### JetBrains航空和JetBrains航空助理

GitHub 副驾驶作为内置代理在 [JetBrains 空军](https://www.jetbrains.com/air/) 财务报告和审定财务报表 [JetBrains 大赦国际助理](https://www.jetbrains.com/help/ai-assistant/copilot-agent.html),因此没有手动的 ACP 配置 通常使用时需要使用.

要手动将副驾驶语言服务器注册为自定义的 ACP 代理,请在 `~/.jetbrains/acp.json`数字 :

```json
{
  "agent_servers": {
    "GitHub Copilot": {
      "command": "npx",
      "args": [
        "@github/copilot-language-server@latest",
        "--acp"
      ],
      "env": {
        "VARIABLE_NAME": "value"
      }
    }
  }
}
```

可选 `env` 对象可用于将环境变量传递到代理进程。 无额外时删除 需要环境变量。 有关内置航空一体化的更多信息,请参见: [在JetBrains航空的 GitHub 副驾驶](https://devblogs.microsoft.com/java/github-copilot-jetbrains-air/)。 。 。 .

见 [非加太国家规格](https://agentclientprotocol.com/) 完整协议细节.

## 通讯议定书

这个 [语言服务器协议](https://microsoft.github.io/language-server-protocol/) (LSP)用于与 客户 基础协议是 [JSON-RPC 2.0 附加数据 页眉](https://microsoft.github.io/language-server-protocol/specifications/specification-current/#baseProtocol)。 。 。 .

副驾驶语言服务器试图尽可能密切跟踪 LSP 规格,但许多自定义消息是 用于支持副驾驶的独特性.

## 初始化

根据LSP规格,客户端预计将发送 [`initialize`](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#initialize) 作为第一个消息请求语言服务器。 示例参数:

```json
{
    "processId": 1234,
    "workspaceFolders": [
        {
            "uri": "file:///home/user/project"
        }
    ],
    "capabilities": {
        "workspace": {"workspaceFolders": true}
    },
    "initializationOptions": {
        "editorInfo": {
            "name": "GNU ed",
            "version": "1.19"
        },
        "editorPluginInfo": {
            "name": "GitHub Copilot for ed",
            "version": "1.0.0"
        }
    }
}
```

收到答复后 `initialize`,客户端必须发送的第二个信息是 [`initialized`](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#initialized) 通知.

## 配置管理

初始化后,客户端应当发送 [`workspace/didChangeConfiguration`](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_didChangeConfiguration) 通知将初始配置告知语言服务器,并每次再次告知配置 变化。 示例参数:

```json
{
     "settings": {
        "http": {
            "proxy": "http://localhost:8888",
            "proxyStrictSSL": true,
            "proxyKerberosServicePrincipal": "spn"
        },
        "telemetry": {
            "telemetryLevel": "all"
        },
        "github-enterprise": {
            "uri": "https://example.ghe.com"
        }
    }
}
```

调用基于配置 [`workspace/configuration`](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_configuration) 也得到支持.

## 工作空间文件夹同步

工作空间文件夹是可选的,但极受推荐,因为它们大大提高了建议的质量。 见 LSP 规格 [`workspace/didChangeWorkspaceFolders`](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_didChangeWorkspaceFolders)。 。 。 .

## 文本文档同步

按 LSP 规格 [文本文档同步](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_synchronization), (中文(简体) ), 支持 `textDocument/didOpen`, (中文(简体) ), `textDocument/didChange`,以及 `textDocument/didClose` 需要使用递增 同步 .

## 文本文档焦点

外加习俗 `textDocument/didFocus` 当客户端聚焦另一文档时,应当发送通知 (如更改分页). 示例参数:

```json
{
    "textDocument": {
        "uri": "file:///path/to/file"
    }
}
```

如果没有文件聚焦,则请求无参数(`{}`可发去.

## 状态通知

状态作为 `didChangeStatus` 通知。 通常,这将在 状态栏图标或其他UI支付.

通知包括下列领域:

-   `busy` - 布尔表示任务是否正在进行中
-   `message` - 描述状态的字符串( 可以是空的)
-   `kind` - 语言服务器状态 :
    -   `'Normal'` - 当一切都正常的时候.
    -   `'Error'` - 未经批准和认证.
    -   `'Warning'` - 当存在临时问题时,例如HTTP请求失败.
    -   `'Inactive'` - 当由于文件大小或内容排除而忽略当前文件时.
-   `command` - 一个可选的LSP `Command` 为客户端提供可操作命令的对象(例如,签入,更多地了解配额限制)

## 认证

要报名,打电话 `signIn`。这将返回如下回复:

```json
{
    "userCode": "ABCD-EFGH",
    "command": {
        "command": "github.copilot.finishDeviceFlow",
        "arguments": [],
        "title": "Sign in"
    }
}
```

指示用户复制 `userCode` 输入剪贴板(和/或程序复制)。 当用户准备好时,请引用 [`workspace/executeCommand`](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_executeCommand) 执行 `command`。这将打开浏览器窗口,让用户通过认证程序. 用户完成签名后不久(最多10秒),您应该看到反映新状态的状态通知 状态.

如果可用, 语言服务器将使用 [`window/showDocument`](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#window_showDocument) 打开 URL。 否则,它将试图以本地方式打开URL(例如: `/usr/bin/open` (原始内容存档于2018-09-28). on macOS.

签个字,打个电话 `signOut`。 。 。 .

## 内置补全

这个 [`textDocument/inlineCompletion`](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.18/specification/#textDocument_inlineCompletion) 从下一个 LSP 光谱的草稿版本中请求, 用于取回内置( “ 鬼文字 ” ) 的补全, 并带有一些 非标准添加(`textDocument.version` 财务报告和审定财务报表 `formattingOptions`参数:

```json
{
    "textDocument": {
        "uri": "file:///path/to/file",
        "version": 0
    },
    "position": {"line": 1, "character": 2},
    "context": {
        "triggerKind": 2
    },
    "formattingOptions": {
        "tabSize": 4,
        "insertSpaces": true
    }
}
```

结果是一个包含 `items` 阵列.

```json
{
    "items": [
        {
            "insertText": "a helpful suggestion",
            "range": {
                "start": {"line": 1, "character": 0},
                "end": {"line": 1, "character": 2}
            },
            "command": {
                "command": "github.copilot.didAcceptCompletionItem",
                "arguments": ["some id"]
            }
        }
    ]
}
```

新建行数 `insertText` 在插入文档之前,编辑器应当酌情恢复正常.

这个 `command` 字段,根据 LSP 规格,称为通过 [`workspace/executeCommand`](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_executeCommand) _之后_ 用户接受完成。 副驾驶使用此来进行接收遥测.

LSP 光谱没有为显示完成提供事件, 所以自定义 `textDocument/didShowCompletion` 已使用. 用一个叫 `item` 包含全部完成项的参数:

```json
{
    "item": {
        "insertText": "a helpful suggestion",
        "range": {
            "start": {"line": 1, "character": 0},
            "end": {"line": 1, "character": 2}
        },
        "command": {
            "command": "github.copilot.didAcceptCompletionItem",
            "arguments": ["some id"]
        }
    }
}
```

同样,对于部分接受,则发送: `textDocument/didPartiallyAcceptCompletion` 通知全文 ,加上(在UTF-16编码点中)被接受的完成长度:

```json
{
    "item": {
        "insertText": "a helpful suggestion",
        "range": {
            "start": {"line": 1, "character": 0},
            "end": {"line": 1, "character": 2}
        },
        "command": {
            "command": "github.copilot.didAcceptCompletionItem",
            "arguments": ["some id"]
        }
    },
    "acceptedLength": 9
}
```

注意 `acceptedLength` 包括从开始的一切 `insertText` 改为已接受文本的末尾。 没错 _没有_ 所接受文本本身的长度.

## 下次编辑建议

`textDocument/copilotInlineEdit` 是用于获取“ 下一次编辑” 的自定义方法 内含可包括删除或 对现有文本的修改,不得置于光标上。 这些 类似内在补全,API形状也相似. 不过 是一种单独的方法,可以选择进入特性并区分 这两类建议.

请求参数类似于 [`TextDocumentPositionParams`](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.18/specification/#textDocumentPositionParams) 但有一个 `textDocument.version` 所需字段 [`VersionedTextDocumentIdentifier`](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.18/specification/#versionedTextDocumentIdentifier)数字 :

```json
{
    "textDocument": {
        "uri": "file:///path/to/file",
        "version": 0
    },
    "position": {"line": 1, "character": 2}
}
```

结果是一个包含 `edits` 数组 :

```json
{
    "edits": [
        {
            "text": "an edit suggestion",
            "textDocument": {
                "uri": "file:///path/to/file",
                "version": 0
            },
            "range": {
                "start": {"line": 1, "character": 0},
                "end": {"line": 1, "character": 5}
            },
            "command": {
                "title": "Accept inline edit",
                "command": "github.copilot.didAcceptCompletionItem",
                "arguments": ["some-id"]
            }
        }
    ]
}
```

这个 `command` 字段,根据 LSP 规格,称为通过 [`workspace/executeCommand`](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_executeCommand) _之后_ 用户接受编辑。 副驾驶使用此来进行接收遥测. 每个编辑也可能带有可选 `requestedLanguageId` 财务报告和审定财务报表 `targetLanguageId` 与生成请求的文档的 CLS 所检测语言并 页:1 `textDocument` 正在接收编辑.

LSP 光谱没有为显示编辑提供事件, 所以自定义 `textDocument/didShowInlineEdit` 已使用。 用一个叫 `item` 参数 包含从 `edits` 数组(注意只需要第一个参数), 和可选 `viewKind` 描述向用户显示的第一个演示文稿:

```json
{
    "item": {
        "command": {
            "arguments": ["some-id"]
        }
    },
    "viewKind": "inlineDiff"
}
```

有已知源属性的编辑包括可选 `cacheTelemetryContext`。 。 。 . 保留此不透明字符串并带有缓存副本 。 在每个客户端- cache 服务上创建一个 本地新机会标识并跟踪其存在周期; 不重用源标识 或等待CLS。 或等待CLS。 将上下文保留到事件结束, 即使缓存结束 过期, 然后发送一个 `textDocument/reportCachedInlineEdit` 通知:

```json
{
    "opportunityId": "unique-id-for-this-cache-serve",
    "context": "<unchanged cacheTelemetryContext from the source edit>",
    "isShown": true,
    "acceptance": "accepted"
}
```

`acceptance` 实值 `accepted`, (中文(简体) ), `rejected`,或 `notAccepted`· ; `disposalReason` 实值 选项。 从未提交的成果报告 `isShown: false` 财务报告和审定财务报表 `notAccepted`。 。 。 . 不为这些缓存ID发送普通提供者反馈 .

CLS 验证上下文并释放现有的 `copilot-nes/provideInlineEdit` 事件为 `isFromCache=1` 和原始请求/模型/ExP归属。 没有 源查询,ACK,或遥测-触发模型请求. 上下文包含无 源代码,证书或原始 ExP 过滤器/可变. 无效上下文 已登录/ 已投放; 最近重复被压制 。 交付仍然是最好的努力, 并且没有发明缓存延迟/托肯/ARC测量.

普通提供者反馈不变;废弃提供者结果使用 `github.copilot.didIgnoreNextEditSuggestionItem`保留缺失/空白上下文 遗留客户端行为。 已更正的汇报船舶 CLS/plugin 版本,没有单独的推出旗;原始模型实验 任务仍然保留.

## 统一建议

`textDocument/copilotSuggest` 是一种自定义方法,用于要求内置补全,然后在其中编辑下一条建议 请求。 服务器在触发原因允许的情况下给供应商打电话,选择胜者,最多返回一个 建议,因此客户不需要在二者之间作出选择. `textDocument/inlineCompletion` 财务报告和审定财务报表 `textDocument/copilotInlineEdit` 现保持不变,可供使用.

CLS 可以使用默认关闭选择一个孤立的统一模型 `copilotunifiedmodelenabled` 并完整显示 `copilotunifiedmodelconfig` ExP 变量。 电线合同和反馈种类不变. SDK 引用/文本限制和零预测冷启动兼容性 路线明确;见 [统一型号的路由](https://npmcn.com/package/%40github/doc/copilot_suggest.md#unified-model-routing)。 。 。 .

参数结合了两种方法的参数,并增加了: `reason` 请求:

```json
{
    "textDocument": {
        "uri": "file:///path/to/file",
        "version": 0
    },
    "position": {"line": 1, "character": 2},
    "reason": "typing",
    "include": {"completions": true, "edits": true},
    "formattingOptions": {
        "tabSize": 4,
        "insertSpaces": true
    }
}
```

`reason` 决定要求哪些提供者:

| `reason` | 问 |
| --- | --- |
| `typing` | 完成和下一次编辑 |
| `manual` | 完成情况 |
| `cycling` | 结业(别名: `manual`(中文(简体) ) |
| `caretMove` | 下次编辑 |
| `postAccept` | 下次编辑 |

一个未知 `reason` 被视为 `typing`选项 `include` 关闭一个原因允许的提供者 以实例来纪念用户设置; 它从不打开一个 . `context.selectedCompletionInfo` 财务报告和审定财务报表 `formattingOptions` 表示与 `textDocument/inlineCompletion`,以及 `diagnostics`如果给定,则传递给下一个编辑提供者 与 `textDocument/copilotInlineEdit`。 。 。 .

当插入新文本时, 补全会获胜; 只需在光标被丢弃后重复文本 。 否则 后一编辑获胜。 结果是带有可选对象 `suggestion`,当没有显示时缺席:

```json
{
    "suggestion": {
        "id": "some-id",
        "kind": "completion",
        "presentation": "ghostText",
        "target": {
            "uri": "file:///path/to/file",
            "version": 0
        },
        "items": [
            {
                "text": "a helpful suggestion",
                "range": {
                    "start": {"line": 1, "character": 0},
                    "end": {"line": 1, "character": 2}
                },
                "command": {
                    "title": "Completion Accepted",
                    "command": "github.copilot.didAcceptCompletionItem",
                    "arguments": ["some-id"]
                }
            }
        ],
        "provenance": {"viaProxy": true, "model": "some-model", "fromCache": false}
    }
}
```

-   `kind` 建议是: `completion`, (中文(简体) ), `edit`,或 `jump`,在另一个文档中编辑 `target`。 。 。 . 它决定如何报告结果.
-   `presentation` 是怎样画它: `ghostText`, (中文(简体) ), `diff`,或 `jump`绘制 `presentation` 报告 `kind`; 数据 两者在未来版本中可能有所不同.
-   `items` 持有单项中标项目并接受 `command`。 。 。 .
-   A 类 `jump` 可能携带 `targetLine`: 目标文档中要预览的行,作为单词级diff.
-   一个 `edit` 或者说 `jump` 可能携带 `requestedLanguageId` 财务报告和审定财务报表 `targetLanguageId`: CLS 探测语言 生成请求的文档和 `target` 正在接收编辑的文档.
-   `provenance.model` 财务报告和审定财务报表 `provenance.fromCache` 描述第一个项目,当其提供者不在场时则缺席 报告他们. `fromCache` 意思是没有打模型就送货了.

跳过一个建议 `kind` 或者说 `presentation` 您不识别,因为可能会添加新的值.

报告的结果是: `kind` ,通过显示或接受的项目。 对a `completion`发送 `textDocument/didShowCompletion` 财务报告和审定财务报表 `textDocument/didPartiallyAcceptCompletion` 说明 [内置补全](https://npmcn.com/package/%40github/copilot-language-server/#readme-inline-completions)对于一个 `edit` 或一个 `jump`发送 `textDocument/didShowInlineEdit` 说明 内 [下次编辑建议](https://npmcn.com/package/%40github/copilot-language-server/#readme-next-edit-suggestions)。在所有情况下,拨打项目 `command` 通过 `workspace/executeCommand` 用户接受后。 下一次编辑返回此方式时带不 `cacheTelemetryContext`数字 : 服务器本身缓存它们.

## 小组完成情况

面板完成用于"开放副驾驶"风格完成. 它们与内含完成类似,但被显示 在一个单独的面板。 使用自定义检索 `textDocument/copilotPanelCompletion` 请求,它已经 参数紧接其后 `textDocument/inlineCompletion`数字 :

```json
{
    "textDocument": {
        "uri": "file:///path/to/file",
        "version": 0
    },
    "position": {"line": 1, "character": 2},
    "partialResultToken": "some token"
}
```

如果提供,则 `partialResultToken` 用于流 [部分结果](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#partialResults) 回到客户端。 返回类型和部分结果类型与内含补全相同:一个对象 包含 `items` 阵列。 这些项目相同 `command` 必须援引 `workspace/executeCommand` 在接受接受遥测后 这里不支持部分接受和显示的事件 .

## 取消

`textDocument/inlineCompletion` 支持取消的先前策略 : 如果您发送了新的补全 请求,上一请求被取消. `textDocument/copilotSuggest` 请求完成时分享此信息 战略 `textDocument/inlineCompletion`,而一个被取代的 失败的相同 `ServerCancelled` 错误. 这也适用于代理在完成调用后等待NES时.

此外,《劳动法》 `$/cancelRequest` 用于取消任何请求的方法。 强烈鼓励它迫切地 尽快取消完成请求.

## 日志

日志作为 [`window/logMessage`](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#window_logMessage) 通知书.

## 信件

可以发送客户端 [`window/showMessageRequest`](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#window_showMessage) 请求。 对这些信息的支持至关重要,因为它们用于重要通知,包括账户和账户 计费.

* * *

## 许可证

以麻省理工学院许可证分发。 详情见LICENSE.

## 常见问题

### @github/copilot-language-server 是什么？

您的 AI 双程序员

### 如何安装 @github/copilot-language-server？

在项目目录运行 npm install @github/copilot-language-server，或使用 pnpm add / yarn add / bun add。它还提供命令行工具 copilot-language-server，可以用 npx copilot-language-server 直接运行。

### @github/copilot-language-server 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @github/copilot-language-server 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### @github/copilot-language-server 可以商用吗？

@github/copilot-language-server 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @github/copilot-language-server 的下载量有多少？

根据 npm 官方下载统计，@github/copilot-language-server 在 2026/10/17 – 2026/11/15 这 30 天内被下载 825,878 次，日均约 27,529 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @github/copilot-language-server 还在维护吗？

最新版本 1\.570\.0 发布于 2026/11/13（3 天前）；至今共发布 423 个版本，其中过去 12 个月发布了 255 个；首次发布于 2024/09/04。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

