@ github/ 副驾驶语言服务器
副驾驶语言服务器允许任何编辑器或IDE与 GitHub 集成 副驾驶通过 语言服务器协议。 。 。 .
GitHub 副驾驶 是一个AI配对程序员工具,可以帮助您更快和更聪明地写入代码.
报名 GitHub 免费副驾驶来啊!
开始
要与副驾驶语言服务器整合, 请从 npm 下载最新版本 :
npm install @github/copilot-language-server
要运行语言服务器,可单独使用特定平台的二进制
作为可选依赖性包含的软件包。 譬如说, @github/copilot-language-server-darwin-arm64对于手臂上的macOS64:
例如,在arm64上的macOS:
./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 例如,要下载所有二进制的拉链:
gh release download -R github/copilot-language-server-release -p 'copilot-language-server-native-*'
你也可以用这个 节点.js 第20.8版或以后版本:
npx @github/copilot-language-server --version
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), (中文(简体) ), 与非加太公司兼容的客户融合 JetBrains 空军, (中文(简体) ), JetBrains 大赦国际助理, (中文(简体) ), 齐德还有更多.
在非加太模式下运行
要以 ACP 模式启动语言服务器 :
npx -y @github/copilot-language-server --acp
或者如果安装在本地 :
node ./node_modules/@github/copilot-language-server/dist/language-server.js --acp
沟通发生在 stdin/ stdout.
JetBrains航空和JetBrains航空助理
GitHub 副驾驶作为内置代理在 JetBrains 空军 财务报告和审定财务报表 JetBrains 大赦国际助理,因此没有手动的 ACP 配置 通常使用时需要使用.
要手动将副驾驶语言服务器注册为自定义的 ACP 代理,请在
~/.jetbrains/acp.json数字 :
{
"agent_servers": {
"GitHub Copilot": {
"command": "npx",
"args": [
"@github/copilot-language-server@latest",
"--acp"
],
"env": {
"VARIABLE_NAME": "value"
}
}
}
}
可选 env 对象可用于将环境变量传递到代理进程。 无额外时删除
需要环境变量。 有关内置航空一体化的更多信息,请参见:
在JetBrains航空的 GitHub 副驾驶。 。 。 .
见 非加太国家规格 完整协议细节.
通讯议定书
这个 语言服务器协议 (LSP)用于与 客户 基础协议是 JSON-RPC 2.0 附加数据 页眉。 。 。 .
副驾驶语言服务器试图尽可能密切跟踪 LSP 规格,但许多自定义消息是 用于支持副驾驶的独特性.
初始化
根据LSP规格,客户端预计将发送
initialize
作为第一个消息请求语言服务器。 示例参数:
{
"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
通知.
配置管理
初始化后,客户端应当发送
workspace/didChangeConfiguration
通知将初始配置告知语言服务器,并每次再次告知配置
变化。 示例参数:
{
"settings": {
"http": {
"proxy": "http://localhost:8888",
"proxyStrictSSL": true,
"proxyKerberosServicePrincipal": "spn"
},
"telemetry": {
"telemetryLevel": "all"
},
"github-enterprise": {
"uri": "https://example.ghe.com"
}
}
}
调用基于配置
workspace/configuration
也得到支持.
工作空间文件夹同步
工作空间文件夹是可选的,但极受推荐,因为它们大大提高了建议的质量。 见 LSP 规格
workspace/didChangeWorkspaceFolders。 。 。 .
文本文档同步
按 LSP 规格
文本文档同步, (中文(简体) ),
支持 textDocument/didOpen, (中文(简体) ), textDocument/didChange,以及 textDocument/didClose 需要使用递增
同步 .
文本文档焦点
外加习俗 textDocument/didFocus 当客户端聚焦另一文档时,应当发送通知
(如更改分页). 示例参数:
{
"textDocument": {
"uri": "file:///path/to/file"
}
}
如果没有文件聚焦,则请求无参数({}可发去.
状态通知
状态作为 didChangeStatus 通知。 通常,这将在
状态栏图标或其他UI支付.
通知包括下列领域:
busy- 布尔表示任务是否正在进行中message- 描述状态的字符串( 可以是空的)kind- 语言服务器状态 :'Normal'- 当一切都正常的时候.'Error'- 未经批准和认证.'Warning'- 当存在临时问题时,例如HTTP请求失败.'Inactive'- 当由于文件大小或内容排除而忽略当前文件时.
command- 一个可选的LSPCommand为客户端提供可操作命令的对象(例如,签入,更多地了解配额限制)
认证
要报名,打电话 signIn。这将返回如下回复:
{
"userCode": "ABCD-EFGH",
"command": {
"command": "github.copilot.finishDeviceFlow",
"arguments": [],
"title": "Sign in"
}
}
指示用户复制 userCode 输入剪贴板(和/或程序复制)。 当用户准备好时,请引用
workspace/executeCommand
执行 command。这将打开浏览器窗口,让用户通过认证程序.
用户完成签名后不久(最多10秒),您应该看到反映新状态的状态通知
状态.
如果可用, 语言服务器将使用
window/showDocument
打开 URL。 否则,它将试图以本地方式打开URL(例如: /usr/bin/open (原始内容存档于2018-09-28). on macOS.
签个字,打个电话 signOut。 。 。 .
内置补全
这个 textDocument/inlineCompletion
从下一个 LSP 光谱的草稿版本中请求, 用于取回内置( “ 鬼文字 ” ) 的补全, 并带有一些
非标准添加(textDocument.version 财务报告和审定财务报表 formattingOptions参数:
{
"textDocument": {
"uri": "file:///path/to/file",
"version": 0
},
"position": {"line": 1, "character": 2},
"context": {
"triggerKind": 2
},
"formattingOptions": {
"tabSize": 4,
"insertSpaces": true
}
}
结果是一个包含 items 阵列.
{
"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
之后 用户接受完成。 副驾驶使用此来进行接收遥测.
LSP 光谱没有为显示完成提供事件, 所以自定义 textDocument/didShowCompletion 已使用.
用一个叫 item 包含全部完成项的参数:
{
"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编码点中)被接受的完成长度:
{
"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
但有一个 textDocument.version 所需字段
VersionedTextDocumentIdentifier数字 :
{
"textDocument": {
"uri": "file:///path/to/file",
"version": 0
},
"position": {"line": 1, "character": 2}
}
结果是一个包含 edits 数组 :
{
"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
之后 用户接受编辑。 副驾驶使用此来进行接收遥测.
每个编辑也可能带有可选 requestedLanguageId 财务报告和审定财务报表 targetLanguageId
与生成请求的文档的 CLS 所检测语言并
页:1 textDocument 正在接收编辑.
LSP 光谱没有为显示编辑提供事件, 所以自定义
textDocument/didShowInlineEdit 已使用。 用一个叫 item 参数
包含从 edits 数组(注意只需要第一个参数),
和可选 viewKind 描述向用户显示的第一个演示文稿:
{
"item": {
"command": {
"arguments": ["some-id"]
}
},
"viewKind": "inlineDiff"
}
有已知源属性的编辑包括可选 cacheTelemetryContext。 。 。 .
保留此不透明字符串并带有缓存副本 。 在每个客户端- cache 服务上创建一个
本地新机会标识并跟踪其存在周期; 不重用源标识
或等待CLS。 或等待CLS。 将上下文保留到事件结束, 即使缓存结束
过期, 然后发送一个 textDocument/reportCachedInlineEdit 通知:
{
"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 引用/文本限制和零预测冷启动兼容性
路线明确;见 统一型号的路由。 。 。 .
参数结合了两种方法的参数,并增加了: reason 请求:
{
"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,当没有显示时缺席:
{
"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 说明
内置补全对于一个 edit 或一个 jump发送 textDocument/didShowInlineEdit 说明
内 下次编辑建议。在所有情况下,拨打项目 command 通过
workspace/executeCommand 用户接受后。 下一次编辑返回此方式时带不 cacheTelemetryContext数字 :
服务器本身缓存它们.
小组完成情况
面板完成用于"开放副驾驶"风格完成. 它们与内含完成类似,但被显示
在一个单独的面板。 使用自定义检索 textDocument/copilotPanelCompletion 请求,它已经
参数紧接其后 textDocument/inlineCompletion数字 :
{
"textDocument": {
"uri": "file:///path/to/file",
"version": 0
},
"position": {"line": 1, "character": 2},
"partialResultToken": "some token"
}
如果提供,则 partialResultToken 用于流
部分结果
回到客户端。 返回类型和部分结果类型与内含补全相同:一个对象
包含 items 阵列。 这些项目相同 command 必须援引 workspace/executeCommand
在接受接受遥测后 这里不支持部分接受和显示的事件 .
取消
textDocument/inlineCompletion 支持取消的先前策略 : 如果您发送了新的补全
请求,上一请求被取消. textDocument/copilotSuggest 请求完成时分享此信息
战略 textDocument/inlineCompletion,而一个被取代的 失败的相同 ServerCancelled 错误.
这也适用于代理在完成调用后等待NES时.
此外,《劳动法》 $/cancelRequest 用于取消任何请求的方法。 强烈鼓励它迫切地
尽快取消完成请求.
日志
日志作为
window/logMessage
通知书.
信件
可以发送客户端
window/showMessageRequest
请求。 对这些信息的支持至关重要,因为它们用于重要通知,包括账户和账户
计费.
许可证
以麻省理工学院许可证分发。 详情见LICENSE.