内容摘录
@github/copilot-language-server
The Copilot Language Server enables any editor or IDE to integrate with GitHub
Copilot via the language server protocol.
**GitHub Copilot** is an AI pair programmer tool that helps you write code faster and smarter.
**Sign up for GitHub Copilot Free!**
Please see terms of use for GitHub Copilot
Getting Started
To integrate with the Copilot Language Server, download the latest release from npm:
To run the language server, platform-specific binaries are available as separate
packages included as optional dependencies. For example, @github/copilot-language-server-darwin-arm64, for macOS on arm64:
example, for macOS on arm64:
If repackaging the language server, all platform-specific binaries are available
in the releases: https://github.com/github/copilot-language-server-release/releases
For example, to download a zip of all of the binaries together:
Or you can use Node.js version 20.8 or later:
If using the language-server.js distribution, it is necessary to retain the entire dist directory contents.
Communication with the language server typically happens over stdio with --stdio. The language-server.js
distribution additionally supports Node IPC with --node-ipc.
Agent Client Protocol (ACP) (Preview)
The Copilot Language Server also supports the Agent Client Protocol (ACP),
enabling integration with ACP-compatible editors like JetBrains AI Assistant, Zed, and more.
Running in ACP Mode
To start the language server in ACP mode:
Or if installed locally:
Communication happens over stdin/stdout.
JetBrains AI Assistant
To use Copilot as an ACP agent in JetBrains AI Assistant, add the following to your ~/.jetbrains/acp.json:
See the ACP specification for full protocol details.
Communication Protocol
The Language Server Protocol (LSP) is used to communicate with
the client. The base protocol is JSON-RPC 2.0 with additional
headers.
The Copilot Language Server attempts to follow the LSP spec as closely as possible, but many custom messages are
employed to support the unique features of Copilot.
Initialization
Per the LSP spec, the client is expected to send a
initialize
request to the language server as a first message. Example parameters:
After receiving the response to initialize, the second message the client must send is an
initialized
notification.
Configuration Management
After initialization, clients should send a
workspace/didChangeConfiguration
notification to inform the language server about the initial configuration, and again each time the configuration
changes. Example parameters:
Pull based configuration on
workspace/configuration
is also supported.
Workspace Folders Synchronization
Workspace folders are optional but highly recommended as they greatly improve the quality of suggestions. See the LSP spec for
workspace/didChangeWorkspaceFolders.
Text Document Synchronization
Per the LSP spec for
text document synchronization,
support for textDocument/didOpen, textDocument/didChange, and textDocument/didClose is required, using incremental
sync.
Text Document Focusing
Additionally a custom textDocument/didFocus notification should be sent when the client focuses another document
(e.g., changing tabs). Example parameters:
If no document is focused, a request with no parameters ({}) may be sent.
Status Notification
The status is sent to the client as a didChangeStatus notification. Typically this would be conveyed to the user in a
status bar icon or other UI affordance.
Notification includes the following fields:
message - a string describing the status (can be empty)
kind - status of the language server:
'Normal' - When everything is working normally.
'Error' - When not authorized and authenticated.
'Warning' - When there is a temporary issue, such as a failed HTTP request.
'Inactive' - When the current file is ignored due to file size or content exclusions.
Authentication
To sign in, call signIn. This will return a response like the following:
Instruct the user to copy the userCode to their clipboard (and/or copy it programmatically). When the user is ready, invoke
workspace/executeCommand
to execute the command. This will open a browser window that walks the user through the authentication process.
Shortly (up to 10 seconds) after the user finishes signing in, you should see a status notification reflecting the new
state.
If available, the language server will use
window/showDocument
to open the URL. Otherwise, it will attempt to open the URL natively (e.g., with /usr/bin/open on macOS).
To sign out, call signOut.
Inline Completions
The textDocument/inlineCompletion
request from the draft version of the next LSP spec is used to retrieve inline ("ghost text") completions, with some
non-standard additions (textDocument.version and formattingOptions) to the parameters:
The result is an object containing an items array.
Newlines in insertText should be normalized as is appropriate for the editor before inserting into the document.
The command field, per the LSP spec, is called via
workspace/executeCommand
*after* the user accepts the completion. Copilot uses this for acceptance telemetry.
The LSP spec does not provide an event for showing the completion, so a custom textDocument/didShowCompletion is used.
Call it with an item parameter containing the full completion item:
Similarly, for partial acceptance, send a textDocument/didPartiallyAcceptCompletion notification with the full
item, plus the length (in UTF-16 codepoints) of the completion that was accepted:
Note that the acceptedLength includes everything from the start of insertText to the end of the accepted text. It is
*not* the length of the accepted text itself.
Next Edit Suggestions
textDocument/copilotInlineEdit is a custom method used to retrieve "next edit"
suggestions which are inline completions that may include deletions or
modifications to existing text and may not be positioned at the cursor. These
are similar to inline completions and the API shape is…